11
11
12
12
public class When_using_auto_delete_on_idle : NServiceBusAcceptanceTest
13
13
{
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
+
15
18
[ SetUp ]
16
19
public async Task Setup ( )
17
20
{
@@ -21,7 +24,9 @@ public async Task Setup()
21
24
try
22
25
{
23
26
// 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 ) ;
25
30
}
26
31
catch ( ServiceBusException ex ) when ( ex . Reason == ServiceBusFailureReason . MessagingEntityNotFound )
27
32
{
@@ -49,11 +54,59 @@ public async Task Should_configure_queue_with_auto_delete_on_idle()
49
54
var adminClient = new ServiceBusAdministrationClient (
50
55
Environment . GetEnvironmentVariable ( "AzureServiceBus_ConnectionString" ) ) ;
51
56
52
- var queueProperties = await adminClient . GetQueueAsync ( ResultingEndpointInstanceName ) ;
57
+ var queueProperties = await adminClient . GetQueueAsync ( HasAutoDeleteOnIdleEndpointInstanceName ) ;
53
58
54
59
Assert . That ( queueProperties . Value . AutoDeleteOnIdle , Is . EqualTo ( TimeSpan . FromMinutes ( 10 ) ) ) ;
55
60
}
56
61
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
+
57
110
public class Context : ScenarioContext
58
111
{
59
112
}
@@ -65,5 +118,21 @@ public EndpointWithAutoDeleteOnIdle()
65
118
EndpointSetup < DefaultServer > ( ) ;
66
119
}
67
120
}
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
+ }
68
137
}
69
138
}
0 commit comments