/
StartupModeTests.cs
74 lines (61 loc) · 2.68 KB
/
StartupModeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace ServiceControl.AcceptanceTests.RavenDB
{
using System;
using System.Threading.Tasks;
using Hosting.Commands;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using NUnit.Framework;
using Particular.ServiceControl.Hosting;
using Persistence;
using Persistence.RavenDB;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.AcceptanceTesting.InfrastructureConfig;
class StartupModeTests : AcceptanceTest
{
Settings settings;
AcceptanceTestStorageConfiguration configuration;
[SetUp]
public async Task InitializeSettings()
{
var transportIntegration = new ConfigureEndpointLearningTransport();
settings = new Settings(
forwardErrorMessages: false,
errorRetentionPeriod: TimeSpan.FromDays(1),
persisterType: typeof(RavenPersistenceConfiguration).AssemblyQualifiedName)
{
TransportType = transportIntegration.TypeName,
TransportConnectionString = transportIntegration.ConnectionString,
};
configuration = new AcceptanceTestStorageConfiguration();
await configuration.CustomizeSettings(settings);
}
[TearDown]
public async Task Cleanup() => await configuration.Cleanup();
[Test]
public async Task CanRunMaintenanceMode()
{
// ideally we'd be using the MaintenanceModeCommand here but that indefinitely blocks due to the RunAsync
// not terminating.
var hostBuilder = Host.CreateApplicationBuilder();
hostBuilder.Services.AddPersistence(settings, maintenanceMode: true);
using var host = hostBuilder.Build();
await host.StartAsync();
await host.StopAsync();
}
[Test]
public async Task CanRunImportFailedMessagesMode()
=> await new TestableImportFailedErrorsCommand().Execute(new HostArguments(Array.Empty<string>()), settings);
class TestableImportFailedErrorsCommand : ImportFailedErrorsCommand
{
protected override EndpointConfiguration CreateEndpointConfiguration(Settings settings)
{
var configuration = base.CreateEndpointConfiguration(settings);
//HINT: we want to exclude this assembly to prevent loading features that are part of the acceptance testing framework
var thisAssembly = new[] { typeof(StartupModeTests).Assembly.GetName().Name };
configuration.AssemblyScanner().ExcludeAssemblies(thisAssembly);
return configuration;
}
}
}
}