@@ -54,7 +54,7 @@ public void SetUp()
5454 }
5555
5656 [ Test ]
57- public void GetVariationForcedVariationPrecedesAudienceEval ( )
57+ public void TestGetVariationForcedVariationPrecedesAudienceEval ( )
5858 {
5959 var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
6060
@@ -74,7 +74,7 @@ public void GetVariationForcedVariationPrecedesAudienceEval()
7474 }
7575
7676 [ Test ]
77- public void GetVariationEvaluatesUserProfileBeforeAudienceTargeting ( )
77+ public void TestGetVariationEvaluatesUserProfileBeforeAudienceTargeting ( )
7878 {
7979 var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
8080 Experiment experiment = ValidProjectConfig . Experiments [ 0 ] ;
@@ -102,7 +102,7 @@ public void GetVariationEvaluatesUserProfileBeforeAudienceTargeting()
102102 }
103103
104104 [ Test ]
105- public void GetForcedVariationReturnsForcedVariation ( )
105+ public void TestGetForcedVariationReturnsForcedVariation ( )
106106 {
107107 var BucketerMock = new Mock < Bucketer > ( LoggerMock . Object ) ;
108108
@@ -116,7 +116,7 @@ public void GetForcedVariationReturnsForcedVariation()
116116 }
117117
118118 [ Test ]
119- public void GetForcedVariationWithInvalidVariation ( )
119+ public void TestGetForcedVariationWithInvalidVariation ( )
120120 {
121121 string userId = "testUser1" ;
122122 string invalidVariationKey = "invalidVarKey" ;
@@ -159,7 +159,7 @@ public void GetForcedVariationWithInvalidVariation()
159159 }
160160
161161 [ Test ]
162- public void GetForcedVariationReturnsNullWhenUserIsNotWhitelisted ( )
162+ public void TestGetForcedVariationReturnsNullWhenUserIsNotWhitelisted ( )
163163 {
164164 Bucketer bucketer = new Bucketer ( LoggerMock . Object ) ;
165165 DecisionService decisionService = new DecisionService ( bucketer , ErrorHandlerMock . Object , ValidProjectConfig , null , LoggerMock . Object ) ;
@@ -168,7 +168,7 @@ public void GetForcedVariationReturnsNullWhenUserIsNotWhitelisted()
168168 }
169169
170170 [ Test ]
171- public void BucketReturnsVariationStoredInUserProfile ( )
171+ public void TestBucketReturnsVariationStoredInUserProfile ( )
172172 {
173173 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
174174 Variation variation = experiment . Variations [ 0 ] ;
@@ -195,7 +195,7 @@ public void BucketReturnsVariationStoredInUserProfile()
195195 }
196196
197197 [ Test ]
198- public void GetStoredVariationLogsWhenLookupReturnsNull ( )
198+ public void TestGetStoredVariationLogsWhenLookupReturnsNull ( )
199199 {
200200 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
201201
@@ -215,7 +215,7 @@ public void GetStoredVariationLogsWhenLookupReturnsNull()
215215 }
216216
217217 [ Test ]
218- public void GetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig ( )
218+ public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig ( )
219219 {
220220 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
221221 string storedVariationId = "missingVariation" ;
@@ -238,7 +238,7 @@ public void GetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
238238 , UserProfileId , storedVariationId , experiment . Id ) ) , Times . Once ) ;
239239 }
240240 [ Test ]
241- public void GetVariationSavesBucketedVariationIntoUserProfile ( )
241+ public void TestGetVariationSavesBucketedVariationIntoUserProfile ( )
242242 {
243243 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
244244 Variation variation = experiment . Variations [ 0 ] ;
@@ -268,7 +268,7 @@ public void GetVariationSavesBucketedVariationIntoUserProfile()
268268 }
269269 [ Test ]
270270 [ ExpectedException ]
271- public void BucketLogsCorrectlyWhenUserProfileFailsToSave ( )
271+ public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave ( )
272272 {
273273 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
274274 Variation variation = experiment . Variations [ 0 ] ;
@@ -294,7 +294,7 @@ public void BucketLogsCorrectlyWhenUserProfileFailsToSave()
294294 , Times . Once ) ;
295295 }
296296 [ Test ]
297- public void GetVariationSavesANewUserProfile ( )
297+ public void TestGetVariationSavesANewUserProfile ( )
298298 {
299299 Experiment experiment = NoAudienceProjectConfig . Experiments [ 0 ] ;
300300 Variation variation = experiment . Variations [ 0 ] ;
@@ -318,5 +318,47 @@ public void GetVariationSavesANewUserProfile()
318318 Assert . IsTrue ( TestData . CompareObjects ( variation , decisionService . GetVariation ( experiment , UserProfileId , new UserAttributes ( ) ) ) ) ;
319319 UserProfileServiceMock . Verify ( _ => _ . Save ( It . IsAny < Dictionary < string , object > > ( ) ) , Times . Once ) ;
320320 }
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+ }
321363 }
322364}
0 commit comments