Example #1
0
        public void TestGetStoredVariationLogsWhenLookupReturnsNull()
        {
            Experiment experiment = ProjectConfig.Experiments[6];

            UserProfileService userProfileService = UserProfileServiceMock.Object;
            UserProfile        userProfile        = new UserProfile(UserProfileId, new Dictionary <string, Decision>());

            Bucketer bucketer = new Bucketer(LoggerMock.Object);

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

            DecisionService decisionService = new DecisionService(bucketer,
                                                                  ErrorHandlerMock.Object, ProjectConfig, userProfileService, LoggerMock.Object);

            Assert.IsNull(decisionService.GetStoredVariation(experiment, userProfile));

            LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("No previously activated variation of experiment \"{0}\" for user \"{1}\" found in user profile."
                                                                      , experiment.Key, UserProfileId)), Times.Once);
        }
Example #2
0
        public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
        {
            Experiment experiment        = ProjectConfig.Experiments[6];
            string     storedVariationId = "missingVariation";
            Decision   storedDecision    = new Decision(storedVariationId);

            var storedDecisions = new Dictionary <string, Decision>();

            storedDecisions[experiment.Id] = storedDecision;

            UserProfile storedUserProfile = new UserProfile(UserProfileId, storedDecisions);

            Bucketer bucketer = new Bucketer(LoggerMock.Object);

            UserProfileServiceMock.Setup(up => up.Lookup(UserProfileId)).Returns(storedUserProfile.ToMap());

            DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, ProjectConfig,
                                                                  UserProfileServiceMock.Object, LoggerMock.Object);

            Assert.IsNull(decisionService.GetStoredVariation(experiment, storedUserProfile));
            LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" was previously bucketed into variation with ID \"{1}\" for experiment \"{2}\", but no matching variation was found for that user. We will re-bucket the user."
                                                                      , UserProfileId, storedVariationId, experiment.Id)), Times.Once);
        }