@@ -943,6 +943,34 @@ public void TestSetForcedVariation()
943943 Assert . IsTrue ( TestData . CompareObjects ( VariationWithKeyVariation , actualForcedVariation ) ) ;
944944 }
945945
946+ [ Test ]
947+ public void TestSetForcedVariationWithNullAndEmptyUserId ( )
948+ {
949+ Assert . False ( Optimizely . SetForcedVariation ( "test_experiment" , null , "variation" ) ) ;
950+ Assert . True ( Optimizely . SetForcedVariation ( "test_experiment" , "" , "variation" ) ) ;
951+ }
952+
953+ [ Test ]
954+ public void TestSetForcedVariationWithInvalidExperimentKey ( )
955+ {
956+ var userId = "test_user" ;
957+ var variation = "variation" ;
958+
959+ Assert . False ( Optimizely . SetForcedVariation ( "test_experiment_not_in_datafile" , userId , variation ) ) ;
960+ Assert . False ( Optimizely . SetForcedVariation ( "" , userId , variation ) ) ;
961+ Assert . False ( Optimizely . SetForcedVariation ( null , userId , variation ) ) ;
962+ }
963+
964+ [ Test ]
965+ public void TestSetForcedVariationWithInvalidVariationKey ( )
966+ {
967+ var userId = "test_user" ;
968+ var experimentKey = "test_experiment" ;
969+
970+ Assert . False ( Optimizely . SetForcedVariation ( experimentKey , userId , "variation_not_in_datafile" ) ) ;
971+ Assert . False ( Optimizely . SetForcedVariation ( experimentKey , userId , "" ) ) ;
972+ }
973+
946974 // check that the get forced variation is correct.
947975 [ Test ]
948976 public void TestGetForcedVariation ( )
@@ -986,6 +1014,28 @@ public void TestGetForcedVariation()
9861014 Assert . IsTrue ( TestData . CompareObjects ( expectedForcedVariation , actualForcedVariation ) ) ;
9871015 }
9881016
1017+ [ Test ]
1018+ public void TestGetForcedVariationWithInvalidUserID ( )
1019+ {
1020+ var experimentKey = "test_experiment" ;
1021+ Optimizely . SetForcedVariation ( experimentKey , "test_user" , "test_variation" ) ;
1022+
1023+ Assert . Null ( Optimizely . GetForcedVariation ( experimentKey , null ) ) ;
1024+ Assert . Null ( Optimizely . GetForcedVariation ( experimentKey , "invalid_user" ) ) ;
1025+ }
1026+
1027+ [ Test ]
1028+ public void TestGetForcedVariationWithInvalidExperimentKey ( )
1029+ {
1030+ var userId = "test_user" ;
1031+ var experimentKey = "test_experiment" ;
1032+ Optimizely . SetForcedVariation ( experimentKey , userId , "test_variation" ) ;
1033+
1034+ Assert . Null ( Optimizely . GetForcedVariation ( "test_experiment" , userId ) ) ;
1035+ Assert . Null ( Optimizely . GetForcedVariation ( "" , userId ) ) ;
1036+ Assert . Null ( Optimizely . GetForcedVariation ( null , userId ) ) ;
1037+ }
1038+
9891039 [ Test ]
9901040 public void TestGetVariationAudienceMatchAfterSetForcedVariation ( )
9911041 {
@@ -1325,9 +1375,9 @@ public void TestGetFeatureVariableValueForTypeGivenNullOrEmptyArguments()
13251375 Assert . IsNull ( Optimizely . GetFeatureVariableValueForType ( featureKey , variableKey , null , null , variableType ) ) ;
13261376 Assert . IsNull ( Optimizely . GetFeatureVariableValueForType ( featureKey , variableKey , "" , null , variableType ) ) ;
13271377
1328- LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Feature flag key must not be empty ." ) , Times . Exactly ( 2 ) ) ;
1329- LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Variable key must not be empty ." ) , Times . Exactly ( 2 ) ) ;
1330- LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "User ID must not be empty ." ) , Times . Exactly ( 2 ) ) ;
1378+ LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Provided Feature Key is in invalid format ." ) , Times . Exactly ( 2 ) ) ;
1379+ LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Provided Variable Key is in invalid format ." ) , Times . Exactly ( 2 ) ) ;
1380+ LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Provided User Id is in invalid format ." ) , Times . Exactly ( 1 ) ) ;
13311381 }
13321382
13331383 // Should return null and log error message when feature key or variable key does not get found.
@@ -1487,8 +1537,8 @@ public void TestIsFeatureEnabledGivenNullOrEmptyArguments()
14871537 Assert . IsFalse ( Optimizely . IsFeatureEnabled ( null , TestUserId , null ) ) ;
14881538 Assert . IsFalse ( Optimizely . IsFeatureEnabled ( "" , TestUserId , null ) ) ;
14891539
1490- LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "User ID must not be empty ." ) , Times . Exactly ( 2 ) ) ;
1491- LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Feature flag key must not be empty ." ) , Times . Exactly ( 2 ) ) ;
1540+ LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Provided Feature Key is in invalid format ." ) , Times . Exactly ( 2 ) ) ;
1541+ LoggerMock . Verify ( l => l . Log ( LogLevel . ERROR , "Provided User Id is in invalid format ." ) , Times . Exactly ( 1 ) ) ;
14921542 }
14931543
14941544 // Should return false and log error message when feature flag key is not found in the datafile.
@@ -1941,5 +1991,48 @@ public void TestTrackValidateInputValues()
19411991 }
19421992
19431993 #endregion // Test ValidateStringInputs
1994+
1995+ #region TestValidateStringInputs
1996+
1997+ [ Test ]
1998+ public void TestValidateStringInputsWithValidValues ( )
1999+ {
2000+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2001+
2002+ bool result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . EXPERIMENT_KEY , "test_experiment" } } ) ;
2003+ Assert . True ( result ) ;
2004+
2005+ result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . EVENT_KEY , "buy_now_event" } } ) ;
2006+ Assert . True ( result ) ;
2007+ }
2008+
2009+ [ Test ]
2010+ public void TestValidateStringInputsWithInvalidValues ( )
2011+ {
2012+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2013+
2014+ bool result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . EXPERIMENT_KEY , "" } } ) ;
2015+ Assert . False ( result ) ;
2016+
2017+ result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . EVENT_KEY , null } } ) ;
2018+ Assert . False ( result ) ;
2019+ }
2020+
2021+ [ Test ]
2022+ public void TestValidateStringInputsWithUserId ( )
2023+ {
2024+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2025+
2026+ bool result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . USER_ID , "testUser" } } ) ;
2027+ Assert . True ( result ) ;
2028+
2029+ result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . USER_ID , "" } } ) ;
2030+ Assert . True ( result ) ;
2031+
2032+ result = ( bool ) optly . Invoke ( "ValidateStringInputs" , new Dictionary < string , string > { { Optimizely . USER_ID , null } } ) ;
2033+ Assert . False ( result ) ;
2034+ }
2035+
2036+ #endregion //TestValidateStringInputs
19442037 }
19452038}
0 commit comments