public async Task delete_response_no_content_if_toggle_exist_and_is_the_only_one() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var deployment = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("toggle-type-1") .Build(); var parameter = Builders.Parameter() .WithName("param1") .WithValue("value1") .WithRingName(deployment.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); product.Deployments .Add(deployment); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.Delete(product.Name, feature.Name, toggle.Type)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task post_response_bad_request_if_try_to_duplicate_toggle() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType(typeof(EnvironmentToggle).FullName) .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var body = new AddToggleRequest() { FeatureId = feature.Id, Type = typeof(EnvironmentToggle).FullName, Parameters = new List <AddToggleRequestDetailParameter>() }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Post()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(body); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task postparameter_response_ok_if_toggle_exist_but_is_new_parameter() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType(typeof(EnvironmentToggle).FullName) .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var parameterToggleRequest = new AddParameterToggleRequest() { Name = "Environments", Value = "Production", }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.PostParameter(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task reveal_response_forbidden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .WithReadPermission(false) .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Reveal("Esquio.Toggles.EnvironmentToggle")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task delete_response_no_content_if_toggle_exist() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("toggle-type-1") .Build(); var parameter = Builders.Parameter() .WithName("param#1") .WithValue("value#1") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Delete(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task reveal_response_forbidden_if_user_is_not_authorized() { var deployment = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(deployment.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.Reveal("Esquio.Toggles.EnvironmentToggle")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task delete_response_no_content_when_delete_product_with_features_toggles_and_parameters() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("toggle-type-1") .Build(); var parameter = Builders.Parameter() .WithName("param#1") .WithValue("value#1") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Delete(product.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task reveal_response_ok_if_toggle_exist_and_parameters_can_be_revealed() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Reveal("Esquio.Toggles.EnvironmentToggle")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <RevealToggleResponse>(); content.Type .Should() .BeEquivalentTo("Esquio.Toggles.EnvironmentToggle"); content.Parameters .Count .Should().Be(1); content.Parameters .First() .Name .Should().BeEquivalentTo("Environments"); content.Parameters .First() .ClrType .Should().BeEquivalentTo(EsquioConstants.SEMICOLON_LIST_PARAMETER_TYPE); content.Parameters .First() .Description .Should().NotBeNull(); }
public async Task get_response_ok_and_contain_details() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.FromToToggle, Esquio") .Build(); var parameter = Builders.Parameter() .WithName("From") .WithValue("01/91/2991") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Get(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <DetailsToggleResponse>(); content.Type .Should() .BeEquivalentTo("Esquio.Toggles.FromToToggle, Esquio"); content.Assembly .Should() .BeEquivalentTo("Esquio"); content.Parameters .Count .Should().Be(1); content.Parameters .First() .Id .Should().Be(parameter.Id); content.Parameters .First() .Name .Should().Be("From"); content.Parameters .First() .Value .Should().Be("01/91/2991"); }
public async Task get_feature_from_the_store() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); product.Deployments .Add(defaultRing); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var apiKeyValue = "barkey"; var apiKey = Builders.ApiKey() .WithName("fooname") .Withkey(apiKeyValue) .WithValidTo(DateTime.UtcNow.AddDays(1)) .Build(); await _fixture.Given .AddApiKey(apiKey); var store = CreateStore(apiKey: apiKey.Key); var featureModel = await store .FindFeatureAsync(feature.Name, product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME); featureModel.Name .Should() .BeEquivalentTo(feature.Name); featureModel.IsEnabled .Should() .Be(false); featureModel.GetToggles() .Count() .Should().Be(1); featureModel.GetToggles() .First() .Type .Should() .BeEquivalentTo("Esquio.Toggles.EnvironmentToggle,Esquio"); featureModel.GetToggles() .First() .GetParameters() .Count() .Should() .Be(1); featureModel.GetToggles() .First() .GetParameters() .First() .Name .Should() .BeEquivalentTo("Environments"); featureModel.GetToggles() .First() .GetParameters() .First() .Value .Should() .BeEquivalentTo("Development"); }
public async Task reveal_response_ok_if_toggle_exist_and_parameters_can_be_revealed() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var deployment = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeatuer") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentVariableToggle,Esquio") .Build(); var parameterEnvVar = Builders.Parameter() .WithName("EnvironmentVariable") .WithValue("ASPNETCORE_ENVIRONENT") .WithRingName(deployment.Name) .Build(); var parameterValue = Builders.Parameter() .WithName("Values") .WithValue("Development") .WithRingName(deployment.Name) .Build(); toggle.Parameters .Add(parameterEnvVar); toggle.Parameters .Add(parameterValue); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.Reveal("Esquio.Toggles.EnvironmentVariableToggle,Esquio")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <RevealToggleResponse>(); content.Type .Should() .BeEquivalentTo("Esquio.Toggles.EnvironmentVariableToggle,Esquio"); content.Parameters .Count .Should().Be(2); content.Parameters .First() .Name .Should().BeEquivalentTo("EnvironmentVariable"); content.Parameters .First() .ClrType .Should().BeEquivalentTo(EsquioConstants.STRING_PARAMETER_TYPE); content.Parameters .First() .Description .Should().NotBeNull(); }
public async Task addparameter_response_ok_if_toggle_and_parameter_already_exist_but_new_is_for_differnt_ring() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var selectedRing = Builders.Deployment() .WithName("Production") .WithDefault(false) .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType(typeof(HostEnvironmentToggle).FullName) .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); product.Deployments .Add(defaultRing); product.Deployments .Add(selectedRing); await _fixture.Given .AddProduct(product); var parameterToggleRequest = new AddParameterToggleRequest() { ProductName = product.Name, FeatureName = feature.Name, ToggleType = toggle.Type, DeploymentName = selectedRing.Name, Name = "Environments", Value = "Development", }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.PostParameter()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(parameterToggleRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task get_feature_from_the_store_dont_use_cache_if_isnot_configured() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); product.Deployments .Add(defaultRing); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var apiKeyValue = "barkey"; var apiKey = Builders.ApiKey() .WithName("fooname") .Withkey(apiKeyValue) .WithValidTo(DateTime.UtcNow.AddDays(1)) .Build(); await _fixture.Given .AddApiKey(apiKey); var cache = CreateDefaultCache(); var store = CreateCachedStore(cache, apiKey: apiKey.Key, useCache: false); var featureModel = await store .FindFeatureAsync(feature.Name, product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME); featureModel.Name .Should() .BeEquivalentTo(feature.Name); var cacheKey = CacheKeyCreator.GetCacheKey(product.Name, feature.Name, defaultRing.Name, "3.0"); var entry = await cache.GetStringAsync(cacheKey); entry.Should() .BeNull(); await cache.SetStringAsync(cacheKey, "{\"featureName\":\"barfeature\",\"enabled\":false}"); featureModel = await store .FindFeatureAsync(feature.Name, product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME); featureModel.IsEnabled .Should().BeFalse(); }
public async Task get_null_if_features_does_not_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); product.Deployments .Add(defaultRing); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var apiKeyValue = "barkey"; var apiKey = Builders.ApiKey() .WithName("fooname") .Withkey(apiKeyValue) .WithValidTo(DateTime.UtcNow.AddDays(1)) .Build(); await _fixture.Given .AddApiKey(apiKey); var store = CreateStore(apiKey: apiKey.Key); var featureModel = await store .FindFeatureAsync("non-existing", product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME); featureModel.Should() .BeNull(); }
public async Task get_feature_from_the_store_throw_if_cache_is_enabled_but_distributed_cache_service_is_null() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); product.Deployments .Add(defaultRing); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var apiKeyValue = "barkey"; var apiKey = Builders.ApiKey() .WithName("fooname") .Withkey(apiKeyValue) .WithValidTo(DateTime.UtcNow.AddDays(1)) .Build(); await _fixture.Given .AddApiKey(apiKey); var store = CreateCachedStore(null, apiKey: apiKey.Key, useCache: true); await Assert.ThrowsAsync <InvalidOperationException>(async() => { await store.FindFeatureAsync(feature.Name, product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME); }); }
public async Task get_response_ok_and_contain_details() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle = Builders.Toggle() .WithType("toggle-type-1") .Build(); var parameter = Builders.Parameter() .WithName("param#1") .WithValue("value#1") .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Get(toggleId: toggle.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <DetailsToggleResponse>(); content.TypeName .Should() .BeEquivalentTo("toggle-type-1"); content.Parameters .Count .Should().Be(1); content.Parameters .First() .Id .Should().Be(parameter.Id); content.Parameters .First() .Name .Should().Be("param#1"); content.Parameters .First() .Value .Should().Be("value#1"); }
public async Task response_ok_when_sucess() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var defaultRing = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); product.Deployments.Add(defaultRing); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.EnvironmentToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("Environments") .WithValue("Development") .WithRingName(defaultRing.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Configuration.Get(productName: "fooproduct", featureName: "barfeature", deployment: EsquioConstants.DEFAULT_DEPLOYMENT_NAME)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <DetailsConfigurationResponse>(); content.Enabled .Should().BeFalse(); content.FeatureName .Should().Be("barfeature"); content.Toggles .Count .Should().BeGreaterThan(0); content.Toggles ["Esquio.Toggles.EnvironmentToggle,Esquio"] .Count .Should() .Be(1); content.Toggles ["Esquio.Toggles.EnvironmentToggle,Esquio"] ["Environments"] .ToString() .Should() .BeEquivalentTo("Development"); }
public async Task get_response_ok_and_contain_details() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var deployment = Builders.Deployment() .WithName(EsquioConstants.DEFAULT_DEPLOYMENT_NAME) .WithDefault(true) .Build(); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); var toggle = Builders.Toggle() .WithType("Esquio.Toggles.FromToToggle,Esquio") .Build(); var parameter = Builders.Parameter() .WithName("From") .WithValue("01/91/2991") .WithRingName(deployment.Name) .Build(); toggle.Parameters .Add(parameter); feature.Toggles .Add(toggle); product.Features .Add(feature); product.Deployments .Add(deployment); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Toggles.Get(product.Name, feature.Name, toggle.Type)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <DetailsToggleResponse>(); content.Type .Should() .BeEquivalentTo("Esquio.Toggles.FromToToggle,Esquio"); content.Assembly .Should() .BeEquivalentTo("Esquio"); content.Parameters .Count .Should().Be(1); content.Parameters .First() .Name .Should().Be("From"); content.Parameters .First() .Value .Should().Be("01/91/2991"); }