From 49f9584f80f803c23734eac2bd6403c61c5f93ac Mon Sep 17 00:00:00 2001 From: Mike Chu Date: Fri, 18 Oct 2024 11:23:20 -0400 Subject: [PATCH] test: corrections --- OptimizelySDK.Tests/DecisionServiceTest.cs | 10 ++-- OptimizelySDK.Tests/OptimizelyTest.cs | 65 +++++++++++++--------- OptimizelySDK/Optimizely.cs | 11 ++-- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/OptimizelySDK.Tests/DecisionServiceTest.cs b/OptimizelySDK.Tests/DecisionServiceTest.cs index 633847ae..94c47a38 100644 --- a/OptimizelySDK.Tests/DecisionServiceTest.cs +++ b/OptimizelySDK.Tests/DecisionServiceTest.cs @@ -700,7 +700,7 @@ public void TestGetVariationForFeatureExperimentGivenNonMutexGroupAndUserNotBuck DecisionServiceMock. Setup(ds => ds.GetVariation(multiVariateExp, OptimizelyUserContextMock.Object, - ProjectConfig, null)). + ProjectConfig, It.IsAny(), It.IsAny())). Returns(null); var featureFlag = ProjectConfig.GetFeatureFlagFromKey("multi_variate_feature"); @@ -736,7 +736,7 @@ public void TestGetVariationForFeatureExperimentGivenNonMutexGroupAndUserIsBucke DecisionServiceMock.Setup(ds => ds.GetVariation( ProjectConfig.GetExperimentFromKey("test_experiment_multivariate"), OptimizelyUserContextMock.Object, ProjectConfig, - It.IsAny())). + It.IsAny(), It.IsAny())). Returns(variation); var featureFlag = ProjectConfig.GetFeatureFlagFromKey("multi_variate_feature"); @@ -771,7 +771,7 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserIsBucketed DecisionServiceMock. Setup(ds => ds.GetVariation(ProjectConfig.GetExperimentFromKey("group_experiment_1"), - OptimizelyUserContextMock.Object, ProjectConfig)). + OptimizelyUserContextMock.Object, ProjectConfig, It.IsAny(), It.IsAny())). Returns(variation); var featureFlag = ProjectConfig.GetFeatureFlagFromKey("boolean_feature"); @@ -795,7 +795,7 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserNotBuckete DecisionServiceMock. Setup(ds => ds.GetVariation(It.IsAny(), It.IsAny(), ProjectConfig, - It.IsAny())). + It.IsAny(), It.IsAny())). Returns(Result.NullResult(null)); var featureFlag = ProjectConfig.GetFeatureFlagFromKey("boolean_feature"); @@ -1311,7 +1311,7 @@ public void TestGetVariationForFeatureWhenTheUserIsBuckedtedInBothExperimentAndR DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, OptimizelyUserContextMock.Object, ProjectConfig, - It.IsAny())). + It.IsAny(), It.IsAny())). Returns(variation); var actualDecision = DecisionServiceMock.Object.GetVariationForFeatureExperiment( featureFlag, OptimizelyUserContextMock.Object, userAttributes, ProjectConfig, diff --git a/OptimizelySDK.Tests/OptimizelyTest.cs b/OptimizelySDK.Tests/OptimizelyTest.cs index f83304bb..f2d85fe9 100644 --- a/OptimizelySDK.Tests/OptimizelyTest.cs +++ b/OptimizelySDK.Tests/OptimizelyTest.cs @@ -1,5 +1,5 @@ /* - * Copyright 2017-2023, Optimizely + * Copyright 2017-2024, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -3395,8 +3395,9 @@ public void TestActivateListener(UserAttributes userAttributes) mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId); DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, - It.IsAny(), It.IsAny())) - .Returns(variation); + It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())). + Returns(variation); DecisionServiceMock.Setup(ds => ds.GetVariationForFeature(featureFlag, It.IsAny(), It.IsAny())) .Returns(decision); @@ -3509,9 +3510,10 @@ public void TestTrackListener(UserAttributes userAttributes, EventTags eventTags ErrorHandlerMock.Object, LoggerMock.Object); mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId); - DecisionServiceMock - .Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config)) - .Returns(variation); + DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, + It.IsAny(), Config, It.IsAny(), + It.IsAny())). + Returns(variation); // Adding notification listeners. var notificationType = NotificationCenter.NotificationType.Track; @@ -3565,9 +3567,10 @@ public void TestActivateSendsDecisionNotificationWithActualVariationKey() It.IsAny(), It.IsAny(), It.IsAny>())); - DecisionServiceMock - .Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config)) - .Returns(variation); + DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, + It.IsAny(), Config, It.IsAny(), + It.IsAny())). + Returns(variation); var optly = Helper.CreatePrivateOptimizely(); optly.SetFieldOrProperty("ProjectConfigManager", ConfigManager); @@ -3622,9 +3625,10 @@ public void It.IsAny(), It.IsAny(), It.IsAny>())); - DecisionServiceMock - .Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config)) - .Returns(variation); + DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, + It.IsAny(), Config, It.IsAny(), + It.IsAny())). + Returns(variation); var optly = Helper.CreatePrivateOptimizely(); optly.SetFieldOrProperty("ProjectConfigManager", ConfigManager); @@ -3666,8 +3670,9 @@ public void TestActivateSendsDecisionNotificationWithNullVariationKey() DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, It.IsAny(), - It.IsAny(), null)) - .Returns(Result.NullResult(null)); + It.IsAny(), It.IsAny(), + It.IsAny())). + Returns(Result.NullResult(null)); optStronglyTyped.NotificationCenter.AddNotification( NotificationCenter.NotificationType.Decision, @@ -3727,9 +3732,10 @@ public void TestGetVariationSendsDecisionNotificationWithActualVariationKey() ErrorHandlerMock.Object, LoggerMock.Object); mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId); - DecisionServiceMock - .Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config)) - .Returns(variation); + DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, + It.IsAny(), Config, It.IsAny(), + It.IsAny())). + Returns(variation); optStronglyTyped.NotificationCenter.AddNotification( NotificationCenter.NotificationType.Decision, @@ -3788,9 +3794,10 @@ public void ErrorHandlerMock.Object, LoggerMock.Object); mockUserContext.Setup(ouc => ouc.GetUserId()).Returns(TestUserId); - DecisionServiceMock - .Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config)) - .Returns(variation); + DecisionServiceMock. + Setup(ds => ds.GetVariation(experiment, It.IsAny(), Config + , It.IsAny(), It.IsAny())). + Returns(variation); optStronglyTyped.NotificationCenter.AddNotification( NotificationCenter.NotificationType.Decision, @@ -3828,8 +3835,9 @@ public void TestGetVariationSendsDecisionNotificationWithNullVariationKey() It.IsAny(), It.IsAny>())); DecisionServiceMock.Setup(ds => ds.GetVariation(It.IsAny(), - It.IsAny(), It.IsAny())) - .Returns(Result.NullResult(null)); + It.IsAny(), It.IsAny() + , It.IsAny(), It.IsAny())). + Returns(Result.NullResult(null)); //DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, TestUserId, Config, null)).Returns(Result.NullResult(null)); optStronglyTyped.NotificationCenter.AddNotification( @@ -3875,8 +3883,9 @@ public void It.IsAny(), It.IsAny>())); DecisionServiceMock.Setup(ds => ds.GetVariation(experiment, - It.IsAny(), ConfigManager.GetConfig(), null)) - .Returns(variation); + It.IsAny(), ConfigManager.GetConfig() + , It.IsAny(), It.IsAny())). + Returns(variation); var optly = Helper.CreatePrivateOptimizely(); var optStronglyTyped = optly.GetObject() as Optimizely; @@ -3936,8 +3945,9 @@ public void It.IsAny(), It.IsAny>())); DecisionServiceMock.Setup(ds => - ds.GetVariation(experiment, It.IsAny(), Config, null)) - .Returns(variation); + ds.GetVariation(experiment, It.IsAny(), Config + , It.IsAny(), It.IsAny())). + Returns(variation); var optly = Helper.CreatePrivateOptimizely(); var optStronglyTyped = optly.GetObject() as Optimizely; @@ -5322,7 +5332,8 @@ public void TestGetAllFeatureVariablesReturnsNullScenarios() LoggerMock.Verify( log => log.Log(LogLevel.ERROR, - "Optimizely instance is not valid, failing getAllFeatureVariableValues call. type"), + "Optimizely instance is not valid, failing getAllFeatureVariableValues call. type") + , Times.Once); } diff --git a/OptimizelySDK/Optimizely.cs b/OptimizelySDK/Optimizely.cs index 3b5c37fa..19e2a417 100644 --- a/OptimizelySDK/Optimizely.cs +++ b/OptimizelySDK/Optimizely.cs @@ -931,10 +931,13 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user, decisionReasons += flagDecisionResult.DecisionReasons; decision = flagDecisionResult.ResultObject; } - - DecisionService.AddDecisionToUnitOfWork(userId, decision.Experiment?.Id, - new Decision(decision.Variation?.Id)); - + + if (!options.Contains(OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE)) + { + DecisionService.AddDecisionToUnitOfWork(userId, decision.Experiment?.Id, + new Decision(decision.Variation?.Id)); + } + var featureEnabled = false; if (decision?.Variation != null)