public async Task delete_response_badrequest_if_toggle_not_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Toggles.Delete(product.Name, feature.Name, "non-existing")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task update_response_no_content_if_product_is_updated() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var request = new UpdateProductRequest() { Name = "barproduct", Description = "description for product#2" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.Update(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task deletedeployment_response_noconent_when_success() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var deployment = Builders.Deployment() .WithName("production") .Build(); product.Deployments .Add(deployment); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.DeleteDeployment(product.Name, deployment.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task adddeployment_response_created_when_success() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.AddDeployment(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(new AddDeploymentRequest() { Name = "Production" }); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task add_response_badrequest_if_product_name_already_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var productRequest = new AddProductRequest() { Name = product.Name, Description = "some description" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(productRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task delete_response_no_content_when_delete_product_without_features() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Delete(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task deletedeployment_response_badrequest_if_ring_does_not_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.DeleteDeployment(product.Name, "barring")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task update_response_ok_when_create_the_feature() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature1") .WithEnabled(false) .Build(); product.Features.Add(feature); await _fixture.Given .AddProduct(product); var updateFlagRequest = new UpdateFlagRequest() { Name = "feature#1", Description = "description", Enabled = true, FlagId = feature.Id }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Update()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(updateFlagRequest); response.StatusCode .Should() .Be(StatusCodes.Status200OK); }
public async Task add_response_badrequest_if_feature_with_the_same_name_already_exist_on_same_product() { var product = Builders.Product() .WithName("product#1") .Build(); var feature1 = Builders.Feature() .WithName("feature#1") .Build(); product.Features .Add(feature1); await _fixture.Given .AddProduct(product); var addFlagRequest = new AddFlagRequest() { Name = "feature#1", Description = "description", Enabled = true, ProductId = product.Id }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(addFlagRequest); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task list_response_ok_and_use_default_skip_take_values() { var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.List()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <ListProductResponse>(); content.Total .Should().Be(1); content.Count .Should().Be(1); content.PageIndex .Should().Be(0); content.Result .First().Name .Should().BeEquivalentTo("product#1"); }
public async Task update_response_no_conent_if_product_is_updated() { var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given .AddProduct(product); var request = new UpdateProductRequest() { ProductId = product.Id, Name = "product#2", Description = "description for product#2" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Update()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task list_response_ok_when_no_page_data() { var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.List(pageIndex: 10, pageCount: 10)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <ListProductResponse>(); content.Total .Should().Be(1); content.Count .Should().Be(0); content.PageIndex .Should().Be(10); content.Result .Count .Should().Be(0); }
public async Task importproduct_response_forbiden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithReaderPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("default") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Import()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(new ImportProductRequest() { Content = "{\"Id\":1,\"Name\":\"default\",\"Description\":\"this is default product\",\"Features\":[{\"Id\":1,\"Name\":\"MatchScore\",\"Description\":\"show the match score on products\",\"ProductEntityId\":1,\"Archived\":false,\"FeatureTags\":[],\"FeatureStates\":[],\"Toggles\":[{\"Id\":1,\"Type\":\"Esquio.Toggles.FromToToggle,Esquio\",\"FeatureEntityId\":1,\"Parameters\":[{\"Id\":1,\"ToggleEntityId\":1,\"Name\":\"From\",\"Value\":\"2020-07-13 09:36:23\",\"DeploymentName\":\"Tests\"},{\"Id\":2,\"ToggleEntityId\":1,\"Name\":\"To\",\"Value\":\"2020-07-29 09:36:25\",\"DeploymentName\":\"Tests\"}]}]}],\"Deployments\":[{\"Id\":1,\"Name\":\"Tests\",\"ByDefault\":true,\"ProductEntityId\":1},{\"Id\":2,\"Name\":\"production\",\"ByDefault\":false,\"ProductEntityId\":1}]}" }); response.StatusCode .Should() .Be(HttpStatusCode.Forbidden); }
public async Task get_response_not_found_if_toggle_not_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); var feature = Builders.Feature() .WithName("barfeature") .Build(); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Toggles.Get(productName: product.Name, featureName: feature.Name, toggleType: "non-existing-toggle")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status404NotFound); }
public async Task not_allow_untag_a_feature_when_it_has_not_been_previously_tagged_with_the_tag() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle#1") .Build(); feature.Toggles.Add(toggle1); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Tags.Untag("tag", feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task add_response_ok_when_create_the_feature() { var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given .AddProduct(product); var addFlagRequest = new AddFlagRequest() { Name = "feature#1", Description = "description", Enabled = true, ProductId = product.Id }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Add()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(addFlagRequest); response.StatusCode .Should() .Be(StatusCodes.Status201Created); }
public async Task get_response_ok_if_product_exist() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Get(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content .ReadAs <DetailsProductResponse>(); content.Name .Should().BeEquivalentTo(product.Name); }
public async Task rollout_is_idempotent() { var product = Builders.Product() .WithName("product#2") .Build(); var feature = Builders.Feature() .WithName("feature") .Build(); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Rollout(featureId: feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Rollout(featureId: feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); }
public async Task exportproduct_response_ok_when_success() { var permission = Builders.Permission() .WithReaderPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Export("fooproduct")) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status200OK); var content = await response.Content.ReadAsStringAsync(); }
public async Task delete_response_ok_when_product_and_feature_exist_and_feature_toggles_is_not_empty() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle#1") .Build(); feature.Toggles.Add(toggle1); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Flags.Delete(feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task adddeployment_response_badrequest_if_ring_name_is_not_valid() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.AddDeployment(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(new AddDeploymentRequest() { Name = "@#~invalidring@#~" }); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task update_response_forbidden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithAllPrivilegesForDefaultIdentity() .WithWritePermission(false) .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("product#1") .Build(); await _fixture.Given .AddProduct(product); var request = new UpdateProductRequest() { ProductId = product.Id, Name = "product#2", Description = "description for product#2" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Product.Update()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task importproduct_response_bad_request_if_product_to_import_already_exists() { var permission = Builders.Permission() .WithContributorPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("default") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V5.Product.Import()) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(new ImportProductRequest() { Content = "{\"Name\":\"default\",\"Description\":\"this is default product\",\"Features\":[{\"Name\":\"MatchScore\",\"Description\":\"show the match score on products\",\"Archived\":false,\"FeatureTags\":[],\"FeatureStates\":[],\"Toggles\":[{\"Type\":\"Esquio.Toggles.FromToToggle,Esquio\",\"Parameters\":[{\"Name\":\"From\",\"Value\":\"2020-07-13 09:36:23\",\"DeploymentName\":\"Tests\"},{\"Name\":\"To\",\"Value\":\"2020-07-29 09:36:25\",\"DeploymentName\":\"Tests\"}]}]}],\"Deployments\":[{\"Name\":\"Tests\",\"ByDefault\":true},{\"Name\":\"production\",\"ByDefault\":false}]}" }); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task allow_to_tag_features() { var tag = "tag"; var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle#1") .Build(); feature.Toggles.Add(toggle1); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var request = new AddTagRequest(tag); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Tags.Tag(feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status200OK); }
public async Task update_response_forbidden_if_user_is_not_authorized() { var permission = Builders.Permission() .WithReaderPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var request = new UpdateProductRequest() { Name = "barpdroduct", Description = "description for product#2" }; var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.Update(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PutAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status403Forbidden); }
public async Task not_allow_to_tag_features_when_it_has_been_previously_tagged_with_the_same_tag() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle#1") .Build(); var tag = Builders.Tag() .Build(); var featureTag = Builders.FeatureTag() .WithFeature(feature) .WithTag(tag) .Build(); feature.Toggles.Add(toggle1); feature.FeatureTags.Add(featureTag); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var request = new AddTagRequest(tag.Name); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Tags.Tag(feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(request); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task deletedeployment_response_badrequest_if_ring_is_default() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.DeleteDeployment(product.Name, EsquioConstants.DEFAULT_DEPLOYMENT_NAME)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task allow_to_untag_features() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle#1") .Build(); var tag = Builders.Tag() .Build(); var featureTag = Builders.FeatureTag() .WithFeature(feature) .WithTag(tag) .Build(); feature.Toggles.Add(toggle1); feature.FeatureTags.Add(featureTag); product.Features.Add(feature); await _fixture.Given.AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Tags.Untag(tag.Name, feature.Id)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .DeleteAsync(); response.StatusCode .Should() .Be(StatusCodes.Status204NoContent); }
public async Task adddeployment_response_badrequest_if_ring_name_grether_than_200_characters() { var permission = Builders.Permission() .WithManagementPermission() .Build(); await _fixture.Given .AddPermission(permission); var product = Builders.Product() .WithName("fooproduct") .Build(); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V3.Product.AddDeployment(product.Name)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .PostAsJsonAsync(new AddDeploymentRequest() { Name = new string('c', 201) }); response.StatusCode .Should() .Be(StatusCodes.Status400BadRequest); }
public async Task get_response_not_found_if_toggle_not_exist() { var product = Builders.Product() .WithName("product#1") .Build(); var feature = Builders.Feature() .WithName("feature#1") .Build(); var toggle1 = Builders.Toggle() .WithType("toggle-type-1") .Build(); feature.Toggles .Add(toggle1); product.Features .Add(feature); await _fixture.Given .AddProduct(product); var response = await _fixture.TestServer .CreateRequest(ApiDefinitions.V1.Toggles.Get(toggleId: toggle1.Id * 2)) .WithIdentity(Builders.Identity().WithDefaultClaims().Build()) .GetAsync(); response.StatusCode .Should() .Be(StatusCodes.Status404NotFound); }