forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceBusAdministrationClientTest.cs
More file actions
77 lines (59 loc) · 2.56 KB
/
ServiceBusAdministrationClientTest.cs
File metadata and controls
77 lines (59 loc) · 2.56 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
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
namespace Testcontainers.ServiceBus;
public abstract class ServiceBusAdministrationClientTest : IAsyncLifetime
{
private readonly ServiceBusContainer _serviceBusContainer;
private ServiceBusAdministrationClientTest(ServiceBusContainer serviceBusContainer)
{
_serviceBusContainer = serviceBusContainer;
}
public async ValueTask InitializeAsync()
{
await _serviceBusContainer.StartAsync()
.ConfigureAwait(false);
}
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore()
.ConfigureAwait(false);
GC.SuppressFinalize(this);
}
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task CreateQueueViaServiceBusAdministrationClient()
{
// Given
const string helloServiceBus = "Hello, Service Bus!";
var queueName = $"sample-queue-{Guid.NewGuid()}";
// 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.
var message = new ServiceBusMessage(helloServiceBus);
await using var client = new ServiceBusClient(_serviceBusContainer.GetConnectionString());
var adminClient = new ServiceBusAdministrationClient(_serviceBusContainer.GetHttpConnectionString());
var sender = client.CreateSender(queueName);
var receiver = client.CreateReceiver(queueName);
// When
await adminClient.CreateQueueAsync(new CreateQueueOptions(queueName), TestContext.Current.CancellationToken)
.ConfigureAwait(true);
await sender.SendMessageAsync(message, TestContext.Current.CancellationToken)
.ConfigureAwait(true);
var receivedMessage = await receiver.ReceiveMessageAsync(cancellationToken: TestContext.Current.CancellationToken)
.ConfigureAwait(true);
// Then
Assert.NotNull(receivedMessage);
Assert.Equal(helloServiceBus, receivedMessage.Body.ToString());
}
protected virtual ValueTask DisposeAsyncCore()
{
return _serviceBusContainer.DisposeAsync();
}
[UsedImplicitly]
public sealed class ServiceBusDefaultMsSqlConfiguration : ServiceBusAdministrationClientTest
{
public ServiceBusDefaultMsSqlConfiguration()
: base(new ServiceBusBuilder(TestSession.GetImageFromDockerfile())
.WithAcceptLicenseAgreement(true)
.Build())
{
}
}
}