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 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 add_response_badrequest_if_product_does_not_exist()
        {
            var addFlagRequest = new AddFlagRequest()
            {
                Name        = new string('c', 201),
                Description = "description",
                Enabled     = true,
                ProductId   = 1
            };

            var response = await _fixture.TestServer
                           .CreateRequest(ApiDefinitions.V1.Flags.Add())
                           .WithIdentity(Builders.Identity().WithDefaultClaims().Build())
                           .PostAsJsonAsync(addFlagRequest);

            response.StatusCode
            .Should()
            .Be(StatusCodes.Status400BadRequest);
        }
Example #4
0
        public async Task <IActionResult> Add(AddFlagRequest addFlagRequest, CancellationToken cancellationToken = default)
        {
            var flagId = await _mediator.Send(addFlagRequest, cancellationToken);

            return(Created($"api/v1/flags/{flagId}", null));
        }