From 342fe617838fd57e9f3780cf6d92cf20de90e852 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Mon, 18 Oct 2021 16:09:53 +0200 Subject: [PATCH 1/7] Target only net48 --- src/MyOtherService/MyOtherService.csproj | 2 +- src/MyService/MyService.csproj | 2 +- src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MyOtherService/MyOtherService.csproj b/src/MyOtherService/MyOtherService.csproj index 4a37c509..d5e22e45 100644 --- a/src/MyOtherService/MyOtherService.csproj +++ b/src/MyOtherService/MyOtherService.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net48 + net48 latest diff --git a/src/MyService/MyService.csproj b/src/MyService/MyService.csproj index f331ac6f..e7788c5a 100644 --- a/src/MyService/MyService.csproj +++ b/src/MyService/MyService.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1;net48 + net48 latest diff --git a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj index c523866c..3df5d697 100644 --- a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj +++ b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net48 + net48 false From 25599dd36a60bb12d952711854ae55258a4eb568 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 29 Oct 2021 11:41:10 +0200 Subject: [PATCH 2/7] Remove snippets --- src/Snippets/AssemblyScannerSnippets.cs | 18 ------ src/Snippets/AssertionSnippets.cs | 41 ------------- src/Snippets/ConfigurationSnippets.cs | 38 ------------ src/Snippets/DoneSnippets.cs | 38 ------------ src/Snippets/EndpointsSnippets.cs | 49 --------------- src/Snippets/GenericHostSnippets.cs | 70 ---------------------- src/Snippets/KickOffSnippets.cs | 25 -------- src/Snippets/ScenarioSnippets.cs | 26 -------- src/Snippets/Snippets.csproj | 17 ------ src/Snippets/TimeoutsRescheduleSnippets.cs | 32 ---------- src/Snippets/TooLongDontReadSnippets.cs | 43 ------------- 11 files changed, 397 deletions(-) delete mode 100644 src/Snippets/AssemblyScannerSnippets.cs delete mode 100644 src/Snippets/AssertionSnippets.cs delete mode 100644 src/Snippets/ConfigurationSnippets.cs delete mode 100644 src/Snippets/DoneSnippets.cs delete mode 100644 src/Snippets/EndpointsSnippets.cs delete mode 100644 src/Snippets/GenericHostSnippets.cs delete mode 100644 src/Snippets/KickOffSnippets.cs delete mode 100644 src/Snippets/ScenarioSnippets.cs delete mode 100644 src/Snippets/Snippets.csproj delete mode 100644 src/Snippets/TimeoutsRescheduleSnippets.cs delete mode 100644 src/Snippets/TooLongDontReadSnippets.cs diff --git a/src/Snippets/AssemblyScannerSnippets.cs b/src/Snippets/AssemblyScannerSnippets.cs deleted file mode 100644 index c0bae746..00000000 --- a/src/Snippets/AssemblyScannerSnippets.cs +++ /dev/null @@ -1,18 +0,0 @@ -using NServiceBus; - -namespace AssemblyScannerSnippets -{ - // begin-snippet: assembly-scanner-config - public class MyServiceConfiguration : EndpointConfiguration - { - public MyServiceConfiguration() - : base("MyService") - { - var scanner = this.AssemblyScanner(); - scanner.IncludeOnly("MyService.dll", "MyMessages.dll"); - - //rest of the configuration - } - } - // end-snippet -} \ No newline at end of file diff --git a/src/Snippets/AssertionSnippets.cs b/src/Snippets/AssertionSnippets.cs deleted file mode 100644 index 79b01515..00000000 --- a/src/Snippets/AssertionSnippets.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using MyMessages.Messages; -using MyService; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; -using NUnit.Framework; - -namespace AssertionsSnippets -{ - public class Snippets - { - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - var theExpectedIdentifier = Guid.NewGuid(); - var context = await Scenario.Define() - .WithEndpoint(behavior => - { - behavior.When(session => session.Send(new AMessage() {AnIdentifier = theExpectedIdentifier})); - }) - .WithEndpoint() - .Done(c => c.SagaWasInvoked() || c.HasFailedMessages()) - .Run(); - - // begin-snippet: assert-on-tests-results - var invokedSaga = context.InvokedSagas.Single(s => s.SagaType == typeof(ASaga)); - - Assert.True(invokedSaga.IsNew); - Assert.AreEqual("MyService", invokedSaga.EndpointName); - Assert.True(((ASagaData)invokedSaga.SagaData).AnIdentifier == theExpectedIdentifier); - Assert.False(context.HasFailedMessages()); - Assert.False(context.HasHandlingErrors()); - // end-snippet - } - - class MyServiceEndpoint : EndpointConfigurationBuilder{ /* omitted */ } - class MyOtherServiceEndpoint : EndpointConfigurationBuilder{ /* omited */ } - } -} \ No newline at end of file diff --git a/src/Snippets/ConfigurationSnippets.cs b/src/Snippets/ConfigurationSnippets.cs deleted file mode 100644 index 5a362efb..00000000 --- a/src/Snippets/ConfigurationSnippets.cs +++ /dev/null @@ -1,38 +0,0 @@ -using NServiceBus; - -namespace ConfigurationSnippets -{ - // begin-snippet: inherit-from-endpoint-configuration - public class MyServiceConfiguration : EndpointConfiguration - { - public MyServiceConfiguration() - : base("MyService") - { - this.SendFailedMessagesTo("error"); - this.EnableInstallers(); - - var transportConfig = this.UseTransport(); - transportConfig.UseConventionalRoutingTopology(); - transportConfig.ConnectionString("host=localhost"); - } - } - // end-snippet - - // begin-snippet: use-builder-class - public static class MyServiceConfigurationBuilder - { - public static EndpointConfiguration Build(string endpointName, string rabbitMqConnectionString) - { - var config = new EndpointConfiguration(endpointName); - config.SendFailedMessagesTo("error"); - config.EnableInstallers(); - - var transportConfig = config.UseTransport(); - transportConfig.UseConventionalRoutingTopology(); - transportConfig.ConnectionString(rabbitMqConnectionString); - - return config; - } - } - // end-snippet -} \ No newline at end of file diff --git a/src/Snippets/DoneSnippets.cs b/src/Snippets/DoneSnippets.cs deleted file mode 100644 index cd92d5aa..00000000 --- a/src/Snippets/DoneSnippets.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Threading.Tasks; -using MyService; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; - -namespace DoneSnippets -{ - public class When_sending_AMessage - { - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - await Scenario.Define() - .WithEndpoint() - .WithEndpoint() - // begin-snippet: simple-done-condition - .Done(ctx => - { - return ctx.HasFailedMessages(); - }) - // end-snippet - .Run(); - - await Scenario.Define() - .WithEndpoint() - .WithEndpoint() - // begin-snippet: complete-done-condition - .Done(ctx => - { - return ctx.SagaWasInvoked() || ctx.HasFailedMessages(); - }) - // end-snippet - .Run(); - } - - class MyServiceEndpoint : EndpointConfigurationBuilder{ /* omitted */ } - class MyOtherServiceEndpoint : EndpointConfigurationBuilder{ /* omited */ } - } -} \ No newline at end of file diff --git a/src/Snippets/EndpointsSnippets.cs b/src/Snippets/EndpointsSnippets.cs deleted file mode 100644 index 9200391a..00000000 --- a/src/Snippets/EndpointsSnippets.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Threading.Tasks; -using MyOtherService; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.AcceptanceTesting.Support; -using NServiceBus.IntegrationTesting; - -namespace EndpointsSnippets -{ - // begin-snippet: endpoints-used-in-each-test - public class When_sending_AMessage - { - class MyServiceEndpoint : EndpointConfigurationBuilder - { - public MyServiceEndpoint() - { - EndpointSetup>(); - } - } - - class MyOtherServiceEndpoint : EndpointConfigurationBuilder - { - public MyOtherServiceEndpoint() - { - EndpointSetup(); - } - } - } - // end-snippet - - class MyServiceConfiguration : EndpointConfiguration - { - public MyServiceConfiguration() :base(""){} - } - - // begin-snippet: my-other-service-template - class MyOtherServiceTemplate : EndpointTemplate - { - protected override Task OnGetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointCustomizationConfiguration, Action configurationBuilderCustomization) - { - var config = MyOtherServiceConfigurationBuilder.Build( - "MyOtherService", - "host=localhost;username=guest;password=guest"); - return Task.FromResult(config); - } - } - // end-snippet -} \ No newline at end of file diff --git a/src/Snippets/GenericHostSnippets.cs b/src/Snippets/GenericHostSnippets.cs deleted file mode 100644 index 8dbc45cc..00000000 --- a/src/Snippets/GenericHostSnippets.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; -using NUnit.Framework; - -namespace GenericHostSnippets -{ - public class When_sending_AMessage - { - [Test] - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - // begin-snippet: with-generic-host-endpoint - _ = await Scenario.Define() - .WithGenericHostEndpoint("endpoint-name", configPreview => Program.CreateHostBuilder(new string[0], configPreview).Build()) - // end-snippet - .Done(ctx=>false) - .Run(); - } - } - - class Program - { - // begin-snippet: basic-generic-host-endpoint - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) - { - var builder = Host.CreateDefaultBuilder(args); - builder.UseConsoleLifetime(); - - builder.UseNServiceBus(ctx => - { - var config = new EndpointConfiguration("endpoint-name"); - config.UseTransport(); - - return config; - }); - - return builder; - } - // end-snippet - - // begin-snippet: basic-generic-host-endpoint-with-config-previewer - public static IHostBuilder CreateHostBuilder(string[] args, Action configPreview) - { - var builder = Host.CreateDefaultBuilder(args); - builder.UseConsoleLifetime(); - - builder.UseNServiceBus(ctx => - { - var config = new EndpointConfiguration("endpoint-name"); - config.UseTransport(); - - configPreview?.Invoke(config); - - return config; - }); - - return builder; - } - // end-snippet - } -} \ No newline at end of file diff --git a/src/Snippets/KickOffSnippets.cs b/src/Snippets/KickOffSnippets.cs deleted file mode 100644 index 1dbfed09..00000000 --- a/src/Snippets/KickOffSnippets.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Threading.Tasks; -using MyMessages.Messages; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; - -namespace KickOffSnippets -{ - public class When_sending_AMessage - { - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - // begin-snippet: kick-off-choreography - var context = await Scenario.Define() - .WithEndpoint(builder => builder.When(session => session.Send(new AMessage()))) - // end-snippet - .WithEndpoint() - .Done(ctx =>false) - .Run(); - } - - class MyServiceEndpoint : EndpointConfigurationBuilder{ /* omitted */ } - class MyOtherServiceEndpoint : EndpointConfigurationBuilder{ /* omited */ } - } -} \ No newline at end of file diff --git a/src/Snippets/ScenarioSnippets.cs b/src/Snippets/ScenarioSnippets.cs deleted file mode 100644 index bbcd1c40..00000000 --- a/src/Snippets/ScenarioSnippets.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Threading.Tasks; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; -using NUnit.Framework; - -namespace ScenarioSnippets -{ - public class When_sending_AMessage - { - // begin-snippet: scenario-skeleton - [Test] - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - var context = await Scenario.Define() - .WithEndpoint(/*...*/) - .WithEndpoint(/*...*/) - .Done(ctx=>false) - .Run(); - } - - class MyServiceEndpoint : EndpointConfigurationBuilder{ /* omitted */ } - class MyOtherServiceEndpoint : EndpointConfigurationBuilder{ /* omited */ } - - // end-snippet - } -} \ No newline at end of file diff --git a/src/Snippets/Snippets.csproj b/src/Snippets/Snippets.csproj deleted file mode 100644 index aa72f3cc..00000000 --- a/src/Snippets/Snippets.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netcoreapp3.1 - - - - - - - - - - - - - diff --git a/src/Snippets/TimeoutsRescheduleSnippets.cs b/src/Snippets/TimeoutsRescheduleSnippets.cs deleted file mode 100644 index 142f46f9..00000000 --- a/src/Snippets/TimeoutsRescheduleSnippets.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Threading.Tasks; -using MyMessages.Messages; -using MyService; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.DelayedDelivery; -using NServiceBus.IntegrationTesting; - -namespace TimeoutsRescheduleSnippets -{ - public class TimeoutsRescheduleSnippets - { - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - // begin-snippet: timeouts-reschedule - var context = await Scenario.Define(ctx => - { - ctx.RegisterTimeoutRescheduleRule((msg, delay) => - { - return new DoNotDeliverBefore(DateTime.UtcNow.AddSeconds(5)); - }); - }) - .WithEndpoint(builder => builder.When(session => session.Send("MyService", new StartASaga() { AnIdentifier = Guid.NewGuid() }))) - .Done(ctx => ctx.MessageWasProcessedBySaga() || ctx.HasFailedMessages()) - .Run(); - // end-snippet - } - - class MyServiceEndpoint : EndpointConfigurationBuilder{} - } -} \ No newline at end of file diff --git a/src/Snippets/TooLongDontReadSnippets.cs b/src/Snippets/TooLongDontReadSnippets.cs deleted file mode 100644 index fe2f4cc8..00000000 --- a/src/Snippets/TooLongDontReadSnippets.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using MyMessages.Messages; -using MyService; -using NServiceBus; -using NServiceBus.AcceptanceTesting; -using NServiceBus.IntegrationTesting; -using NUnit.Framework; - -namespace TooLongDontReadSnippets -{ - public class Snippets - { - // begin-snippet: too-long-dont-read-full-test - [Test] - public async Task AReplyMessage_is_received_and_ASaga_is_started() - { - var theExpectedIdentifier = Guid.NewGuid(); - var context = await Scenario.Define() - .WithEndpoint(behavior => - { - behavior.When(session => session.Send(new AMessage() {AnIdentifier = theExpectedIdentifier})); - }) - .WithEndpoint() - .Done(c => c.SagaWasInvoked() || c.HasFailedMessages()) - .Run(); - - var invokedSaga = context.InvokedSagas.Single(s => s.SagaType == typeof(ASaga)); - - - Assert.True(invokedSaga.IsNew); - Assert.AreEqual("MyService", invokedSaga.EndpointName); - Assert.True(((ASagaData)invokedSaga.SagaData).AnIdentifier == theExpectedIdentifier); - Assert.False(context.HasFailedMessages()); - Assert.False(context.HasHandlingErrors()); - } - // end-snippet - - class MyServiceEndpoint : EndpointConfigurationBuilder{ /* omitted */ } - class MyOtherServiceEndpoint : EndpointConfigurationBuilder{ /* omited */ } - } -} \ No newline at end of file From 33534525cf8574dda662e6c83b194893ffecd923 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 29 Oct 2021 11:46:13 +0200 Subject: [PATCH 3/7] Remove RabbitMQ dependency --- src/MyOtherService/MyOtherService.csproj | 1 - .../MyOtherServiceConfigurationBuilder.cs | 6 +- src/MyOtherService/Program.cs | 4 +- src/MyService/MyService.csproj | 1 - src/MyService/MyServiceConfiguration.cs | 4 +- src/MySystem.AcceptanceTests/DockerCompose.cs | 55 ------------------- .../MyOtherServiceTemplate.cs | 4 +- .../MySystem.AcceptanceTests.csproj | 6 -- .../When_requesting_a_timeout.cs | 12 ---- .../When_sending_AMessage.cs | 12 ---- .../When_sending_CompleteASaga.cs | 12 ---- .../docker-compose.yml | 12 ---- src/NServiceBus.IntegrationTesting.sln | 14 ++--- 13 files changed, 9 insertions(+), 134 deletions(-) delete mode 100644 src/MySystem.AcceptanceTests/DockerCompose.cs delete mode 100644 src/MySystem.AcceptanceTests/docker-compose.yml diff --git a/src/MyOtherService/MyOtherService.csproj b/src/MyOtherService/MyOtherService.csproj index d5e22e45..42a2e86e 100644 --- a/src/MyOtherService/MyOtherService.csproj +++ b/src/MyOtherService/MyOtherService.csproj @@ -9,7 +9,6 @@ - diff --git a/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs b/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs index 2c3499b7..ae453d46 100644 --- a/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs +++ b/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs @@ -4,7 +4,7 @@ namespace MyOtherService { public static class MyOtherServiceConfigurationBuilder { - public static EndpointConfiguration Build(string endpointName, string rabbitMqConnectionString) + public static EndpointConfiguration Build(string endpointName) { var config = new EndpointConfiguration(endpointName); var scanner = config.AssemblyScanner(); @@ -14,9 +14,7 @@ public static EndpointConfiguration Build(string endpointName, string rabbitMqCo config.UsePersistence(); config.EnableInstallers(); - var transportConfig = config.UseTransport(); - transportConfig.UseConventionalRoutingTopology(); - transportConfig.ConnectionString(rabbitMqConnectionString); + var transportConfig = config.UseTransport(); config.SendFailedMessagesTo("error"); diff --git a/src/MyOtherService/Program.cs b/src/MyOtherService/Program.cs index 5e9c750b..f22dc097 100644 --- a/src/MyOtherService/Program.cs +++ b/src/MyOtherService/Program.cs @@ -10,9 +10,7 @@ static async Task Main(string[] args) { Console.Title = typeof(Program).Namespace; - var endpointConfiguration = MyOtherServiceConfigurationBuilder.Build( - typeof(Program).Namespace, - "host=localhost;username=guest;password=guest"); + var endpointConfiguration = MyOtherServiceConfigurationBuilder.Build(typeof(Program).Namespace); var endpointInstance = await Endpoint.Start(endpointConfiguration); Console.WriteLine($"{typeof(Program).Namespace} started. Press any key to stop."); diff --git a/src/MyService/MyService.csproj b/src/MyService/MyService.csproj index e7788c5a..e8ff005e 100644 --- a/src/MyService/MyService.csproj +++ b/src/MyService/MyService.csproj @@ -10,7 +10,6 @@ - diff --git a/src/MyService/MyServiceConfiguration.cs b/src/MyService/MyServiceConfiguration.cs index 80c52eb0..6e06b5a4 100644 --- a/src/MyService/MyServiceConfiguration.cs +++ b/src/MyService/MyServiceConfiguration.cs @@ -15,9 +15,7 @@ public MyServiceConfiguration() this.UsePersistence(); this.EnableInstallers(); - var transportConfig = this.UseTransport(); - transportConfig.UseConventionalRoutingTopology(); - transportConfig.ConnectionString("host=localhost;username=guest;password=guest"); + var transportConfig = this.UseTransport(); transportConfig.Routing() .RouteToEndpoint(typeof(AMessage), "MyOtherService"); diff --git a/src/MySystem.AcceptanceTests/DockerCompose.cs b/src/MySystem.AcceptanceTests/DockerCompose.cs deleted file mode 100644 index 757cb70a..00000000 --- a/src/MySystem.AcceptanceTests/DockerCompose.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Threading.Tasks; -using static SimpleExec.Command; - -#if NETCOREAPP -using System.Net.Http; -#endif - -#if NET48 -using System.Net; -#endif - -namespace MySystem.AcceptanceTests -{ - public static class DockerCompose - { - public static async Task Up() - { - Run("docker-compose", "up -d", workingDirectory: AppDomain.CurrentDomain.BaseDirectory); - Run("docker", "ps -a"); - - static async Task statusChecker() - { - try - { - var managementUrl = "http://localhost:15672/"; -#if NETCOREAPP - using var client = new HttpClient(); - var response = await client.GetAsync(managementUrl); - return response.IsSuccessStatusCode; -#endif - -#if NET48 - var request = HttpWebRequest.Create(managementUrl); - var response = await request.GetResponseAsync(); - return ((HttpWebResponse)response).StatusCode == HttpStatusCode.OK; -#endif - } - catch - { - return false; - } - } - while (!await statusChecker()) - { - await Task.Delay(500); - } - } - - public static void Down() - { - Run("docker-compose", "down", workingDirectory: AppDomain.CurrentDomain.BaseDirectory); - } - } -} diff --git a/src/MySystem.AcceptanceTests/MyOtherServiceTemplate.cs b/src/MySystem.AcceptanceTests/MyOtherServiceTemplate.cs index 222d87cb..2915d7aa 100644 --- a/src/MySystem.AcceptanceTests/MyOtherServiceTemplate.cs +++ b/src/MySystem.AcceptanceTests/MyOtherServiceTemplate.cs @@ -11,9 +11,7 @@ class MyOtherServiceTemplate : EndpointTemplate { protected override Task OnGetConfiguration(RunDescriptor runDescriptor, EndpointCustomizationConfiguration endpointCustomizationConfiguration, Action configurationBuilderCustomization) { - var config = MyOtherServiceConfigurationBuilder.Build( - "MyOtherService", - "host=localhost;username=guest;password=guest"); + var config = MyOtherServiceConfigurationBuilder.Build("MyOtherService"); return Task.FromResult(config); } } diff --git a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj index 3df5d697..7c3ec8a3 100644 --- a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj +++ b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj @@ -25,10 +25,4 @@ - - - PreserveNewest - - - diff --git a/src/MySystem.AcceptanceTests/When_requesting_a_timeout.cs b/src/MySystem.AcceptanceTests/When_requesting_a_timeout.cs index 08419a74..85dd9278 100644 --- a/src/MySystem.AcceptanceTests/When_requesting_a_timeout.cs +++ b/src/MySystem.AcceptanceTests/When_requesting_a_timeout.cs @@ -12,18 +12,6 @@ namespace MySystem.AcceptanceTests { public class When_requesting_a_timeout { - [OneTimeSetUp] - public async Task Setup() - { - await DockerCompose.Up(); - } - - [OneTimeTearDown] - public void Teardown() - { - DockerCompose.Down(); - } - [Test] public async Task It_should_be_rescheduled_and_handled() { diff --git a/src/MySystem.AcceptanceTests/When_sending_AMessage.cs b/src/MySystem.AcceptanceTests/When_sending_AMessage.cs index 10c52a7d..bb117e2e 100644 --- a/src/MySystem.AcceptanceTests/When_sending_AMessage.cs +++ b/src/MySystem.AcceptanceTests/When_sending_AMessage.cs @@ -12,18 +12,6 @@ namespace MySystem.AcceptanceTests { public class When_sending_AMessage { - [OneTimeSetUp] - public async Task Setup() - { - await DockerCompose.Up(); - } - - [OneTimeTearDown] - public void Teardown() - { - DockerCompose.Down(); - } - [Test] public async Task AReplyMessage_is_received_and_ASaga_is_started() { diff --git a/src/MySystem.AcceptanceTests/When_sending_CompleteASaga.cs b/src/MySystem.AcceptanceTests/When_sending_CompleteASaga.cs index 262c843a..eaa671c2 100644 --- a/src/MySystem.AcceptanceTests/When_sending_CompleteASaga.cs +++ b/src/MySystem.AcceptanceTests/When_sending_CompleteASaga.cs @@ -12,18 +12,6 @@ namespace MySystem.AcceptanceTests { public class When_sending_CompleteASaga { - [OneTimeSetUp] - public async Task Setup() - { - await DockerCompose.Up(); - } - - [OneTimeTearDown] - public void Teardown() - { - DockerCompose.Down(); - } - [Test] public async Task ASaga_is_completed() { diff --git a/src/MySystem.AcceptanceTests/docker-compose.yml b/src/MySystem.AcceptanceTests/docker-compose.yml deleted file mode 100644 index cad9e1d3..00000000 --- a/src/MySystem.AcceptanceTests/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '2.0' -services: - rabbit: - container_name: mysystem_acceptancetests_rabbit - hostname: rabbit - image: rabbitmq:3.6.6-management - environment: - - RABBITMQ_DEFAULT_USER=guest - - RABBITMQ_DEFAULT_PASS=guest - ports: - - "5672:5672" - - "15672:15672" \ No newline at end of file diff --git a/src/NServiceBus.IntegrationTesting.sln b/src/NServiceBus.IntegrationTesting.sln index cb936d29..5e8f5af2 100644 --- a/src/NServiceBus.IntegrationTesting.sln +++ b/src/NServiceBus.IntegrationTesting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29020.237 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31825.309 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyService", "MyService\MyService.csproj", "{AB7F9FB9-B79B-47BF-A42E-CD6DB62E0E40}" EndProject @@ -15,11 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.IntegrationTest EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.AssemblyScanner.Extensions", "NServiceBus.AssemblyScanner.Extensions\NServiceBus.AssemblyScanner.Extensions.csproj", "{DA921CE7-6B53-4196-8567-B0197E773043}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBus.IntegrationTesting.Tests", "NServiceBus.IntegrationTesting.Tests\NServiceBus.IntegrationTesting.Tests.csproj", "{18A4490B-641E-471C-9A53-02C4AAB69551}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.IntegrationTesting.Tests", "NServiceBus.IntegrationTesting.Tests\NServiceBus.IntegrationTesting.Tests.csproj", "{18A4490B-641E-471C-9A53-02C4AAB69551}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snippets", "Snippets\Snippets.csproj", "{927BC675-5940-43C6-BB97-96DA64CBA6D0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBus.IntegrationTesting.Tests.TestEndpoint", "NServiceBus.IntegrationTesting.Tests.TestEndpoint\NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj", "{A830D9C2-07D2-49F3-996A-9AE9EE85B38B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBus.IntegrationTesting.Tests.TestEndpoint", "NServiceBus.IntegrationTesting.Tests.TestEndpoint\NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj", "{A830D9C2-07D2-49F3-996A-9AE9EE85B38B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,10 +53,6 @@ Global {18A4490B-641E-471C-9A53-02C4AAB69551}.Debug|Any CPU.Build.0 = Debug|Any CPU {18A4490B-641E-471C-9A53-02C4AAB69551}.Release|Any CPU.ActiveCfg = Release|Any CPU {18A4490B-641E-471C-9A53-02C4AAB69551}.Release|Any CPU.Build.0 = Release|Any CPU - {927BC675-5940-43C6-BB97-96DA64CBA6D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {927BC675-5940-43C6-BB97-96DA64CBA6D0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {927BC675-5940-43C6-BB97-96DA64CBA6D0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {927BC675-5940-43C6-BB97-96DA64CBA6D0}.Release|Any CPU.Build.0 = Release|Any CPU {A830D9C2-07D2-49F3-996A-9AE9EE85B38B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A830D9C2-07D2-49F3-996A-9AE9EE85B38B}.Debug|Any CPU.Build.0 = Debug|Any CPU {A830D9C2-07D2-49F3-996A-9AE9EE85B38B}.Release|Any CPU.ActiveCfg = Release|Any CPU From 1d5381ad6e53fca6b92dacae1e8bc707392a3d33 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 10 Dec 2021 16:57:14 +0100 Subject: [PATCH 4/7] Remove doco generation --- .github/workflows/on-push-do-doco.yml | 22 --- README.source.md | 211 -------------------------- 2 files changed, 233 deletions(-) delete mode 100644 .github/workflows/on-push-do-doco.yml delete mode 100644 README.source.md diff --git a/.github/workflows/on-push-do-doco.yml b/.github/workflows/on-push-do-doco.yml deleted file mode 100644 index 5fb33aae..00000000 --- a/.github/workflows/on-push-do-doco.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: on-push-do-doco -on: - push: -jobs: - release: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Run MarkdownSnippets - run: | - dotnet tool install --global MarkdownSnippets.Tool - mdsnippets ${GITHUB_WORKSPACE} - shell: bash - - name: Push changes - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git commit -m "MarkdownSnippets documentation changes" -a || echo "nothing to commit" - remote="https://${GITHUB_ACTOR}:${{secrets.GITHUB_TOKEN}}@github.com/${GITHUB_REPOSITORY}.git" - branch="${GITHUB_REF:11}" - git push "${remote}" ${branch} || echo "nothing to push" - shell: bash diff --git a/README.source.md b/README.source.md deleted file mode 100644 index d1b5471f..00000000 --- a/README.source.md +++ /dev/null @@ -1,211 +0,0 @@ - - -# NServiceBus.IntegrationTesting - -NServiceBus.IntegrationTesting allows testing end-to-end business scenarios, exercising the real production code. - -## Disclaimer - -NServiceBus.IntegrationTesting is not affiliated with Particular Software and thus is not officially supported. It's evolution stage doesn't make it production ready yet. - -## tl;dr - -NServiceBus.IntegrationTesting enables a test like the following one to be defined: - -snippet: too-long-dont-read-full-test - -(Full test [source code](https://github.com/mauroservienti/NServiceBus.IntegrationTesting/blob/master/src/MySystem.AcceptanceTests/When_sending_AMessage.cs) for the above sample is available in this repo) - -The above test does quite a lot of things, but the most important ones are: - -- it's exercising the real production endpoints -- it's asserting on the end-to-end choreography, for example it's checking that a saga was invoked and/or a message handler was invoked - -When the test is started, it sends an initial `AMessage` message to trigger the choreography, and then it lets the endpoints involved do their job until a specific condition is met. In this sample the `done` condition is: - -- A saga is invoked -- Or there are failed messages - -*NOTE*: Endpoints in the samples contained in this repository are using RabbitMQ as the NServiceBus transport, LearningPersistence as the persistence mechanism. Tests are using `docker-compose` to make sure the required infrastructure is made available to endpoints exercised by tests. - -## Why? - -By using [NServiceBus testing](https://docs.particular.net/nservicebus/testing/) capabilities it is possible to unit test all NServiceBus features, from message handlers and sagas to custom behaviors. This doesn't mean that the system will work as expected in production, things like: - -- the overall business process behavior, or choreography -- correctness of the endpoint configuration -- message routing and events subscriptions -- saga message mappings - -and probably more, cannot be tested using a unit testing approach. NServiceBus.IntegrationTesting is designed to solve these problems. - -### Testing business processes (choreography testing) - -The goal of choreography testing is to consider endpoints in the system as black boxes, the only thing the test knows are input messages, output messages, and if really needed saga data stored by NServiceBus sagas while processing messages. In this case saga data are considered like an output of an endpoint. - -### Testing endpoint configuration - -It's important to make sure that each endpoint configuration works as expected, the only real way to validate that is to exercise the real production endpoint by instantiating and running it using the exact same configuration that will be used in production. - -### Testing message routing - -[Message routing](https://docs.particular.net/nservicebus/messaging/routing) is part of the endpoint configuration and is what makes a choreography successful, the only way to test correctness of the message routing set up is to exercise the choreography so that endpoints will use the production routing configuration to exchange messages, and to subscribe to events. If the routing configuration is wrong or is missing pieces the choreography tests wil fail. - -### Testing saga message mappings - -In theory, it's possible to assert on [saga message mappings](https://docs.particular.net/nservicebus/sagas/message-correlation) using an approval testing approach. By using this technique it's possible to catch changes to mappings. Although, it's impossible to validate that mappings are correct. The only way to make sure saga mappings are correct is, once again, to exercise sagas by hosting them in endpoints, by sending messages, and asserting on published messages and saga data. - -## How to define a test - -Defining an NServiceBus integration test is a multi-step process, composed of: - -- Make sure endpoints configuration can be istantiated by tests -- Define endpoints used in each test; and if needed customize each endpoint configuration to adapt to the test environment -- Define tests and completion criteria -- Assert on tests results - -### Make sure endpoints configuration can be istantiated by tests - -One of the goals of end-to-end testing a NServiceBus endpoint is to make sure that what gets tested is the real production code, not a copy of it crafted for the tests. The production endpoint configuration has to be used in tests. To make sure that the testing infrastructure can instantiate the endpoint configuration there are a couple of options, with many variations. - -#### Inherit from EndpointConfiguration - -It's possible to create a class that inherits from `EndpointConfiguration` and then use it in both the production endpoint and the tests. To make so that the testing infrastructure can automatically instantiate it, the class must have a parameterless constructor, like in the following snippet: - -snippet: inherit-from-endpoint-configuration - -Using the above approach can be problematic when configuration values need to be read from an external source, like for example a configuration file. If this is the case the same external configuration source, most of the times with different values, needs to be available in tests too. - -#### Use a builder class - -In case configuration values need to be passed to the endpoint configuration the easiest option is to use a builder class, even a very simple static one, that can then be used in tests as well with different configuration values. The following snippet shows a simple configuration builder: - -snippet: use-builder-class - -### Define endpoints used in each test - -To define an endpoint in tests a class inheriting from `NServiceBus.AcceptanceTesting.EndpointConfigurationBuilder` needs to be created for each endpoint that needs to be used in a test. The best place to define such classes is as nested classes within the test class itself: - -snippet: endpoints-used-in-each-test - -The sample defines two endpoints, `MyServiceEndpoint` and `MyOtherServiceEndpoint`. `MyServiceEndpoint` uses the "inherit from EndpointConfiguration" approach to reference the production endpoint configuration. `MyOtherServiceEndpoint` uses the "builder class" by inheriting from `NServiceBus.IntegrationTesting.EndpointTemplate`: - -snippet: my-other-service-template - -The "builder class" approach allows specific modifications of the `EndpointConfiguration` for the tests. Although modifications should be kept to a minimum they are reasonable for a few aspects: - -- Retries - - Retries should be reduced or even disabled for tests. - - Otherwise (with the default retry configuration) the IntegrationTests throw a "Some failed messages were not handled by the recoverability feature."-Exception because of a fixed 30 sec timeout in the `NServiceBus.AcceptanceTests.ScenarioRunner`. -- Cleaning up the queues via `PurgeOnStartup(true)` - -#### Generic host support - -NServiceBus endpoints can be [hosted using the generic host](https://docs.particular.net/samples/hosting/generic-host/). When using the generic host the endpoint lifecycle and configuration are controlled by the host. The following is a sample endpoint hosted using the generic host: - -snippet: basic-generic-host-endpoint - -> For more information about hosting NServiceBus using the generic host refer to the [official documentation](https://docs.particular.net/samples/hosting/generic-host/). - -Before using generic host hosted endpoints with `NServiceBus.IntegrationTesting`, a minor change to the above snippet is required: - -snippet: basic-generic-host-endpoint-with-config-previewer - -The testing engine needs to access the endpoint configuration before it's initialized to register the needed tests behaviors. The creation of the `IHostBuilder` needs to be tweaked to invoke a callback delegate that the test engine injects at tests runtime. - -Finally, the endpoint can be added to the scenario using the `WithGenericHostEndpoint` configuration method: - -snippet: with-generic-host-endpoint - -Be sure to pass to the method that creates the `IHostBuilder` the provided `Action` parameter. If the endpoint is not configured correctly the following exception will be raised at test time: - -> Endpoint \ is not correctly configured to be tested. Make sure to pass the EndpointConfiguration instance to the Action provided by WithGenericHostEndpoint tests setup method. - -### Define tests and completion criteria - -#### Scenario - -Once endpoints are defined, the test choreography can be implemented, the first thing is to define a `Scenario`: - -snippet: scenario-skeleton - -NOTE: The defined `Scenario` must use the `IntegrationScenarioContext` or a type that inherits from `IntegrationScenarioContext`. - -This tests aims to verify that when "MyService" sends a message to "MyOtherService" a reply is received by "MyService" and finally that a new saga instance is created. Use the `Define` static method to create a scenario and then add endpoints to the created scenario to append as many endpoints as needed for the scenario. Add a `Done` condition to specify when the test has to be considered completed and finally invoke `Run` to exercise the `Scenario`. - -#### Done condition - -An end-to-end test execution can only be terminated by 3 events: - -- the done condition is `true` -- the test times out -- there are unhandled exceptions - -Unhandled exceptions are a sort of problem from the integration testing infrastructure perspecive as most of the times they'll result in messages being retried and eventually ending up in the error queue. Based on this it's better to consider failed messages as part of the done condition: - -snippet: simple-done-condition - -Such a done condition has to be read as: "If there are one or more failed messages the test is done, proceed to evaulate the assertions". Obviously this is not enough. In the identified test case scenario the test is done when a saga is invoked (specifically is created, more on this later). A saga invokation can be expressed as a done condition in the following way: - -snippet: complete-done-condition - -The integration scenario context, the `c` argument, can be "queried" to gather the status of the test, in this case the done condition is augmented to make so that the test is considered done when a saga of type `ASaga` has been invoked or there are failed messages. - -#### Kick-off the test choreography - -The last bit is to kick-off the choreography to test. This is usually done by stimulating the system with a message. `WithEndpoint` has an overload that allows to define a callback that is invoked when the test is run. -In the defined callback it's possible to define one or more "when" conditions that are evaluated by the testing infrastructure and invoked at the appropriate time: - -snippet: kick-off-choreography - -The above code snippet makes so that when "MyServiceEndpoint" is started `AMessage` is sent. `When` has multiple overloads (including one with a condition-parameter) to accommodate many different scenarios. - -### Assert on tests results - -The last step is to assert on test results. The `IntegrationScenarioContext` instance, created at the beginning of the test captures tests stages and exposes an API to query tests results. The following snippet demonstrates how to assert that a new `ASaga` instance has been created with specific values, a `AMessage` has been handled, and `AReplyMessage` has been handled: - -snippet: assert-on-tests-results - -The context contains also general assertions like `HasFailedMessages` or `HasHandlingErrors` useful to validate the overall correctness of the test execution. `HasFailedMessages` Is `true` if any message has been moved to the configured error queue. `HasHandlingErrors` is `true` if any handler or saga invocation failed at least ones. - -## How to deal with NServiceBus Timeouts - -When testing production code, running a choreography, NServiceBus Timeouts can be problematic. Tests will timeout after 90 seconds, this means that if the production code schedules an NServiceBus Timeout for 1 hour, or for next week, it becomes impossible to verify the choreography. - -NServiceBus.IntegrationTesting provides a way to reschedule NServiceBus Timeouts when they are requested by the production code: - -snippet: timeouts-reschedule - -The above sample test shows how to inject an NServiceBus Timeout reschedule rule. When the production code, in this case the `ASaga` saga, schedules the `ASaga.MyTimeout` message, the registered NServiceBus Timeout reschedule rule will be invoked and a new delivery constraint is created, in this sample, to make so that the NServiceBus Timeout expires in 5 seconds instead of the default production value. The NServiceBus Timeout reschedule rule receives as arguments the current NServiceBus Timeout message and the current delivery constraint. - -## Limitations - -NServiceBus.IntegrationTesting is built on top of the NServiceBus.AcceptanceTesting framework, this comes with a few limitations: - -- Each test has a fixed, hardcoded, timeout of 90 seconds -- Tests can only use NUnit and at this time there is no way to use a different unit testing framework -- All endpoints run in a test share the same test process, they are not isolated - -### Assembly scanning setup - -By default NServiceBus endpoints scan and load all assemblies found in the bin directory. This means that if more than one endpoint is loaded into the same process all endpoints will scan the same bin directory and all types related to NServiceBus, such as message handlers and/or sagas, are loaded by all endpoints. This can issues to endpoints running in end-to-end tests. It's suggested to configure the endpoint configuration to scan only a limited set of assemblies, and exclude those not related to the current endpoint. The assembly scanner configuration can be applied directly to the production endpoint configuration or as a customization in the test endpoint template setup. - -snippet: assembly-scanner-config - -The `IncludeOnly` extension method is a custom extension defined as follows: - -snippet: include-only-extension - -The above extension method is far from being complete and doesn't handle all the possible scenarios. It's provided as a sample and needs to customized on a case by case. - -## How to install - -Using a package manager add a nuget reference to [NServiceBus.IntegrationTesting](https://www.nuget.org/packages/NServiceBus.IntegrationTesting/). - -## Background - -For more information on the genesis of this package refer to the [Exploring NServiceBus Integration Testing options](https://milestone.topics.it/2019/07/04/exploring-nservicebus-integration-testing-options.html) article. - ---- - -Icon [test](https://thenounproject.com/search/?q=test&i=2829166) by Andrei Yushchenko from the Noun Project From 4d7ee6d22491e26fd453a70800f023ee089727ed Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 10 Dec 2021 18:17:58 +0100 Subject: [PATCH 5/7] Update packages --- src/MyOtherService/MyOtherService.csproj | 6 ++++-- src/MyService/MyService.csproj | 6 ++++-- .../MySystem.AcceptanceTests.csproj | 4 ++-- .../NServiceBus.AssemblyScanner.Extensions.csproj | 2 +- ...NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/MyOtherService/MyOtherService.csproj b/src/MyOtherService/MyOtherService.csproj index 42a2e86e..482e4d24 100644 --- a/src/MyOtherService/MyOtherService.csproj +++ b/src/MyOtherService/MyOtherService.csproj @@ -7,8 +7,10 @@ - - + + + + diff --git a/src/MyService/MyService.csproj b/src/MyService/MyService.csproj index e8ff005e..897305de 100644 --- a/src/MyService/MyService.csproj +++ b/src/MyService/MyService.csproj @@ -7,9 +7,11 @@ - + - + + + diff --git a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj index 7c3ec8a3..a28e3e04 100644 --- a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj +++ b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj @@ -7,11 +7,11 @@ - + - + diff --git a/src/NServiceBus.AssemblyScanner.Extensions/NServiceBus.AssemblyScanner.Extensions.csproj b/src/NServiceBus.AssemblyScanner.Extensions/NServiceBus.AssemblyScanner.Extensions.csproj index b25ea46c..f4488c23 100644 --- a/src/NServiceBus.AssemblyScanner.Extensions/NServiceBus.AssemblyScanner.Extensions.csproj +++ b/src/NServiceBus.AssemblyScanner.Extensions/NServiceBus.AssemblyScanner.Extensions.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/NServiceBus.IntegrationTesting.Tests.TestEndpoint/NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj b/src/NServiceBus.IntegrationTesting.Tests.TestEndpoint/NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj index fedc321a..0300a17f 100644 --- a/src/NServiceBus.IntegrationTesting.Tests.TestEndpoint/NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj +++ b/src/NServiceBus.IntegrationTesting.Tests.TestEndpoint/NServiceBus.IntegrationTesting.Tests.TestEndpoint.csproj @@ -7,7 +7,7 @@ - + From 15fb26118360f88257230391db73779fb04652e6 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 10 Dec 2021 18:18:32 +0100 Subject: [PATCH 6/7] Use SqlP and SqlT --- .../MyOtherServiceConfigurationBuilder.cs | 21 +++++++++++++---- src/MyService/MyServiceConfiguration.cs | 23 +++++++++++++++---- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs b/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs index ae453d46..5bc8428d 100644 --- a/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs +++ b/src/MyOtherService/MyOtherServiceConfigurationBuilder.cs @@ -1,4 +1,5 @@ -using NServiceBus; +using Microsoft.Data.SqlClient; +using NServiceBus; namespace MyOtherService { @@ -6,15 +7,27 @@ public static class MyOtherServiceConfigurationBuilder { public static EndpointConfiguration Build(string endpointName) { + var connectionString = "Data Source=.;Initial Catalog=db;User ID=sa;Password=YourStrong@Passw0rd;Max Pool Size=80"; + var config = new EndpointConfiguration(endpointName); var scanner = config.AssemblyScanner(); - scanner.IncludeOnly("MyOtherService.dll", "MyMessages.dll"); + scanner.IncludeOnly("MyOtherService.dll", + "MyMessages.dll", + "NServiceBus.Transport.SqlServer.dll", + "NServiceBus.Persistence.Sql.dll"); config.UseSerialization(); - config.UsePersistence(); config.EnableInstallers(); - var transportConfig = config.UseTransport(); + config.EnableOutbox(); + + var persistence = config.UsePersistence(); + persistence.SqlDialect(); + persistence.ConnectionBuilder(() => new SqlConnection(connectionString)); + + var transportConfig = config.UseTransport() + .ConnectionString(connectionString); + transportConfig.Transactions(TransportTransactionMode.SendsAtomicWithReceive); config.SendFailedMessagesTo("error"); diff --git a/src/MyService/MyServiceConfiguration.cs b/src/MyService/MyServiceConfiguration.cs index 6e06b5a4..6d4a9438 100644 --- a/src/MyService/MyServiceConfiguration.cs +++ b/src/MyService/MyServiceConfiguration.cs @@ -1,4 +1,6 @@ -using MyMessages.Messages; +using System; +using Microsoft.Data.SqlClient; +using MyMessages.Messages; using NServiceBus; namespace MyService @@ -8,15 +10,26 @@ class MyServiceConfiguration : EndpointConfiguration public MyServiceConfiguration() : base("MyService") { + var connectionString = "Data Source=.;Initial Catalog=db;User ID=sa;Password=YourStrong@Passw0rd;Max Pool Size=80"; + var scanner = this.AssemblyScanner(); - scanner.IncludeOnly("MyService.dll", "MyMessages.dll"); + scanner.IncludeOnly("MyService.dll", + "MyMessages.dll", + "NServiceBus.Transport.SqlServer.dll", + "NServiceBus.Persistence.Sql.dll"); this.UseSerialization(); - this.UsePersistence(); this.EnableInstallers(); + + this.EnableOutbox(); + + var persistence = this.UsePersistence(); + persistence.SqlDialect(); + persistence.ConnectionBuilder(() => new SqlConnection(connectionString)); - var transportConfig = this.UseTransport(); - + var transportConfig = this.UseTransport() + .ConnectionString(connectionString); + transportConfig.Transactions(TransportTransactionMode.SendsAtomicWithReceive); transportConfig.Routing() .RouteToEndpoint(typeof(AMessage), "MyOtherService"); From c9a1e1cc7c9a371fef68292e023bc981deb92b09 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 10 Dec 2021 18:26:19 +0100 Subject: [PATCH 7/7] Update Nunit and NSB Testing package --- .../MySystem.AcceptanceTests.csproj | 4 ++-- .../NServiceBus.IntegrationTesting.Tests.csproj | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj index a28e3e04..c1423d8b 100644 --- a/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj +++ b/src/MySystem.AcceptanceTests/MySystem.AcceptanceTests.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj b/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj index ac4abb7f..a9e85e7f 100644 --- a/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj +++ b/src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive