/
AcceptanceTest.cs
67 lines (56 loc) · 2.53 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
namespace ServiceControl.Monitoring.AcceptanceTests
{
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using AcceptanceTesting;
using Monitoring;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTesting.Support;
using NUnit.Framework;
using ServiceControl.AcceptanceTesting.InfrastructureConfig;
using TestSupport;
[TestFixture]
abstract class AcceptanceTest : NServiceBusAcceptanceTest, IAcceptanceTestInfrastructureProvider
{
public HttpClient HttpClient => serviceControlRunnerBehavior.HttpClient;
public JsonSerializerOptions SerializerOptions => serviceControlRunnerBehavior.SerializerOptions;
[SetUp]
public void Setup()
{
SetSettings = _ => { };
CustomConfiguration = _ => { };
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, s => SetSettings(s), s => CustomConfiguration(s));
}
[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> CustomConfiguration = _ => { };
protected Action<Settings> SetSettings = _ => { };
protected ITransportIntegration TransportIntegration;
ServiceControlComponentBehavior serviceControlRunnerBehavior;
TextWriterTraceListener textWriterTraceListener;
}
}