33
33
using Xunit . Abstractions ;
34
34
using System . Collections . Generic ;
35
35
using System . Net . Http . Headers ;
36
+ using Newtonsoft . Json ;
36
37
37
38
namespace Microsoft . Azure . Commands . AnalysisServices . Test . InMemoryTests
38
39
{
@@ -368,25 +369,50 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
368
369
// Set up AsAzureHttpClient mock
369
370
var mockAsAzureHttpClient = new Mock < IAsAzureHttpClient > ( ) ;
370
371
372
+ // set up cluster resolve respnose
373
+ ClusterResolutionResult resolveResult = new ClusterResolutionResult ( )
374
+ {
375
+ ClusterFQDN = "resolved.westcentralus.asazure.windows.net" ,
376
+ CoreServerName = testServer + ":rw" ,
377
+ TenantId = Guid . NewGuid ( ) . ToString ( )
378
+ } ;
379
+ mockAsAzureHttpClient
380
+ . Setup ( obj => obj . CallPostAsync (
381
+ It . IsAny < Uri > ( ) ,
382
+ It . Is < string > ( s => s . Contains ( "clusterResolve" ) ) ,
383
+ It . IsAny < string > ( ) ,
384
+ It . IsAny < HttpContent > ( ) ) )
385
+ . Returns ( Task < HttpResponseMessage > . FromResult (
386
+ new HttpResponseMessage ( HttpStatusCode . OK )
387
+ {
388
+ Content = new StringContent ( JsonConvert . SerializeObject ( resolveResult ) )
389
+ } ) ) ;
390
+
391
+ // set up sync respnose
371
392
var postResponse = new HttpResponseMessage ( HttpStatusCode . Accepted ) ;
372
393
postResponse . Headers . Location = new Uri ( "https://1" ) ;
373
394
postResponse . Headers . RetryAfter = new RetryConditionHeaderValue ( TimeSpan . FromMilliseconds ( 500 ) ) ;
395
+ postResponse . Headers . Add ( "x-ms-root-activity-id" , Guid . NewGuid ( ) . ToString ( ) ) ;
396
+ postResponse . Headers . Add ( "x-ms-current-utc-date" , Guid . NewGuid ( ) . ToString ( ) ) ;
374
397
mockAsAzureHttpClient
375
398
. Setup ( obj => obj . CallPostAsync (
376
399
It . IsAny < Uri > ( ) ,
377
- It . IsAny < string > ( ) ,
378
- It . IsAny < string > ( ) ,
379
- It . IsAny < HttpContent > ( ) ) )
400
+ It . Is < string > ( s => s . Contains ( "sync" ) ) ,
401
+ It . IsAny < string > ( ) ,
402
+ It . IsAny < Guid > ( ) ,
403
+ null ) )
380
404
. Returns ( Task < Mock < HttpResponseMessage > > . FromResult ( postResponse ) ) ;
381
405
406
+
382
407
var getResponse1 = new HttpResponseMessage ( HttpStatusCode . SeeOther ) ;
383
408
getResponse1 . Headers . Location = new Uri ( "https://done" ) ;
384
409
getResponse1 . Headers . RetryAfter = new RetryConditionHeaderValue ( TimeSpan . FromMilliseconds ( 500 ) ) ;
385
410
mockAsAzureHttpClient
386
411
. Setup ( obj => obj . CallGetAsync (
387
412
It . Is < Uri > ( u => u . OriginalString . Contains ( "1" ) ) ,
413
+ string . Empty ,
388
414
It . IsAny < string > ( ) ,
389
- It . IsAny < string > ( ) ) )
415
+ It . IsAny < Guid > ( ) ) )
390
416
. Returns ( Task < HttpResponseMessage > . FromResult ( getResponse1 ) ) ;
391
417
392
418
var getResponseSucceed = new HttpResponseMessage
@@ -402,8 +428,9 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
402
428
mockAsAzureHttpClient
403
429
. Setup ( obj => obj . CallGetAsync (
404
430
It . Is < Uri > ( u => u . OriginalString . Contains ( "done" ) ) ,
431
+ string . Empty ,
405
432
It . IsAny < string > ( ) ,
406
- It . IsAny < string > ( ) ) )
433
+ It . IsAny < Guid > ( ) ) )
407
434
. Returns ( ( ) => Task . FromResult ( finalResponses . Dequeue ( ) ) ) ;
408
435
409
436
var mockTokenCacheItemProvider = new Mock < ITokenCacheItemProvider > ( ) ;
@@ -421,7 +448,7 @@ public void SynchronizeAzureASInstance_SingleDB_Succeeds()
421
448
} ;
422
449
423
450
DoLogin ( addAmdlet ) ;
424
- syncCmdlet . Instance = testServer ;
451
+ syncCmdlet . Instance = testServer + ":rw" ;
425
452
syncCmdlet . Database = "db0" ;
426
453
427
454
// Act
@@ -454,6 +481,26 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
454
481
// Set up AsAzureHttpClient mock
455
482
var mockAsAzureHttpClient = new Mock < IAsAzureHttpClient > ( ) ;
456
483
484
+ // set up cluster resolve respnose
485
+ ClusterResolutionResult resolveResult = new ClusterResolutionResult ( )
486
+ {
487
+ ClusterFQDN = "resolved.westcentralus.asazure.windows.net" ,
488
+ CoreServerName = testServer + ":rw" ,
489
+ TenantId = Guid . NewGuid ( ) . ToString ( )
490
+ } ;
491
+ mockAsAzureHttpClient
492
+ . Setup ( obj => obj . CallPostAsync (
493
+ It . IsAny < Uri > ( ) ,
494
+ It . Is < string > ( s => s . Contains ( "clusterResolve" ) ) ,
495
+ It . IsAny < string > ( ) ,
496
+ It . IsAny < HttpContent > ( ) ) )
497
+ . Returns ( Task < HttpResponseMessage > . FromResult (
498
+ new HttpResponseMessage ( HttpStatusCode . OK )
499
+ {
500
+ Content = new StringContent ( JsonConvert . SerializeObject ( resolveResult ) )
501
+ } ) ) ;
502
+
503
+ // set up sync respnose
457
504
var postResponse = new HttpResponseMessage ( HttpStatusCode . Accepted ) ;
458
505
postResponse . Headers . Location = new Uri ( "https://1" ) ;
459
506
postResponse . Headers . RetryAfter = new RetryConditionHeaderValue ( TimeSpan . FromMilliseconds ( 500 ) ) ;
@@ -462,10 +509,10 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
462
509
mockAsAzureHttpClient
463
510
. Setup ( obj => obj . CallPostAsync (
464
511
It . IsAny < Uri > ( ) ,
465
- It . IsAny < string > ( ) ,
512
+ It . Is < string > ( s => s . Contains ( "sync" ) ) ,
466
513
It . IsAny < string > ( ) ,
467
514
It . IsAny < Guid > ( ) ,
468
- It . IsAny < HttpContent > ( ) ) )
515
+ null ) )
469
516
. Returns ( Task < Mock < HttpResponseMessage > > . FromResult ( postResponse ) ) ;
470
517
471
518
var getResponse1 = new HttpResponseMessage ( HttpStatusCode . SeeOther ) ;
@@ -518,15 +565,15 @@ public void SynchronizeAzureASInstance_FailsAfterTooManyRetries()
518
565
} ;
519
566
520
567
DoLogin ( addAmdlet ) ;
521
- syncCmdlet . Instance = testServer ;
568
+ syncCmdlet . Instance = testServer + ":rw" ;
522
569
syncCmdlet . Database = "db0" ;
523
570
524
571
// Act
525
572
syncCmdlet . InvokeBeginProcessing ( ) ;
526
573
Assert . Throws < SynchronizationFailedException > ( ( ) => syncCmdlet . ExecuteCmdlet ( ) ) ;
527
574
syncCmdlet . InvokeEndProcessing ( ) ;
528
575
}
529
-
576
+
530
577
private void DoLogin ( AddAzureASAccountCommand addCmdlet )
531
578
{
532
579
Mock < ICommandRuntime > commandRuntimeMock = new Mock < ICommandRuntime > ( ) ;
0 commit comments