public async Task be_active_when_claim_value_is_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutClaimValueToggle>() .AddOneParameter("ClaimType", "some_claim_type") .AddOneParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.User = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim("some_claim_type", "some_claim_value") }, "cookies")); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutClaimValue = new GradualRolloutClaimValueToggle(partitioner, store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutClaimValue.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }
public async Task be_non_active_when_claim_value_is_not_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutClaimValueToggle>() .AddParameter("ClaimType", "some_claim_type") .AddParameter("Percentage", 0) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.User = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim("some_claim_type", "some_claim_value") }, "cookies")); var partitioner = new DefaultValuePartitioner(); var gradualRolloutClaimValue = new GradualRolloutClaimValueToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutClaimValue.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeFalse(); }
public async Task be_active_when_claim_value_is_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutHeaderValueToggle>() .AddOneParameter("HeaderName", "header-name") .AddOneParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Request.Headers.Add(new KeyValuePair <string, StringValues>("header-name", "header-value")); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutHeaderValue = new GradualRolloutHeaderValueToggle(partitioner, store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutHeaderValue.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }
public async Task be_no_active_when_percentage_is_zero_percent() { var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddParameter(Percentage, 0) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.User = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimsIdentity.DefaultNameClaimType, "User1") }, "cookies")); var contextAccessor = new FakeHttpContextAccessor(context); var partitioner = new DefaultValuePartitioner(); var active = await new GradualRolloutUserNameToggle(partitioner, contextAccessor).IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should().BeFalse(); }
public async Task be_active_when_user_partition_is_on_percent_bucket(string username, int percentage) { var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + username, partitions: 100); var expected = partition <= percentage; var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddParameter(Percentage, percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.User = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim(ClaimsIdentity.DefaultNameClaimType, username) }, "cookies")); var contextAccessor = new FakeHttpContextAccessor(context); var partitioner = new DefaultValuePartitioner(); var active = await new GradualRolloutUserNameToggle(partitioner, contextAccessor).IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should().Be(expected); }
public async Task be_active_when_session_is_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Session = new FakeSession(); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutSession.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeTrue(); }
public async Task throw_when_session_is_not_active() { var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, new FakeHttpContextAccessor(context)); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await gradualRolloutSession.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); }); }
public async Task be_active_when_claim_value_is_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutHeaderValueToggle>() .AddParameter("HeaderName", "header-name") .AddParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Request.Headers.Add(new KeyValuePair <string, StringValues>("header-name", "header-value")); var partitioner = new DefaultValuePartitioner(); var gradualRolloutHeaderValue = new GradualRolloutHeaderValueToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutHeaderValue.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeTrue(); }
public async Task be_active_when_session_is_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddOneParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Session = new FakeSession(); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutSession.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }
public void throw_if_httpcontextaccessor_is_null() { Assert.Throws <ArgumentNullException>(() => { var partitioner = new DefaultValuePartitioner(); new GradualRolloutHeaderValueToggle(partitioner, null); }); }
public void throw_if_httpcontextaccessor_is_null() { Assert.Throws <ArgumentNullException>(() => { var store = new DelegatedValueFeatureStore((_, __) => null); var partitioner = new DefaultValuePartitioner(); new GradualRolloutSessionToggle(partitioner, store, null); }); }
public void throw_if_store_service_is_null() { Assert.Throws <ArgumentNullException>(() => { var accessor = new FakeHttpContextAccesor(); var partitioner = new DefaultValuePartitioner(); new GradualRolloutClaimValueToggle(partitioner, null, accessor); }); }
public void throw_if_partitioner_is_null() { Assert.Throws <ArgumentNullException>(() => { var accessor = new FakeHttpContextAccessor(); var partitioner = new DefaultValuePartitioner(); new GradualRolloutHeaderValueToggle(null, accessor); }); }
public void throw_if_partitioner_is_null() { Assert.Throws <ArgumentNullException>(() => { var store = new DelegatedValueFeatureStore((_, __) => null); var accessor = new FakeHttpContextAccesor(); var partitioner = new DefaultValuePartitioner(); new GradualRolloutHeaderValueToggle(null, store, accessor); }); }
public async Task use_partition_for_claim_value(int percentage) { var valid = false; var claim_value = default(string); do { claim_value = Guid.NewGuid().ToString(); var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + claim_value, partitions: 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutClaimValueToggle>() .AddParameter("ClaimType", "some_claim_type") .AddParameter("Percentage", percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.User = new ClaimsPrincipal( new ClaimsIdentity(new Claim[] { new Claim("some_claim_type", claim_value) }, "cookies")); var partitioner = new DefaultValuePartitioner(); var gradualRolloutClaimValue = new GradualRolloutClaimValueToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutClaimValue.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeTrue(); }
public async Task use_partition_for_claim_value(int percentage) { var valid = false; var header_value = default(string); do { header_value = Guid.NewGuid().ToString(); var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + header_value, partitions: 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutHeaderValueToggle>() .AddParameter("HeaderName", "header-name") .AddParameter("Percentage", percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Request.Headers.Add(new KeyValuePair <string, StringValues>("header-name", header_value)); var partitioner = new DefaultValuePartitioner(); var gradualRolloutHeaderValue = new GradualRolloutHeaderValueToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutHeaderValue.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeTrue(); }
public async Task be_active_when_percentage_is_hundred_percent() { var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddOneParameter(Percentage, 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var store = new DelegatedValueFeatureStore((_, __) => feature); var userNameProvider = new DelegatedUserNameProviderService(() => "User1"); var partitioner = new DefaultValuePartitioner(); var active = await new GradualRolloutUserNameToggle(partitioner, userNameProvider, store).IsActiveAsync(Constants.FeatureName, Constants.ProductName); active.Should().BeTrue(); }
public async Task use_partition_for_session(int percentage) { var valid = false; var sessionId = string.Empty; do { sessionId = Guid.NewGuid().ToString(); var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + sessionId, partitions: 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddParameter("Percentage", percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Session = new FakeSession(sessionId); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, new FakeHttpContextAccessor(context)); var active = await gradualRolloutSession.IsActiveAsync( ToggleExecutionContext.FromToggle( feature.Name, EsquioConstants.DEFAULT_PRODUCT_NAME, EsquioConstants.DEFAULT_DEPLOYMENT_NAME, toggle)); active.Should() .BeTrue(); }
public void throw_if_username_provider_is_null() { var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddParameter(Percentage, 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var partitioner = new DefaultValuePartitioner(); Assert.Throws <ArgumentNullException>(() => { new GradualRolloutUserNameToggle(partitioner, httpContextAccessor: null); }); }
public void throw_if_username_provider_is_null() { var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddOneParameter(Percentage, 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); Assert.Throws <ArgumentNullException>(() => { new GradualRolloutUserNameToggle(partitioner, userNameProviderService: null, store); }); }
public async Task use_partition_for_claim_value(int percentage) { var valid = false; var header_value = default(string); do { header_value = Guid.NewGuid().ToString(); var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + header_value, partitions: 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutHeaderValueToggle>() .AddOneParameter("HeaderName", "header-name") .AddOneParameter("Percentage", percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Request.Headers.Add(new KeyValuePair <string, StringValues>("header-name", header_value)); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutHeaderValue = new GradualRolloutHeaderValueToggle(partitioner, store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutHeaderValue.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }
public async Task use_partition_for_session(int percentage) { var valid = false; var sessionId = string.Empty; do { sessionId = Guid.NewGuid().ToString(); var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + sessionId, partitions: 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddOneParameter("Percentage", percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); context.Session = new FakeSession(sessionId); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutSession.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }
public async Task be_active_when_user_partition_is_on_percent_bucket(string username, int percentage) { var partition = new DefaultValuePartitioner().ResolvePartition(Constants.FeatureName + username, partitions: 100); var expected = partition <= percentage; var toggle = Build .Toggle <GradualRolloutUserNameToggle>() .AddOneParameter(Percentage, percentage) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var store = new DelegatedValueFeatureStore((_, __) => feature); var userNameProvider = new DelegatedUserNameProviderService(() => username); var partitioner = new DefaultValuePartitioner(); var actual = await new GradualRolloutUserNameToggle(partitioner, userNameProvider, store).IsActiveAsync(Constants.FeatureName, Constants.ProductName); actual.Should().Be(expected); }
public async Task throw_when_session_is_not_active() { var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddOneParameter("Percentage", 100) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var context = new DefaultHttpContext(); var store = new DelegatedValueFeatureStore((_, __) => feature); var partitioner = new DefaultValuePartitioner(); var gradualRolloutSession = new GradualRolloutSessionToggle(partitioner, store, new FakeHttpContextAccesor(context)); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await gradualRolloutSession.IsActiveAsync(Constants.FeatureName); }); }