@@ -43,6 +43,9 @@ public class DecisionServiceTest
43
43
private Variation WhitelistedVariation ;
44
44
private DecisionService DecisionService ;
45
45
46
+ private Variation VariationWithKeyControl ;
47
+ private Variation VariationWithKeyVariation ;
48
+
46
49
[ SetUp ]
47
50
public void SetUp ( )
48
51
{
@@ -59,6 +62,9 @@ public void SetUp()
59
62
DecisionService = new DecisionService ( new Bucketer ( LoggerMock . Object ) , ErrorHandlerMock . Object , ProjectConfig , null , LoggerMock . Object ) ;
60
63
61
64
DecisionServiceMock = new Mock < DecisionService > ( BucketerMock . Object , ErrorHandlerMock . Object , ProjectConfig , null , LoggerMock . Object ) { CallBase = true } ;
65
+
66
+ VariationWithKeyControl = ProjectConfig . GetVariationFromKey ( "test_experiment" , "control" ) ;
67
+ VariationWithKeyVariation = ProjectConfig . GetVariationFromKey ( "test_experiment" , "variation" ) ;
62
68
}
63
69
64
70
[ Test ]
@@ -349,27 +355,26 @@ public void TestGetVariationUserWithSetForcedVariation()
349
355
optlyObject . Activate ( experimentKey , userId , userAttributes ) ;
350
356
351
357
// confirm normal bucketing occurs before setting the forced variation
352
- var actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
353
-
354
- Assert . AreEqual ( expectedVariationKey , actualVariationKey ) ;
358
+ var actualVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
359
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) ) ;
355
360
356
361
// test valid experiment
357
362
Assert . IsTrue ( optlyObject . SetForcedVariation ( experimentKey , userId , expectedForcedVariationKey ) , string . Format ( @"Set variation to ""{0}"" failed." , expectedForcedVariationKey ) ) ;
358
363
359
- var actualForcedVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
360
- Assert . AreEqual ( expectedForcedVariationKey , actualForcedVariationKey ) ;
364
+ var actualForcedVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
365
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyVariation , actualForcedVariation ) ) ;
361
366
362
367
// clear forced variation and confirm that normal bucketing occurs
363
368
Assert . IsTrue ( optlyObject . SetForcedVariation ( experimentKey , userId , null ) ) ;
364
369
365
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
366
- Assert . AreEqual ( expectedVariationKey , actualVariationKey ) ;
370
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
371
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) ) ;
367
372
368
373
// check that a paused experiment returns null
369
374
Assert . IsTrue ( optlyObject . SetForcedVariation ( pausedExperimentKey , userId , expectedForcedVariationKey ) , string . Format ( @"Set variation to ""{0}"" failed." , expectedForcedVariationKey ) ) ;
370
- actualForcedVariationKey = optlyObject . GetVariation ( pausedExperimentKey , userId , userAttributes ) ;
375
+ actualForcedVariation = optlyObject . GetVariation ( pausedExperimentKey , userId , userAttributes ) ;
371
376
372
- Assert . IsNull ( actualForcedVariationKey ) ;
377
+ Assert . IsNull ( actualForcedVariation ) ;
373
378
}
374
379
375
380
[ Test ]
@@ -408,33 +413,33 @@ public void TestGetVariationWithBucketingId()
408
413
var optlyObject = new Optimizely ( TestData . Datafile , new ValidEventDispatcher ( ) , LoggerMock . Object ) ;
409
414
410
415
// confirm normal bucketing occurs before setting the bucketing ID
411
- var actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , testUserAttributes ) ;
412
- Assert . AreEqual ( variationKeyControl , actualVariationKey ) ;
416
+ var actualVariation = optlyObject . GetVariation ( experimentKey , userId , testUserAttributes ) ;
417
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) ) ;
413
418
414
419
// confirm valid bucketing with bucketing ID set in attributes
415
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
416
- Assert . AreEqual ( variationKeyVariation , actualVariationKey ) ;
420
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
421
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyVariation , actualVariation ) ) ;
417
422
418
423
// check invalid audience with bucketing ID
419
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , invalidUserAttributesWithBucketingId ) ;
420
- Assert . AreEqual ( null , actualVariationKey ) ;
424
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , invalidUserAttributesWithBucketingId ) ;
425
+ Assert . Null ( actualVariation ) ;
421
426
422
427
// check null audience with bucketing Id
423
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , null ) ;
424
- Assert . AreEqual ( null , actualVariationKey ) ;
428
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , null ) ;
429
+ Assert . Null ( actualVariation ) ;
425
430
426
431
// test that an experiment that's not running returns a null variation
427
- actualVariationKey = optlyObject . GetVariation ( pausedExperimentKey , userId , userAttributesWithBucketingId ) ;
428
- Assert . AreEqual ( null , actualVariationKey ) ;
432
+ actualVariation = optlyObject . GetVariation ( pausedExperimentKey , userId , userAttributesWithBucketingId ) ;
433
+ Assert . Null ( actualVariation ) ;
429
434
430
435
// check forced variation
431
436
Assert . IsTrue ( optlyObject . SetForcedVariation ( experimentKey , userId , variationKeyControl ) , string . Format ( "Set variation to \" {0}\" failed." , variationKeyControl ) ) ;
432
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
433
- Assert . AreEqual ( variationKeyControl , actualVariationKey ) ;
437
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
438
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) ) ;
434
439
435
440
// check whitelisted variation
436
- actualVariationKey = optlyObject . GetVariation ( experimentKey , testUserIdWhitelisted , userAttributesWithBucketingId ) ;
437
- Assert . AreEqual ( variationKeyControl , actualVariationKey ) ;
441
+ actualVariation = optlyObject . GetVariation ( experimentKey , testUserIdWhitelisted , userAttributesWithBucketingId ) ;
442
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) ) ;
438
443
439
444
var bucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
440
445
var decision = new Decision ( "7722370027" ) ;
@@ -446,8 +451,8 @@ public void TestGetVariationWithBucketingId()
446
451
UserProfileServiceMock . Setup ( up => up . Lookup ( userId ) ) . Returns ( storedUserProfile . ToMap ( ) ) ;
447
452
DecisionService decisionService = new DecisionService ( bucketerMock . Object , ErrorHandlerMock . Object , ValidProjectConfig , UserProfileServiceMock . Object , LoggerMock . Object ) ;
448
453
449
- actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
450
- Assert . AreEqual ( variationKeyControl , actualVariationKey , string . Format ( "Variation \" {0}\" does not match expected user profile variation \" {1}\" ." , actualVariationKey , variationKeyControl ) ) ;
454
+ actualVariation = optlyObject . GetVariation ( experimentKey , userId , userAttributesWithBucketingId ) ;
455
+ Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyControl , actualVariation ) , string . Format ( "Variation \" {0}\" does not match expected user profile variation \" {1}\" ." , actualVariation ? . Key , variationKeyControl ) ) ;
451
456
}
452
457
453
458
#region GetVariationForFeatureExperiment Tests
0 commit comments