public void TestGetForcedVariationReturnsNullWhenUserIsNotWhitelisted() { Bucketer bucketer = new Bucketer(LoggerMock.Object); DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object); Assert.IsNull(decisionService.GetWhitelistedVariation(WhitelistedExperiment, GenericUserId)); }
public void TestGetForcedVariationReturnsForcedVariation() { DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object); Assert.IsTrue(TestData.CompareObjects(WhitelistedVariation, decisionService.GetWhitelistedVariation(WhitelistedExperiment, WhitelistedUserId))); LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" is forced in variation \"{1}\".", WhitelistedUserId, WhitelistedVariation.Key)), Times.Once); BucketerMock.Verify(_ => _.Bucket(It.IsAny <ProjectConfig>(), It.IsAny <Experiment>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void TestGetForcedVariationWithInvalidVariation() { string userId = "testUser1"; string invalidVariationKey = "invalidVarKey"; DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object); var variations = new Variation[] { new Variation { Id = "1", Key = "var1" } }; var trafficAllocation = new TrafficAllocation[] { new TrafficAllocation { EntityId = "1", EndOfRange = 1000 } }; var userIdToVariationKeyMap = new Dictionary <string, string> { { userId, invalidVariationKey } }; var experiment = new Experiment { Id = "1234", Key = "exp_key", Status = "Running", LayerId = "1", AudienceIds = new string[0], Variations = variations, TrafficAllocation = trafficAllocation, ForcedVariations = userIdToVariationKeyMap }; Assert.IsNull(decisionService.GetWhitelistedVariation(experiment, userId)); LoggerMock.Verify(l => l.Log(LogLevel.ERROR, string.Format("Variation \"{0}\" is not in the datafile. Not activating user \"{1}\".", invalidVariationKey, userId)), Times.Once); BucketerMock.Verify(_ => _.Bucket(It.IsAny <ProjectConfig>(), It.IsAny <Experiment>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }