-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathServiceBusContainerTest.cs
52 lines (38 loc) · 1.75 KB
/
ServiceBusContainerTest.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
namespace Testcontainers.ServiceBus;
public sealed class ServiceBusContainerTest : IAsyncLifetime
{
private readonly ServiceBusContainer _serviceBusContainer = new ServiceBusBuilder().WithAcceptLicenseAgreement(true).Build();
public Task InitializeAsync()
{
return _serviceBusContainer.StartAsync();
}
public Task DisposeAsync()
{
return _serviceBusContainer.DisposeAsync().AsTask();
}
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task ReceiveMessageReturnsSentMessage()
{
// Given
const string helloServiceBus = "Hello, Service Bus!";
// Upload your configuration before the container starts using the
// `WithResourceMapping(string, string)` API or one of its overloads:
// `WithResourceMapping("Config.json", "/ServiceBus_Emulator/ConfigFiles/")`.
// By default, the emulator uses the following configuration:
// https://learn.microsoft.com/en-us/azure/service-bus-messaging/test-locally-with-service-bus-emulator?tabs=automated-script#interact-with-the-emulator.
const string queueName = "queue.1";
var message = new ServiceBusMessage(helloServiceBus);
await using var client = new ServiceBusClient(_serviceBusContainer.GetConnectionString());
await Task.Delay(1000);
var sender = client.CreateSender(queueName);
var receiver = client.CreateReceiver(queueName);
// When
await sender.SendMessageAsync(message)
.ConfigureAwait(true);
var receivedMessage = await receiver.ReceiveMessageAsync()
.ConfigureAwait(true);
// Then
Assert.Equal(helloServiceBus, receivedMessage.Body.ToString());
}
}