@@ -270,5 +270,117 @@ public async Task TestCustomEndpointBad()
270
270
KinveyException ke = e as KinveyException ;
271
271
Assert . AreEqual ( 404 , ke . StatusCode ) ;
272
272
}
273
- }
273
+
274
+ [ TestMethod ]
275
+ public async Task TestSetApiVersionAuthRequests ( )
276
+ {
277
+ // Arrange
278
+ var notSupportingApiVersion = int . MaxValue . ToString ( ) ;
279
+
280
+ var builder = new Client . Builder ( AppKey , AppSecret ) ;
281
+ builder . SetFilePath ( TestSetup . db_dir ) ;
282
+
283
+ if ( MockData )
284
+ {
285
+ builder . setBaseURL ( "http://localhost:8080" ) ;
286
+ builder . setMICHostName ( "http://localhost:8081" ) ;
287
+ }
288
+
289
+ var client1 = builder . Build ( ) ;
290
+
291
+ builder . SetApiVersion ( notSupportingApiVersion ) ;
292
+ var client2 = builder . Build ( ) ;
293
+
294
+ builder . SetApiVersion ( KinveyHeaders . kinveyApiVersion ) ;
295
+ var client3 = builder . Build ( ) ;
296
+
297
+ if ( MockData )
298
+ {
299
+ MockResponses ( 3 ) ;
300
+ }
301
+
302
+ // Act
303
+ var userForClient1 = await User . LoginAsync ( client1 ) ;
304
+
305
+ var exception = await Assert . ThrowsExceptionAsync < KinveyException > ( async delegate
306
+ {
307
+ await User . LoginAsync ( client2 ) ;
308
+ } ) ;
309
+
310
+ var userForClient3 = await User . LoginAsync ( client3 ) ;
311
+
312
+ // Assert
313
+ Assert . AreEqual ( typeof ( KinveyException ) , exception . GetType ( ) ) ;
314
+ var kinveyException = exception as KinveyException ;
315
+ Assert . IsTrue ( kinveyException . ErrorCategory == EnumErrorCategory . ERROR_BACKEND ) ;
316
+ Assert . IsTrue ( kinveyException . ErrorCode == EnumErrorCode . ERROR_JSON_RESPONSE ) ;
317
+
318
+ Assert . IsNotNull ( client1 . ActiveUser ) ;
319
+ Assert . IsTrue ( userForClient1 . Active ) ;
320
+
321
+ Assert . IsNotNull ( client3 . ActiveUser ) ;
322
+ Assert . IsTrue ( userForClient3 . Active ) ;
323
+
324
+ Assert . AreEqual ( KinveyHeaders . kinveyApiVersion , client1 . ApiVersion ) ;
325
+ Assert . AreEqual ( notSupportingApiVersion , client2 . ApiVersion ) ;
326
+ Assert . AreEqual ( KinveyHeaders . kinveyApiVersion , client3 . ApiVersion ) ;
327
+ }
328
+
329
+ [ TestMethod ]
330
+ public async Task TestSetApiVersionKinveyClientRequests ( )
331
+ {
332
+ // Arrange
333
+ var notSupportingApiVersion = int . MaxValue . ToString ( ) ;
334
+
335
+ var builder = new Client . Builder ( AppKey , AppSecret ) ;
336
+ builder . SetFilePath ( TestSetup . db_dir ) ;
337
+
338
+ if ( MockData )
339
+ {
340
+ builder . setBaseURL ( "http://localhost:8080" ) ;
341
+ builder . setMICHostName ( "http://localhost:8081" ) ;
342
+ }
343
+
344
+ var client1 = builder . Build ( ) ;
345
+
346
+ builder . SetApiVersion ( notSupportingApiVersion ) ;
347
+ var client2 = builder . Build ( ) ;
348
+
349
+ builder . SetApiVersion ( KinveyHeaders . kinveyApiVersion ) ;
350
+ var client3 = builder . Build ( ) ;
351
+
352
+ if ( MockData )
353
+ {
354
+ MockResponses ( 3 ) ;
355
+ }
356
+
357
+ // Act
358
+ var pingResponse1 = await client1 . PingAsync ( ) ;
359
+
360
+ var exception = await Assert . ThrowsExceptionAsync < KinveyException > ( async delegate
361
+ {
362
+ await client2 . PingAsync ( ) ;
363
+ } ) ;
364
+
365
+ var pingResponse3 = await client3 . PingAsync ( ) ;
366
+
367
+ // Assert
368
+ Assert . AreEqual ( typeof ( KinveyException ) , exception . GetType ( ) ) ;
369
+ var kinveyException = exception as KinveyException ;
370
+ Assert . IsTrue ( kinveyException . ErrorCategory == EnumErrorCategory . ERROR_BACKEND ) ;
371
+ Assert . IsTrue ( kinveyException . ErrorCode == EnumErrorCode . ERROR_JSON_RESPONSE ) ;
372
+
373
+ Assert . IsNotNull ( pingResponse1 . kinvey ) ;
374
+ Assert . IsTrue ( pingResponse1 . kinvey . StartsWith ( "hello" , StringComparison . Ordinal ) ) ;
375
+ Assert . IsNotNull ( pingResponse1 . version ) ;
376
+
377
+ Assert . IsNotNull ( pingResponse3 . kinvey ) ;
378
+ Assert . IsTrue ( pingResponse3 . kinvey . StartsWith ( "hello" , StringComparison . Ordinal ) ) ;
379
+ Assert . IsNotNull ( pingResponse3 . version ) ;
380
+
381
+ Assert . AreEqual ( KinveyHeaders . kinveyApiVersion , client1 . ApiVersion ) ;
382
+ Assert . AreEqual ( notSupportingApiVersion , client2 . ApiVersion ) ;
383
+ Assert . AreEqual ( KinveyHeaders . kinveyApiVersion , client3 . ApiVersion ) ;
384
+ }
385
+ }
274
386
}
0 commit comments