@@ -943,6 +943,34 @@ public void TestSetForcedVariation()
943
943
Assert.IsTrue(TestData.CompareObjects(VariationWithKeyVariation, actualForcedVariation));
944
944
}
945
945
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
+
946
974
// check that the get forced variation is correct.
947
975
[Test]
948
976
public void TestGetForcedVariation()
@@ -986,6 +1014,28 @@ public void TestGetForcedVariation()
986
1014
Assert.IsTrue(TestData.CompareObjects(expectedForcedVariation, actualForcedVariation));
987
1015
}
988
1016
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
+
989
1039
[Test]
990
1040
public void TestGetVariationAudienceMatchAfterSetForcedVariation()
991
1041
{
@@ -1325,9 +1375,9 @@ public void TestGetFeatureVariableValueForTypeGivenNullOrEmptyArguments()
1325
1375
Assert.IsNull(Optimizely.GetFeatureVariableValueForType(featureKey, variableKey, null, null, variableType));
1326
1376
Assert.IsNull(Optimizely.GetFeatureVariableValueForType(featureKey, variableKey, "", null, variableType));
1327
1377
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 ));
1331
1381
}
1332
1382
1333
1383
// Should return null and log error message when feature key or variable key does not get found.
@@ -1487,8 +1537,8 @@ public void TestIsFeatureEnabledGivenNullOrEmptyArguments()
1487
1537
Assert.IsFalse(Optimizely.IsFeatureEnabled(null, TestUserId, null));
1488
1538
Assert.IsFalse(Optimizely.IsFeatureEnabled("", TestUserId, null));
1489
1539
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 ));
1492
1542
}
1493
1543
1494
1544
// Should return false and log error message when feature flag key is not found in the datafile.
@@ -1941,5 +1991,48 @@ public void TestTrackValidateInputValues()
1941
1991
}
1942
1992
1943
1993
#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
1944
2037
}
1945
2038
}
0 commit comments