Skip to content

Commit 97ac579

Browse files
isfeatureenabled should return boolean value. (#39)
1 parent ecbf657 commit 97ac579

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

OptimizelySDK.Tests/OptimizelyTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,11 +1391,11 @@ public void TestIsFeatureEnabledGivenNullOrEmptyArguments()
13911391
{
13921392
var featureKey = "featureKey";
13931393

1394-
Assert.Null(Optimizely.IsFeatureEnabled(featureKey, null, null));
1395-
Assert.Null(Optimizely.IsFeatureEnabled(featureKey, "", null));
1396-
1397-
Assert.Null(Optimizely.IsFeatureEnabled(null, TestUserId, null));
1398-
Assert.Null(Optimizely.IsFeatureEnabled("", TestUserId, null));
1394+
Assert.IsFalse(Optimizely.IsFeatureEnabled(featureKey, null, null));
1395+
Assert.IsFalse(Optimizely.IsFeatureEnabled(featureKey, "", null));
1396+
1397+
Assert.IsFalse(Optimizely.IsFeatureEnabled(null, TestUserId, null));
1398+
Assert.IsFalse(Optimizely.IsFeatureEnabled("", TestUserId, null));
13991399

14001400
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, "User ID must not be empty."), Times.Exactly(2));
14011401
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, "Feature flag key must not be empty."), Times.Exactly(2));
@@ -1406,7 +1406,7 @@ public void TestIsFeatureEnabledGivenNullOrEmptyArguments()
14061406
public void TestIsFeatureEnabledGivenFeatureFlagNotFound()
14071407
{
14081408
var featureKey = "feature_not_found";
1409-
Assert.Null(Optimizely.IsFeatureEnabled(featureKey, TestUserId, null));
1409+
Assert.IsFalse(Optimizely.IsFeatureEnabled(featureKey, TestUserId, null));
14101410

14111411
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, $@"Feature key ""{featureKey}"" is not in datafile."));
14121412
}

OptimizelySDK/Optimizely.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,23 @@ public Variation GetForcedVariation(string experimentKey, string userId)
334334
/// <param name="userId">The user ID</param>
335335
/// <param name="userAttributes">The user's attributes.</param>
336336
/// <returns>True if feature is enabled, false or null otherwise</returns>
337-
public bool? IsFeatureEnabled(string featureKey, string userId, UserAttributes userAttributes = null)
337+
public bool IsFeatureEnabled(string featureKey, string userId, UserAttributes userAttributes = null)
338338
{
339339
if (string.IsNullOrEmpty(userId))
340340
{
341341
Logger.Log(LogLevel.ERROR, "User ID must not be empty.");
342-
return null;
342+
return false;
343343
}
344344

345345
if (string.IsNullOrEmpty(featureKey))
346346
{
347347
Logger.Log(LogLevel.ERROR, "Feature flag key must not be empty.");
348-
return null;
348+
return false;
349349
}
350350

351351
var featureFlag = Config.GetFeatureFlagFromKey(featureKey);
352352
if (string.IsNullOrEmpty(featureFlag.Key))
353-
return null;
353+
return false;
354354

355355
if (!Validator.IsFeatureFlagValid(Config, featureFlag))
356356
return false;

0 commit comments

Comments
 (0)