Skip to content

Commit

Permalink
test: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikechu-optimizely committed Oct 22, 2024
1 parent 03037e2 commit 2ea917e
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions OptimizelySDK.Tests/DecisionServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2021, Optimizely and contributors
* Copyright 2017-2021, 2024 Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,8 +65,8 @@ public void SetUp()
DecisionService = new DecisionService(new Bucketer(LoggerMock.Object),
ErrorHandlerMock.Object, null, LoggerMock.Object);
DecisionServiceMock = new Mock<DecisionService>(BucketerMock.Object,
ErrorHandlerMock.Object, null, LoggerMock.Object)
{ CallBase = true };
ErrorHandlerMock.Object, null, LoggerMock.Object)
{ CallBase = true };
DecisionReasons = new DecisionReasons();

VariationWithKeyControl =
Expand Down Expand Up @@ -294,6 +294,9 @@ public void TestBucketReturnsVariationStoredInUserProfile()
{
var experiment = ProjectConfig.Experiments[6];
var variation = experiment.Variations[0];
var variationResult = Result<Variation>.NewResult(
experiment.Variations[0],
DecisionReasons);
var decision = new Decision(variation.Id);

var userProfile = new UserProfile(UserProfileId, new Dictionary<string, Decision>
Expand All @@ -303,8 +306,10 @@ public void TestBucketReturnsVariationStoredInUserProfile()

UserProfileServiceMock.Setup(_ => _.Lookup(UserProfileId)).Returns(userProfile.ToMap());

var decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object,
UserProfileServiceMock.Object, LoggerMock.Object);
BucketerMock.
Setup(bm => bm.Bucket(ProjectConfig, experiment, It.IsAny<string>(),
It.IsAny<string>())).
Returns(variationResult);

var optlyObject = new Optimizely(TestData.Datafile, new ValidEventDispatcher(),
LoggerMock.Object);
Expand All @@ -313,6 +318,8 @@ public void TestBucketReturnsVariationStoredInUserProfile()
LoggerMock.Object);
OptimizelyUserContextMock.Setup(ouc => ouc.GetUserId()).Returns(UserProfileId);

var decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object,
UserProfileServiceMock.Object, LoggerMock.Object);
var actualVariation = decisionService.GetVariation(experiment,
OptimizelyUserContextMock.Object, ProjectConfig);

Expand Down Expand Up @@ -739,7 +746,8 @@ public void TestGetVariationForFeatureExperimentGivenNonMutexGroupAndUserIsBucke
DecisionServiceMock.Setup(ds => ds.GetVariation(
ProjectConfig.GetExperimentFromKey("test_experiment_multivariate"),
OptimizelyUserContextMock.Object, ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<UserProfileTracker>(),
It.IsAny<DecisionReasons>())).
Returns(variation);

var featureFlag = ProjectConfig.GetFeatureFlagFromKey("multi_variate_feature");
Expand Down Expand Up @@ -792,13 +800,18 @@ public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserIsBucketed
[Test]
public void TestGetVariationForFeatureExperimentGivenMutexGroupAndUserNotBucketed()
{
var mutexExperiment = ProjectConfig.GetExperimentFromKey("group_experiment_1");
var optlyObject = new Optimizely(TestData.Datafile, new ValidEventDispatcher(),
LoggerMock.Object);
OptimizelyUserContextMock = new Mock<OptimizelyUserContext>(optlyObject,
WhitelistedUserId, new UserAttributes(), ErrorHandlerMock.Object,
LoggerMock.Object);
OptimizelyUserContextMock.Setup(ouc => ouc.GetUserId()).Returns("user1");

DecisionServiceMock.
Setup(ds => ds.GetVariation(It.IsAny<Experiment>(),
It.IsAny<OptimizelyUserContext>(), ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
It.IsAny<OptimizelyDecideOption[]>(), It.IsAny<UserProfileTracker>(),
It.IsAny<DecisionReasons>())).
Returns(Result<Variation>.NullResult(null));

var featureFlag = ProjectConfig.GetFeatureFlagFromKey("boolean_feature");
Expand Down Expand Up @@ -1312,6 +1325,11 @@ public void TestGetVariationForFeatureWhenTheUserIsBuckedtedInBothExperimentAndR
WhitelistedUserId, userAttributes, ErrorHandlerMock.Object, LoggerMock.Object);
OptimizelyUserContextMock.Setup(ouc => ouc.GetUserId()).Returns(UserProfileId);

BucketerMock.
Setup(bm => bm.Bucket(ProjectConfig, experiment, It.IsAny<string>(),
It.IsAny<string>())).
Returns(variation);

DecisionServiceMock.Setup(ds => ds.GetVariation(experiment,
OptimizelyUserContextMock.Object, ProjectConfig,
It.IsAny<OptimizelyDecideOption[]>())).
Expand Down

0 comments on commit 2ea917e

Please sign in to comment.