/
AcceptanceTest.cs
87 lines (75 loc) · 3.94 KB
/
AcceptanceTest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace ServiceControl.MultiInstance.AcceptanceTests
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using AcceptanceTesting;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTesting.Support;
using NUnit.Framework;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.AcceptanceTesting.InfrastructureConfig;
using TestSupport;
[TestFixture]
abstract class AcceptanceTest : NServiceBusAcceptanceTest, IAcceptanceTestInfrastructureProviderMultiInstance
{
protected static string ServiceControlInstanceName { get; } = Settings.DEFAULT_SERVICE_NAME;
protected static string ServiceControlAuditInstanceName { get; } = Audit.Infrastructure.Settings.Settings.DEFAULT_SERVICE_NAME;
public Dictionary<string, HttpClient> HttpClients => serviceControlRunnerBehavior.HttpClients;
public Dictionary<string, JsonSerializerOptions> SerializerOptions => serviceControlRunnerBehavior.SerializerOptions;
public Dictionary<string, dynamic> SettingsPerInstance => serviceControlRunnerBehavior.SettingsPerInstance;
[SetUp]
public void Setup()
{
CustomPrimaryEndpointConfiguration = c => { };
CustomAuditEndpointConfiguration = c => { };
CustomServiceControlPrimarySettings = s => { };
CustomServiceControlAuditSettings = s => { };
var logfilesPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "logs");
Directory.CreateDirectory(logfilesPath);
var logFile = Path.Combine(logfilesPath, $"{TestContext.CurrentContext.Test.ID}-{TestContext.CurrentContext.Test.Name}.txt");
if (File.Exists(logFile))
{
File.Delete(logFile);
}
textWriterTraceListener = new TextWriterTraceListener(logFile);
Trace.Listeners.Add(textWriterTraceListener);
TransportIntegration = new ConfigureEndpointLearningTransport();
serviceControlRunnerBehavior = new ServiceControlComponentBehavior(
TransportIntegration,
c => CustomPrimaryEndpointConfiguration(c),
c => CustomAuditEndpointConfiguration(c),
s => CustomServiceControlPrimarySettings(s),
s => CustomServiceControlAuditSettings(s),
b => PrimaryHostBuilderCustomization(b),
b => AuditHostBuilderCustomization(b)
);
}
[TearDown]
public void Teardown()
{
TransportIntegration = null;
Trace.Flush();
Trace.Close();
Trace.Listeners.Remove(textWriterTraceListener);
}
protected IScenarioWithEndpointBehavior<T> Define<T>() where T : ScenarioContext, new() => Define<T>(c => { });
protected IScenarioWithEndpointBehavior<T> Define<T>(Action<T> contextInitializer) where T : ScenarioContext, new() =>
Scenario.Define(contextInitializer)
.WithComponent(serviceControlRunnerBehavior);
protected Action<EndpointConfiguration> CustomPrimaryEndpointConfiguration = c => { };
protected Action<EndpointConfiguration> CustomAuditEndpointConfiguration = c => { };
protected Action<Settings> CustomServiceControlPrimarySettings = c => { };
protected Action<Audit.Infrastructure.Settings.Settings> CustomServiceControlAuditSettings = c => { };
protected Action<IHostApplicationBuilder> PrimaryHostBuilderCustomization = b => { };
protected Action<IHostApplicationBuilder> AuditHostBuilderCustomization = b => { };
protected ITransportIntegration TransportIntegration;
ServiceControlComponentBehavior serviceControlRunnerBehavior;
TextWriterTraceListener textWriterTraceListener;
}
}