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 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_non_active_when_claim_value_is_not_on_valid_partition() { var toggle = Build .Toggle <GradualRolloutSessionToggle>() .AddOneParameter("Percentage", 0) .Build(); var feature = Build .Feature(Constants.FeatureName) .AddOne(toggle) .Build(); var loggerFactory = new LoggerFactory(); var context = new DefaultHttpContext(); context.Session = new FakeSession(); var store = new DelegatedValueFeatureStore((_, __) => feature); var gradualRolloutSession = new GradualRolloutSessionToggle(store, new FakeHttpContextAccesor(context), loggerFactory.CreateLogger <GradualRolloutSessionToggle>()); var active = await gradualRolloutSession.IsActiveAsync(Constants.FeatureName); active.Should() .BeFalse(); }
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 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 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); }); }