@@ -70,7 +70,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Registered()
70
70
Api . Instance . AddHandler ( ProviderEventTypes . ProviderStale , eventHandler ) ;
71
71
72
72
var testProvider = new TestProvider ( ) ;
73
- await Api . Instance . SetProvider ( testProvider ) ;
73
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
74
74
75
75
testProvider . SendEvent ( ProviderEventTypes . ProviderConfigurationChanged ) ;
76
76
testProvider . SendEvent ( ProviderEventTypes . ProviderError ) ;
@@ -117,7 +117,33 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_
117
117
var eventHandler = Substitute . For < EventHandlerDelegate > ( ) ;
118
118
119
119
var testProvider = new TestProvider ( ) ;
120
- await Api . Instance . SetProvider ( testProvider ) ;
120
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
121
+
122
+ Api . Instance . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
123
+
124
+ await Utils . AssertUntilAsync ( _ => eventHandler
125
+ . Received ( )
126
+ . Invoke (
127
+ Arg . Is < ProviderEventPayload > (
128
+ payload => payload . ProviderName == testProvider . GetMetadata ( ) . Name && payload . Type == ProviderEventTypes . ProviderReady
129
+ ) ) ) ;
130
+ }
131
+
132
+ [ Fact ]
133
+ [ Specification ( "5.1.2" , "When a `provider` signals the occurrence of a particular `event`, the associated `client` and `API` event handlers MUST run." ) ]
134
+ [ Specification ( "5.2.2" , "The `API` MUST provide a function for associating `handler functions` with a particular `provider event type`." ) ]
135
+ [ Specification ( "5.2.3" , "The `event details` MUST contain the `provider name` associated with the event." ) ]
136
+ [ Specification ( "5.2.4" , "The `handler function` MUST accept a `event details` parameter." ) ]
137
+ [ Specification ( "5.3.1" , "If the provider's `initialize` function terminates normally, `PROVIDER_READY` handlers MUST run." ) ]
138
+ [ Specification ( "5.3.3" , "Handlers attached after the provider is already in the associated state, MUST run immediately." ) ]
139
+ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_After_Registering_Provider_Ready_Sync ( )
140
+ {
141
+ var eventHandler = Substitute . For < EventHandlerDelegate > ( ) ;
142
+
143
+ var testProvider = new TestProvider ( ) ;
144
+ #pragma warning disable CS0618 // Type or member is obsolete
145
+ Api . Instance . SetProvider ( testProvider ) ;
146
+ #pragma warning restore CS0618 // Type or member is obsolete
121
147
122
148
Api . Instance . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
123
149
@@ -141,7 +167,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Error_State_
141
167
var eventHandler = Substitute . For < EventHandlerDelegate > ( ) ;
142
168
143
169
var testProvider = new TestProvider ( ) ;
144
- await Api . Instance . SetProvider ( testProvider ) ;
170
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
145
171
146
172
testProvider . SetStatus ( ProviderStatus . Error ) ;
147
173
@@ -166,7 +192,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Stale_State_
166
192
var eventHandler = Substitute . For < EventHandlerDelegate > ( ) ;
167
193
168
194
var testProvider = new TestProvider ( ) ;
169
- await Api . Instance . SetProvider ( testProvider ) ;
195
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
170
196
171
197
testProvider . SetStatus ( ProviderStatus . Stale ) ;
172
198
@@ -194,12 +220,12 @@ public async Task API_Level_Event_Handlers_Should_Be_Exchangeable()
194
220
Api . Instance . AddHandler ( ProviderEventTypes . ProviderConfigurationChanged , eventHandler ) ;
195
221
196
222
var testProvider = new TestProvider ( ) ;
197
- await Api . Instance . SetProvider ( testProvider ) ;
223
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
198
224
199
225
testProvider . SendEvent ( ProviderEventTypes . ProviderConfigurationChanged ) ;
200
226
201
227
var newTestProvider = new TestProvider ( ) ;
202
- await Api . Instance . SetProvider ( newTestProvider ) ;
228
+ await Api . Instance . SetProviderAsync ( newTestProvider ) ;
203
229
204
230
newTestProvider . SendEvent ( ProviderEventTypes . ProviderConfigurationChanged ) ;
205
231
@@ -223,13 +249,13 @@ public async Task API_Level_Event_Handlers_Should_Be_Removable()
223
249
Api . Instance . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
224
250
225
251
var testProvider = new TestProvider ( ) ;
226
- await Api . Instance . SetProvider ( testProvider ) ;
252
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
227
253
228
254
Thread . Sleep ( 1000 ) ;
229
255
Api . Instance . RemoveHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
230
256
231
257
var newTestProvider = new TestProvider ( ) ;
232
- await Api . Instance . SetProvider ( newTestProvider ) ;
258
+ await Api . Instance . SetProviderAsync ( newTestProvider ) ;
233
259
234
260
eventHandler . Received ( 1 ) . Invoke ( Arg . Is < ProviderEventPayload > ( payload => payload . ProviderName == testProvider . GetMetadata ( ) . Name ) ) ;
235
261
}
@@ -254,7 +280,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Executed_When_Other_Handler
254
280
Api . Instance . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
255
281
256
282
var testProvider = new TestProvider ( fixture . Create < string > ( ) ) ;
257
- await Api . Instance . SetProvider ( testProvider ) ;
283
+ await Api . Instance . SetProviderAsync ( testProvider ) ;
258
284
259
285
await Utils . AssertUntilAsync (
260
286
_ => failingEventHandler . Received ( ) . Invoke ( Arg . Is < ProviderEventPayload > ( payload => payload . ProviderName == testProvider . GetMetadata ( ) . Name ) )
@@ -277,7 +303,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Registered()
277
303
var myClient = Api . Instance . GetClient ( fixture . Create < string > ( ) ) ;
278
304
279
305
var testProvider = new TestProvider ( ) ;
280
- await Api . Instance . SetProvider ( myClient . GetMetadata ( ) . Name , testProvider ) ;
306
+ await Api . Instance . SetProviderAsync ( myClient . GetMetadata ( ) . Name , testProvider ) ;
281
307
282
308
myClient . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
283
309
@@ -306,7 +332,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Executed_When_Other_Hand
306
332
myClient . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
307
333
308
334
var testProvider = new TestProvider ( ) ;
309
- await Api . Instance . SetProvider ( myClient . GetMetadata ( ) . Name , testProvider ) ;
335
+ await Api . Instance . SetProviderAsync ( myClient . GetMetadata ( ) . Name , testProvider ) ;
310
336
311
337
await Utils . AssertUntilAsync (
312
338
_ => failingEventHandler . Received ( ) . Invoke ( Arg . Is < ProviderEventPayload > ( payload => payload . ProviderName == testProvider . GetMetadata ( ) . Name ) )
@@ -335,9 +361,9 @@ public async Task Client_Level_Event_Handlers_Should_Be_Registered_To_Default_Pr
335
361
var clientProvider = new TestProvider ( fixture . Create < string > ( ) ) ;
336
362
337
363
// set the default provider on API level, but not specifically to the client
338
- await Api . Instance . SetProvider ( apiProvider ) ;
364
+ await Api . Instance . SetProviderAsync ( apiProvider ) ;
339
365
// set the other provider specifically for the client
340
- await Api . Instance . SetProvider ( myClientWithBoundProvider . GetMetadata ( ) . Name , clientProvider ) ;
366
+ await Api . Instance . SetProviderAsync ( myClientWithBoundProvider . GetMetadata ( ) . Name , clientProvider ) ;
341
367
342
368
myClientWithNoBoundProvider . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
343
369
myClientWithBoundProvider . AddHandler ( ProviderEventTypes . ProviderReady , clientEventHandler ) ;
@@ -367,7 +393,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Receive_Events_From_Name
367
393
var clientProvider = new TestProvider ( fixture . Create < string > ( ) ) ;
368
394
369
395
// set the default provider
370
- await Api . Instance . SetProvider ( defaultProvider ) ;
396
+ await Api . Instance . SetProviderAsync ( defaultProvider ) ;
371
397
372
398
client . AddHandler ( ProviderEventTypes . ProviderConfigurationChanged , clientEventHandler ) ;
373
399
@@ -379,7 +405,7 @@ await Utils.AssertUntilAsync(
379
405
) ;
380
406
381
407
// set the other provider specifically for the client
382
- await Api . Instance . SetProvider ( client . GetMetadata ( ) . Name , clientProvider ) ;
408
+ await Api . Instance . SetProviderAsync ( client . GetMetadata ( ) . Name , clientProvider ) ;
383
409
384
410
// now, send another event for the default handler
385
411
defaultProvider . SendEvent ( ProviderEventTypes . ProviderConfigurationChanged ) ;
@@ -410,7 +436,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Informed_About_Ready_Sta
410
436
var myClient = Api . Instance . GetClient ( fixture . Create < string > ( ) ) ;
411
437
412
438
var testProvider = new TestProvider ( ) ;
413
- await Api . Instance . SetProvider ( myClient . GetMetadata ( ) . Name , testProvider ) ;
439
+ await Api . Instance . SetProviderAsync ( myClient . GetMetadata ( ) . Name , testProvider ) ;
414
440
415
441
// add the event handler after the provider has already transitioned into the ready state
416
442
myClient . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
@@ -435,7 +461,7 @@ public async Task Client_Level_Event_Handlers_Should_Be_Removable()
435
461
myClient . AddHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ;
436
462
437
463
var testProvider = new TestProvider ( ) ;
438
- await Api . Instance . SetProvider ( myClient . GetMetadata ( ) . Name , testProvider ) ;
464
+ await Api . Instance . SetProviderAsync ( myClient . GetMetadata ( ) . Name , testProvider ) ;
439
465
440
466
// wait for the first event to be received
441
467
await Utils . AssertUntilAsync ( _ => myClient . RemoveHandler ( ProviderEventTypes . ProviderReady , eventHandler ) ) ;
0 commit comments