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 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 claim_value = default(string); do { claim_value = Guid.NewGuid().ToString(); var partition = global::Esquio.Abstractions.Partitioner.ResolveToLogicalPartition(claim_value, 100); if (partition <= percentage) { valid = true; } } while (!valid); var toggle = Build .Toggle <GradualRolloutClaimValueToggle>() .AddOneParameter("ClaimType", "some_claim_type") .AddOneParameter("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 store = new DelegatedValueFeatureStore((_, __) => feature); var gradualRolloutClaimValue = new GradualRolloutClaimValueToggle(store, new FakeHttpContextAccesor(context)); var active = await gradualRolloutClaimValue.IsActiveAsync(Constants.FeatureName); active.Should() .BeTrue(); }