-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEndToEndTestBase.cs
More file actions
50 lines (42 loc) · 1.83 KB
/
EndToEndTestBase.cs
File metadata and controls
50 lines (42 loc) · 1.83 KB
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
using System.Text;
using System.Text.Json;
using BuslyCLI.Infrastructure;
using BuslyCLI.Infrastructure.Endpoints;
using BuslyCLI.Infrastructure.Factories;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus.Transport;
using Spectre.Console.Cli.Extensions.DependencyInjection;
using Spectre.Console.Cli.Testing;
using TransportConfig = BuslyCLI.Config.TransportConfig;
namespace BuslyCLI.Console.Tests.EndToEnd;
public abstract class EndToEndTestBase
{
protected CommandAppTester _sut;
protected readonly JsonSerializerOptions _jsonObjectOptions =
new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
protected RawEndpoint TestEndpoint;
protected abstract TransportConfig CreateTransportConfig();
[SetUp]
public async Task Setup()
{
var registrations = new ServiceCollection();
registrations.AddBuslyCLIServices();
using var registrar = new DependencyInjectionRegistrar(registrations);
_sut = new CommandAppTester(registrar);
_sut.Configure(AppConfiguration.GetSpectreCommandConfiguration());
TestEndpoint = await new RawEndpointFactory()
.CreateRawEndpoint(TestEndpointNameGenerator.GenerateUniqueEndpointName(), CreateTransportConfig());
await TestEndpoint.StartEndpoint();
}
[TearDown]
public async Task TearDown()
{
await TestEndpoint.ShutDownAndCleanUp();
}
protected static void AssertMessageReceived(IncomingMessage message, string enclosedMessageType, string expectedBody)
{
Assert.That(message.Headers["NServiceBus.EnclosedMessageTypes"], Is.EqualTo(enclosedMessageType));
Assert.That(message.Headers["NServiceBus.ContentType"], Is.EqualTo("application/json"));
Assert.That(Encoding.UTF8.GetString(message.Body.Span), Is.EqualTo(expectedBody));
}
}