Skip to content

Commit 378cb78

Browse files
Add additional tests
1 parent 6af564a commit 378cb78

File tree

1 file changed

+72
-3
lines changed

1 file changed

+72
-3
lines changed

src/AcceptanceTests/When_using_auto_delete_on_idle.cs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
public class When_using_auto_delete_on_idle : NServiceBusAcceptanceTest
1313
{
14-
const string ResultingEndpointInstanceName = "usingautodeleteonidle.endpointwithautodeleteonidle-12345";
14+
const string HasAutoDeleteOnIdleEndpointInstanceName = "usingautodeleteonidle.endpointwithautodeleteonidle-12345";
15+
const string NoAutoDeleteOnIdleEndpointInstanceName = "usingautodeleteonidle.endpointwithoutautodeleteonidle";
16+
const string HasAutoDeleteOnIdleButNoInstancesEndpointName = "usingautodeleteonidle.endpointwithautodeleteonidlebutnoinstances";
17+
1518
[SetUp]
1619
public async Task Setup()
1720
{
@@ -21,7 +24,9 @@ public async Task Setup()
2124
try
2225
{
2326
// makes sure during local development the topic gets cleared before each test run
24-
await adminClient.DeleteQueueAsync(ResultingEndpointInstanceName);
27+
await adminClient.DeleteQueueAsync(HasAutoDeleteOnIdleEndpointInstanceName);
28+
await adminClient.DeleteQueueAsync(NoAutoDeleteOnIdleEndpointInstanceName);
29+
await adminClient.DeleteQueueAsync(HasAutoDeleteOnIdleButNoInstancesEndpointName);
2530
}
2631
catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
2732
{
@@ -49,11 +54,59 @@ public async Task Should_configure_queue_with_auto_delete_on_idle()
4954
var adminClient = new ServiceBusAdministrationClient(
5055
Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"));
5156

52-
var queueProperties = await adminClient.GetQueueAsync(ResultingEndpointInstanceName);
57+
var queueProperties = await adminClient.GetQueueAsync(HasAutoDeleteOnIdleEndpointInstanceName);
5358

5459
Assert.That(queueProperties.Value.AutoDeleteOnIdle, Is.EqualTo(TimeSpan.FromMinutes(10)));
5560
}
5661

62+
[Test]
63+
public async Task Should_not_configure_queue_with_auto_delete_on_idle()
64+
{
65+
var context = await Scenario.Define<Context>()
66+
.WithEndpoint<EndpointWithoutAutoDeleteOnIdle>(b =>
67+
{
68+
b.CustomConfig(c =>
69+
{
70+
c.ConfigureTransport<AzureServiceBusTransport>();
71+
});
72+
})
73+
.Done(c => c.EndpointsStarted)
74+
.Run();
75+
76+
// Verify that the queue was created with the correct AutoDeleteOnIdle setting
77+
var adminClient = new ServiceBusAdministrationClient(
78+
Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"));
79+
80+
var queueProperties = await adminClient.GetQueueAsync(NoAutoDeleteOnIdleEndpointInstanceName);
81+
82+
Assert.That(queueProperties.Value.AutoDeleteOnIdle, Is.EqualTo(TimeSpan.MaxValue));
83+
}
84+
85+
[Test]
86+
public async Task Should_not_configure_queue_with_auto_delete_on_idle_if_no_unique_instances()
87+
{
88+
var context = await Scenario.Define<Context>()
89+
.WithEndpoint<EndpointWithAutoDeleteOnIdleButNoInstances>(b =>
90+
{
91+
b.CustomConfig(c =>
92+
{
93+
var transport = c.ConfigureTransport<AzureServiceBusTransport>();
94+
transport.AutoDeleteOnIdle = TimeSpan.FromMinutes(10);
95+
});
96+
})
97+
.Done(c => c.EndpointsStarted)
98+
.Run();
99+
100+
// Verify that the queue was created with the correct AutoDeleteOnIdle setting
101+
var adminClient = new ServiceBusAdministrationClient(
102+
Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString"));
103+
104+
var queueProperties = await adminClient.GetQueueAsync(HasAutoDeleteOnIdleButNoInstancesEndpointName);
105+
106+
Assert.That(queueProperties.Value.AutoDeleteOnIdle, Is.EqualTo(TimeSpan.MaxValue));
107+
}
108+
109+
57110
public class Context : ScenarioContext
58111
{
59112
}
@@ -65,5 +118,21 @@ public EndpointWithAutoDeleteOnIdle()
65118
EndpointSetup<DefaultServer>();
66119
}
67120
}
121+
122+
public class EndpointWithoutAutoDeleteOnIdle : EndpointConfigurationBuilder
123+
{
124+
public EndpointWithoutAutoDeleteOnIdle()
125+
{
126+
EndpointSetup<DefaultServer>();
127+
}
128+
}
129+
130+
public class EndpointWithAutoDeleteOnIdleButNoInstances : EndpointConfigurationBuilder
131+
{
132+
public EndpointWithAutoDeleteOnIdleButNoInstances()
133+
{
134+
EndpointSetup<DefaultServer>();
135+
}
136+
}
68137
}
69138
}

0 commit comments

Comments
 (0)