public void should_be_disabled_when_missing_user_id() { var context = UnleashContext.New().Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); gradualRolloutStrategy.IsEnabled(new Dictionary <string, string>(), context).Should().BeFalse(); }
public void test(string actualIp, string parameterstring, bool expected) { var context = UnleashContext.New().RemoteAddress(actualIp).Build(); var parameters = setupParameterMap(parameterstring); strategy.IsEnabled(parameters, context).Should().Be(expected); }
public void should_at_most_miss_with_one_percent_when_rolling_out_to_specified_percentage() { string groupId = "group1"; int percentage = 25; int rounds = 20000; int enabledCount = 0; var paramseters = buildParams(percentage, groupId); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); for (var userId = 0; userId < rounds; userId++) { var context = UnleashContext.New().UserId("user" + userId).Build(); if (gradualRolloutStrategy.IsEnabled(paramseters, context)) { enabledCount++; } } var actualPercentage = (enabledCount / (double)rounds) * 100.0; ((percentage - 1) < actualPercentage) .Should().BeTrue("Expected " + percentage + "%, but was " + actualPercentage + "%"); ((percentage + 1) > actualPercentage).Should() .BeTrue("Expected " + percentage + "%, but was " + actualPercentage + "%"); }
public void IsEnabled_Always_ShouldReturnFalse() { var context = UnleashContext.New().Build(); var parameters = new Dictionary <string, string>(); var result = Strategy.IsEnabled(parameters, context); Assert.False(result); }
public void IsEnabled_WhenUserIdIsMissing_ShouldReturnFalse() { var context = UnleashContext.New().Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); var result = gradualRolloutStrategy.IsEnabled(new Dictionary <string, string>(), context); Assert.False(result); }
public void should_not_be_enabled_when_0percent_rollout() { var context = UnleashContext.New().UserId("1574576830").Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); var paramseters = buildParams(0, "innfinn"); var actual = gradualRolloutStrategy.IsEnabled(paramseters, context); actual.Should().BeFalse("should not be enabled when 0% rollout"); }
public void should_be_enabled_when_using_100percent_rollout() { var context = UnleashContext.New().UserId("1574576830").Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); var paramseters = buildParams(100, "innfinn"); var result = gradualRolloutStrategy.IsEnabled(paramseters, context); result.Should().BeTrue(); }
public void should_match_csv_without_space() { var parameters = new Dictionary <string, string>(); var context = UnleashContext.New().UserId("123").Build(); parameters.Add(strategy.UserIdsConst, "123,122,121"); strategy.IsEnabled(parameters, context).Should().BeTrue();; }
public void should_not_match_subparts_of_ids() { var parameters = new Dictionary <string, string>(); var context = UnleashContext.New().UserId("12").Build(); parameters.Add(strategy.UserIdsConst, "123, 122, 121, 212"); strategy.IsEnabled(parameters, context).Should().BeFalse(); }
public void should_match_middle_userId_in_list() { var parameters = new Dictionary <string, string>(); var context = UnleashContext.New().UserId("122").Build(); parameters.Add(strategy.UserIdsConst, "123, 122, 121"); strategy.IsEnabled(parameters, context).Should().BeTrue(); }
public void should_match_real_ids() { var parameters = new Dictionary <string, string>(); var context = UnleashContext.New().UserId("298261117").Build(); parameters.Add(strategy.UserIdsConst, "160118738, 1823311338, 1422637466, 2125981185, 298261117, 1829486714, 463568019, 271166598"); strategy.IsEnabled(parameters, context).Should().BeTrue(); }
public void IsEnabled_ShouldReturnExpectedValue(string actualIp, string parameterString, bool expected) { var context = UnleashContext.New().RemoteAddress(actualIp).Build(); var parameters = new Dictionary <string, string> { [RemoteAddressStrategy.PARAM] = parameterString }; var actual = Strategy.IsEnabled(parameters, context); Assert.Equal(expected, actual); }
public void should_have_same_result_for_multiple_executions() { var context = UnleashContext.New().UserId("1574576830").Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); var paramseters = buildParams(1, "innfinn"); var firstRunResult = gradualRolloutStrategy.IsEnabled(paramseters, context); for (int i = 0; i < 10; i++) { var subsequentRunResult = gradualRolloutStrategy.IsEnabled(paramseters, context); firstRunResult.Should().Be(subsequentRunResult, "loginId will return same result when unchanged parameters"); } }
public void should_be_enabled_above_minimum_percentage() { var userId = "1574576830"; var groupId = ""; var minimumPercentage = StrategyUtils.GetNormalizedNumber(userId, groupId); var context = UnleashContext.New().UserId(userId).Build(); var gradualRolloutStrategy = new GradualRolloutUserIdStrategy(); for (var p = minimumPercentage; p <= 100; p++) { var paramseters = buildParams(p, groupId); var actual = gradualRolloutStrategy.IsEnabled(paramseters, context); actual.Should().BeTrue("should be enabled when " + p + "% rollout"); } }
protected int checkRandomLoginIDs(int numberOfIDs, int percentage) { int numberOfEnabledUsers = 0; for (int i = 0; i < numberOfIDs; i++) { var sessionId = getRandomLoginId(); var context = UnleashContext.New().SessionId(sessionId.ToString()).Build(); var gradualRolloutStrategy = new GradualRolloutSessionIdStrategy(); var parameters = buildParams(percentage, ""); bool enabled = gradualRolloutStrategy.IsEnabled(parameters, context); if (enabled) { numberOfEnabledUsers++; } } return(numberOfEnabledUsers); }
public void IsEnabled_WhenContextIsComparedToParameters_ShouldReturnExpectedResult( string contextUserId, string userIdsParameterValue, bool expectedResult) { var contextBuilder = UnleashContext.New(); if (contextUserId != null) { contextBuilder = contextBuilder.UserId(contextUserId); } var context = contextBuilder.Build(); var parameters = new Dictionary <string, string> { [Strategy.UserIdsConst] = userIdsParameterValue }; var actualResult = Strategy.IsEnabled(parameters, context); Assert.Equal(expectedResult, actualResult); }