@@ -54,7 +54,7 @@ public void SetUp()
54
54
}
55
55
56
56
[ Test ]
57
- public void GetVariationForcedVariationPrecedesAudienceEval ( )
57
+ public void TestGetVariationForcedVariationPrecedesAudienceEval ( )
58
58
{
59
59
var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
60
60
@@ -74,7 +74,7 @@ public void GetVariationForcedVariationPrecedesAudienceEval()
74
74
}
75
75
76
76
[ Test ]
77
- public void GetVariationEvaluatesUserProfileBeforeAudienceTargeting ( )
77
+ public void TestGetVariationEvaluatesUserProfileBeforeAudienceTargeting ( )
78
78
{
79
79
var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
80
80
Experiment experiment = ValidProjectConfig . Experiments [ 0 ] ;
@@ -102,7 +102,7 @@ public void GetVariationEvaluatesUserProfileBeforeAudienceTargeting()
102
102
}
103
103
104
104
[ Test ]
105
- public void GetForcedVariationReturnsForcedVariation ( )
105
+ public void TestGetForcedVariationReturnsForcedVariation ( )
106
106
{
107
107
var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
108
108
@@ -116,7 +116,7 @@ public void GetForcedVariationReturnsForcedVariation()
116
116
}
117
117
118
118
[ Test ]
119
- public void GetForcedVariationWithInvalidVariation ( )
119
+ public void TestGetForcedVariationWithInvalidVariation ( )
120
120
{
121
121
string userId = "testUser1" ;
122
122
string invalidVariationKey = "invalidVarKey" ;
@@ -159,7 +159,7 @@ public void GetForcedVariationWithInvalidVariation()
159
159
}
160
160
161
161
[ Test ]
162
- public void GetForcedVariationReturnsNullWhenUserIsNotWhitelisted ( )
162
+ public void TestGetForcedVariationReturnsNullWhenUserIsNotWhitelisted ( )
163
163
{
164
164
Bucketer bucketer = new Bucketer ( LoggerMock . Object ) ;
165
165
DecisionService decisionService = new DecisionService ( bucketer , ErrorHandlerMock . Object , ValidProjectConfig , null , LoggerMock . Object ) ;
@@ -168,7 +168,7 @@ public void GetForcedVariationReturnsNullWhenUserIsNotWhitelisted()
168
168
}
169
169
170
170
[ Test ]
171
- public void BucketReturnsVariationStoredInUserProfile ( )
171
+ public void TestBucketReturnsVariationStoredInUserProfile ( )
172
172
{
173
173
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
174
174
Variation variation = experiment . Variations [ 0 ] ;
@@ -195,7 +195,7 @@ public void BucketReturnsVariationStoredInUserProfile()
195
195
}
196
196
197
197
[ Test ]
198
- public void GetStoredVariationLogsWhenLookupReturnsNull ( )
198
+ public void TestGetStoredVariationLogsWhenLookupReturnsNull ( )
199
199
{
200
200
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
201
201
@@ -215,7 +215,7 @@ public void GetStoredVariationLogsWhenLookupReturnsNull()
215
215
}
216
216
217
217
[ Test ]
218
- public void GetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig ( )
218
+ public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig ( )
219
219
{
220
220
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
221
221
string storedVariationId = "missingVariation" ;
@@ -238,7 +238,7 @@ public void GetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
238
238
, UserProfileId , storedVariationId , experiment . Id ) ) , Times . Once ) ;
239
239
}
240
240
[ Test ]
241
- public void GetVariationSavesBucketedVariationIntoUserProfile ( )
241
+ public void TestGetVariationSavesBucketedVariationIntoUserProfile ( )
242
242
{
243
243
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
244
244
Variation variation = experiment . Variations [ 0 ] ;
@@ -268,7 +268,7 @@ public void GetVariationSavesBucketedVariationIntoUserProfile()
268
268
}
269
269
[ Test ]
270
270
[ ExpectedException ]
271
- public void BucketLogsCorrectlyWhenUserProfileFailsToSave ( )
271
+ public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave ( )
272
272
{
273
273
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
274
274
Variation variation = experiment . Variations [ 0 ] ;
@@ -294,7 +294,7 @@ public void BucketLogsCorrectlyWhenUserProfileFailsToSave()
294
294
, Times . Once ) ;
295
295
}
296
296
[ Test ]
297
- public void GetVariationSavesANewUserProfile ( )
297
+ public void TestGetVariationSavesANewUserProfile ( )
298
298
{
299
299
Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
300
300
Variation variation = experiment . Variations [ 0 ] ;
@@ -318,5 +318,47 @@ public void GetVariationSavesANewUserProfile()
318
318
Assert . IsTrue ( TestData . CompareObjects ( variation , decisionService . GetVariation ( experiment , UserProfileId , new UserAttributes ( ) ) ) ) ;
319
319
UserProfileServiceMock . Verify ( _ => _ . Save ( It . IsAny < Dictionary < string , object > > ( ) ) , Times . Once ) ;
320
320
}
321
+
322
+ [ Test ]
323
+ public void TestGetVariationUserWithSetForcedVariation ( )
324
+ {
325
+ var experimentKey = "test_experiment" ;
326
+ var pausedExperimentKey = "paused_experiment" ;
327
+ var userId = "test_user" ;
328
+ var expectedForcedVariationKey = "variation" ;
329
+ var expectedVariationKey = "control" ;
330
+ var optlyObject = new Optimizely ( TestData . Datafile , new ValidEventDispatcher ( ) , LoggerMock . Object ) ;
331
+
332
+ var userAttributes = new UserAttributes
333
+ {
334
+ { "device_type" , "iPhone" } ,
335
+ { "location" , "San Francisco" }
336
+ } ;
337
+
338
+ optlyObject . Activate ( experimentKey , userId , userAttributes ) ;
339
+
340
+ // confirm normal bucketing occurs before setting the forced variation
341
+ var actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
342
+
343
+ Assert . AreEqual ( expectedVariationKey , actualVariationKey ) ;
344
+
345
+ // test valid experiment
346
+ Assert . IsTrue ( optlyObject . SetForcedVariation ( experimentKey , userId , expectedForcedVariationKey ) , string . Format ( @"Set variation to ""{0}"" failed." , expectedForcedVariationKey ) ) ;
347
+
348
+ var actualForcedVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
349
+ Assert . AreEqual ( expectedForcedVariationKey , actualForcedVariationKey ) ;
350
+
351
+ // clear forced variation and confirm that normal bucketing occurs
352
+ Assert . IsTrue ( optlyObject . SetForcedVariation ( experimentKey , userId , null ) ) ;
353
+
354
+ actualVariationKey = optlyObject . GetVariation ( experimentKey , userId , userAttributes ) ;
355
+ Assert . AreEqual ( expectedVariationKey , actualVariationKey ) ;
356
+
357
+ // check that a paused experiment returns null
358
+ Assert . IsTrue ( optlyObject . SetForcedVariation ( pausedExperimentKey , userId , expectedForcedVariationKey ) , string . Format ( @"Set variation to ""{0}"" failed." , expectedForcedVariationKey ) ) ;
359
+ actualForcedVariationKey = optlyObject . GetVariation ( pausedExperimentKey , userId , userAttributes ) ;
360
+
361
+ Assert . IsNull ( actualForcedVariationKey ) ;
362
+ }
321
363
}
322
364
}
0 commit comments