1010using AuditThroughput ;
1111using Contracts ;
1212using Infrastructure ;
13+ using Microsoft . Extensions . Configuration ;
1314using Microsoft . Extensions . Logging . Abstractions ;
1415using Microsoft . Extensions . Time . Testing ;
1516using NuGet . Versioning ;
1617using NUnit . Framework ;
1718using ServiceControl . Transports . BrokerThroughput ;
19+ using Shared ;
1820
1921[ TestFixture ]
2022class AuditThroughputCollectorHostedService_Tests : ThroughputCollectorTestFixture
@@ -34,11 +36,19 @@ public async Task Should_handle_no_audit_remotes()
3436 CancellationToken token = tokenSource . Token ;
3537 var fakeTimeProvider = new FakeTimeProvider ( ) ;
3638 var auditQuery = new AuditQuery_NoAuditRemotes ( ) ;
39+ var emptyConfig = new ConfigurationBuilder ( ) . Build ( ) ;
3740
3841 using var auditThroughputCollectorHostedService = new AuditThroughputCollectorHostedService (
39- NullLogger < AuditThroughputCollectorHostedService > . Instance , configuration . ThroughputSettings , DataStore ,
40- auditQuery , fakeTimeProvider )
41- { DelayStart = TimeSpan . Zero } ;
42+ NullLogger < AuditThroughputCollectorHostedService > . Instance ,
43+ configuration . ThroughputSettings ,
44+ DataStore ,
45+ auditQuery ,
46+ fakeTimeProvider ,
47+ new PlatformEndpointHelper ( new ServiceControlSettings ( emptyConfig ) )
48+ )
49+ {
50+ DelayStart = TimeSpan . Zero
51+ } ;
4252
4353 //Act
4454 await auditThroughputCollectorHostedService . StartAsync ( token ) ;
@@ -64,10 +74,17 @@ public async Task Should_handle_exceptions_in_try_block_and_continue()
6474 var fakeTimeProvider = new FakeTimeProvider ( ) ;
6575 var auditQuery = new AuditQuery_ThrowingAnExceptionOnKnownEndpointsCall ( ) ;
6676
77+ var emptyConfig = new ConfigurationBuilder ( ) . Build ( ) ;
78+
6779 using var auditThroughputCollectorHostedService = new AuditThroughputCollectorHostedService (
6880 NullLogger < AuditThroughputCollectorHostedService > . Instance , configuration . ThroughputSettings , DataStore ,
69- auditQuery , fakeTimeProvider )
70- { DelayStart = TimeSpan . Zero } ;
81+ auditQuery ,
82+ fakeTimeProvider ,
83+ new PlatformEndpointHelper ( new ServiceControlSettings ( emptyConfig ) )
84+ )
85+ {
86+ DelayStart = TimeSpan . Zero
87+ } ;
7188
7289 //Act
7390 await auditThroughputCollectorHostedService . StartAsync ( token ) ;
@@ -91,11 +108,17 @@ public async Task Should_handle_cancellation_token_gracefully()
91108 var tokenSource = new CancellationTokenSource ( TimeSpan . FromSeconds ( 3 ) ) ;
92109 CancellationToken token = tokenSource . Token ;
93110 var fakeTimeProvider = new FakeTimeProvider ( ) ;
111+ var emptyConfig = new ConfigurationBuilder ( ) . Build ( ) ;
94112
95113 using var auditThroughputCollectorHostedService = new AuditThroughputCollectorHostedService (
96114 NullLogger < AuditThroughputCollectorHostedService > . Instance , configuration . ThroughputSettings , DataStore ,
97- configuration . AuditQuery , fakeTimeProvider )
98- { DelayStart = TimeSpan . Zero } ;
115+ configuration . AuditQuery ,
116+ fakeTimeProvider ,
117+ new PlatformEndpointHelper ( new ServiceControlSettings ( emptyConfig ) )
118+ )
119+ {
120+ DelayStart = TimeSpan . Zero
121+ } ;
99122
100123 //Act
101124 await auditThroughputCollectorHostedService . StartAsync ( token ) ;
@@ -116,11 +139,17 @@ public async Task Should_sanitize_endpoint_name()
116139 string endpointName = "e$ndpoint&1" ;
117140 var auditQuery = new AuditQuery_WithOneEndpoint ( endpointName , 0 , DateOnly . FromDateTime ( DateTime . UtcNow ) ) ;
118141 string endpointNameSanitized = "e-ndpoint-1" ;
142+ var emptyConfig = new ConfigurationBuilder ( ) . Build ( ) ;
119143
120144 using var auditThroughputCollectorHostedService = new AuditThroughputCollectorHostedService (
121145 NullLogger < AuditThroughputCollectorHostedService > . Instance , configuration . ThroughputSettings , DataStore ,
122- auditQuery , fakeTimeProvider , new BrokerThroughputQuery_WithSanitization ( ) )
123- { DelayStart = TimeSpan . Zero } ;
146+ auditQuery ,
147+ fakeTimeProvider ,
148+ new PlatformEndpointHelper ( new ServiceControlSettings ( emptyConfig ) )
149+ )
150+ {
151+ DelayStart = TimeSpan . Zero
152+ } ;
124153
125154 //Act
126155 await auditThroughputCollectorHostedService . StartAsync ( token ) ;
@@ -152,11 +181,16 @@ public async Task Should_not_add_the_same_endpoint_throughput_if_runs_twice_on_t
152181 var throughputDate = DateOnly . FromDateTime ( DateTime . UtcNow . AddDays ( - 1 ) ) ;
153182 long throughputCount = 5 ;
154183 var auditQuery = new AuditQuery_WithOneEndpoint ( endpointName , throughputCount , throughputDate ) ;
184+ var emptyConfig = new ConfigurationBuilder ( ) . Build ( ) ;
155185
156186 using var auditThroughputCollectorHostedService = new AuditThroughputCollectorHostedService (
157187 NullLogger < AuditThroughputCollectorHostedService > . Instance , configuration . ThroughputSettings , DataStore ,
158- auditQuery : auditQuery , fakeTimeProvider )
159- { DelayStart = TimeSpan . Zero } ;
188+ auditQuery : auditQuery ,
189+ fakeTimeProvider ,
190+ new PlatformEndpointHelper ( new ServiceControlSettings ( emptyConfig ) ) )
191+ {
192+ DelayStart = TimeSpan . Zero
193+ } ;
160194
161195 //Act
162196 await auditThroughputCollectorHostedService . StartAsync ( token1 ) ;
@@ -224,7 +258,11 @@ public Task<IEnumerable<ServiceControlEndpoint>> GetKnownEndpoints(CancellationT
224258
225259 public Task < ConnectionSettingsTestResult > TestAuditConnection ( CancellationToken cancellationToken ) =>
226260 Task . FromResult (
227- new ConnectionSettingsTestResult { ConnectionSuccessful = true , ConnectionErrorMessages = [ ] } ) ;
261+ new ConnectionSettingsTestResult
262+ {
263+ ConnectionSuccessful = true ,
264+ ConnectionErrorMessages = [ ]
265+ } ) ;
228266
229267 public bool InstanceParameter { get ; set ; }
230268 }
@@ -245,23 +283,38 @@ public AuditQuery_WithOneEndpoint(string endpointName, long throughputCount, Dat
245283 public Task < IEnumerable < AuditCount > > GetAuditCountForEndpoint ( string endpointUrlName ,
246284 CancellationToken cancellationToken )
247285 {
248- var auditCount = new AuditCount { UtcDate = ThroughputDate , Count = ThroughputCount } ;
286+ var auditCount = new AuditCount
287+ {
288+ UtcDate = ThroughputDate ,
289+ Count = ThroughputCount
290+ } ;
249291
250- return Task . FromResult ( new List < AuditCount > { auditCount } . AsEnumerable ( ) ) ;
292+ return Task . FromResult ( new List < AuditCount >
293+ {
294+ auditCount
295+ } . AsEnumerable ( ) ) ;
251296 }
252297
253298 public Task < List < RemoteInstanceInformation > > GetAuditRemotes ( CancellationToken cancellationToken ) =>
254299 Task . FromResult < List < RemoteInstanceInformation > > ( [ ] ) ;
255300
256301 public Task < IEnumerable < ServiceControlEndpoint > > GetKnownEndpoints ( CancellationToken cancellationToken )
257302 {
258- var scEndpoint = new ServiceControlEndpoint { Name = EndpointName , HeartbeatsEnabled = true } ;
303+ var scEndpoint = new ServiceControlEndpoint
304+ {
305+ Name = EndpointName ,
306+ HeartbeatsEnabled = true
307+ } ;
259308 return Task . FromResult < IEnumerable < ServiceControlEndpoint > > ( [ scEndpoint ] ) ;
260309 }
261310
262311 public Task < ConnectionSettingsTestResult > TestAuditConnection ( CancellationToken cancellationToken ) =>
263312 Task . FromResult (
264- new ConnectionSettingsTestResult { ConnectionSuccessful = true , ConnectionErrorMessages = [ ] } ) ;
313+ new ConnectionSettingsTestResult
314+ {
315+ ConnectionSuccessful = true ,
316+ ConnectionErrorMessages = [ ]
317+ } ) ;
265318
266319 string EndpointName { get ; }
267320 long ThroughputCount { get ; }
0 commit comments