Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance tests small todos (#4001)
* Remove TODO since we can't dynamically change the database settings yet without resolving the database configuration from DI * Moved some things to test specific overrides * EndpointConfigurationExtensions for testing * Remove compile include * Apply suggestions from code review Co-authored-by: Mauro Servienti <mauro.servienti@gmail.com> * Styling * Align controller loading for ATTs --------- Co-authored-by: Mauro Servienti <mauro.servienti@gmail.com>
- Loading branch information
1 parent
e4122d7
commit 5d7216d
Showing
15 changed files
with
220 additions
and
167 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/ServiceControl.AcceptanceTests/TestSupport/EndpointConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
namespace ServiceControl.AcceptanceTests.TestSupport | ||
{ | ||
using System.IO; | ||
using AcceptanceTesting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.Configuration.AdvancedExtensibility; | ||
|
||
public static class EndpointConfigurationExtensions | ||
{ | ||
public static void ReportSuccessfulRetriesToServiceControl(this EndpointConfiguration configuration) | ||
{ | ||
configuration.Pipeline.Register(typeof(ReportSuccessfulRetryToServiceControl), "Simulate that the audit instance detects and reports successfull retries"); | ||
} | ||
|
||
public static void CustomizeServiceControlEndpointTesting(this EndpointConfiguration configuration, ScenarioContext context) | ||
{ | ||
configuration.GetSettings().Set("SC.ScenarioContext", context); | ||
configuration.GetSettings().Set(context); | ||
|
||
configuration.RegisterComponents(r => | ||
{ | ||
r.AddSingleton(context.GetType(), context); | ||
r.AddSingleton(typeof(ScenarioContext), context); | ||
}); | ||
|
||
configuration.Pipeline.Register<TraceIncomingBehavior.Registration>(); | ||
configuration.Pipeline.Register<TraceOutgoingBehavior.Registration>(); | ||
configuration.Pipeline.Register(new StampDispatchBehavior(context), "Stamps outgoing messages with session ID"); | ||
configuration.Pipeline.Register(new DiscardMessagesBehavior(context), "Discards messages based on session ID"); | ||
|
||
var assemblyScanner = configuration.AssemblyScanner(); | ||
assemblyScanner.ExcludeAssemblies(Path.GetFileName(typeof(ServiceControlComponentRunner).Assembly.Location)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/ServiceControl.AcceptanceTests/TestSupport/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace ServiceControl.AcceptanceTests.RavenDB.Shared; | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using ServiceBus.Management.Infrastructure.Settings; | ||
using TestSupport; | ||
|
||
static class WebApplicationBuilderExtensions | ||
{ | ||
public static void AddServiceControlTesting(this WebApplicationBuilder hostBuilder, Settings settings) | ||
{ | ||
// Do not register additional test controllers or hosted services here. Instead, in the test that needs them, use (for example): | ||
// CustomizeHostBuilder = builder => builder.ConfigureServices((hostContext, services) => services.AddHostedService<SetupNotificationSettings>()); | ||
hostBuilder.Logging.AddScenarioContextLogging(); | ||
|
||
hostBuilder.WebHost.UseTestServer(options => options.BaseAddress = new Uri(settings.RootUrl)); | ||
hostBuilder.Services.AddSingleton<IHostLifetime, TestServerHostLifetime>(); | ||
|
||
// This facilitates receiving the test server anywhere where DI is available | ||
hostBuilder.Services.AddSingleton(provider => (TestServer)provider.GetRequiredService<IServer>()); | ||
|
||
// By default, ASP.NET Core uses the entry point assembly to discover controllers. When running | ||
// inside a test runner the runner exe becomes the entry point which obviously has no controllers in it ;) | ||
// so we are explicitly registering all necessary application parts. | ||
var addControllers = hostBuilder.Services.AddControllers(); | ||
addControllers.AddApplicationPart(typeof(Settings).Assembly); | ||
addControllers.AddApplicationPart(typeof(AcceptanceTest).Assembly); | ||
|
||
hostBuilder.Services.AddHttpClientDefaultsOverrides(settings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/ServiceControl.Audit.AcceptanceTests/TestSupport/EndpointConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace ServiceControl.Audit.AcceptanceTests.TestSupport; | ||
|
||
using System.IO; | ||
using AcceptanceTesting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.Configuration.AdvancedExtensibility; | ||
|
||
static class EndpointConfigurationExtensions | ||
{ | ||
public static void CustomizeServiceControlAuditEndpointTesting(this EndpointConfiguration configuration, ScenarioContext context) | ||
{ | ||
configuration.GetSettings().Set("SC.ScenarioContext", context); | ||
configuration.GetSettings().Set(context); | ||
|
||
configuration.RegisterComponents(r => | ||
{ | ||
r.AddSingleton(context.GetType(), context); | ||
r.AddSingleton(typeof(ScenarioContext), context); | ||
}); | ||
|
||
configuration.Pipeline.Register<TraceIncomingBehavior.Registration>(); | ||
configuration.Pipeline.Register<TraceOutgoingBehavior.Registration>(); | ||
configuration.Pipeline.Register(new StampDispatchBehavior(context), "Stamps outgoing messages with session ID"); | ||
configuration.Pipeline.Register(new DiscardMessagesBehavior(context), "Discards messages based on session ID"); | ||
|
||
var assemblyScanner = configuration.AssemblyScanner(); | ||
assemblyScanner.ExcludeAssemblies(Path.GetFileName(typeof(ServiceControlComponentRunner).Assembly.Location)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/ServiceControl.Audit.AcceptanceTests/TestSupport/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace ServiceControl.Audit.AcceptanceTests.TestSupport; | ||
|
||
using System; | ||
using Auditing; | ||
using Infrastructure.Settings; | ||
using Infrastructure.WebApi; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting.Server; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
static class WebApplicationBuilderExtensions | ||
{ | ||
public static void AddServiceControlAuditTesting(this WebApplicationBuilder hostBuilder, Settings settings) | ||
{ | ||
// Do not register additional test controllers or hosted services here. Instead, in the test that needs them, use (for example): | ||
// CustomizeHostBuilder = builder => builder.ConfigureServices((hostContext, services) => services.AddHostedService<SetupNotificationSettings>()); | ||
hostBuilder.Logging.AddScenarioContextLogging(); | ||
|
||
hostBuilder.WebHost.UseTestServer(options => options.BaseAddress = new Uri(settings.RootUrl)); | ||
// This facilitates receiving the test server anywhere where DI is available | ||
hostBuilder.Services.AddSingleton(provider => (TestServer)provider.GetRequiredService<IServer>()); | ||
|
||
// By default, ASP.NET Core uses the entry point assembly to discover controllers. When running | ||
// inside a test runner the runner exe becomes the entry point which obviously has no controllers in it ;) | ||
// so we are explicitly registering all necessary application parts. | ||
var addControllers = hostBuilder.Services.AddControllers(); | ||
addControllers.AddApplicationPart(typeof(Settings).Assembly); | ||
addControllers.AddApplicationPart(typeof(AcceptanceTest).Assembly); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.