Exemplo n.º 1
0
        public void When_adding_a_product_category_as_a_null_value_it_should_return_a_bad_request_code()
        {
            // Arrange
            var controller = new ProductCategoriesController(null, null);

            // Act
            var result = controller.Add(null);

            // Assert
            result.Should().BeOfType <BadRequestResult>();
        }
Exemplo n.º 2
0
        public void When_adding_a_product_category_the_model_state_should_be_validated()
        {
            // Arrange
            var controller = new ProductCategoriesController(null, null);

            // Act
            controller.ModelState.AddModelError("", "Error");
            var result = controller.Add(new ProductCategoryForPostDto());

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();
        }
        public void When_adding_a_new_valid_product_category_the_new_element_should_be_returned_with_valid_values()
        {
            // Arrange
            var controller = new ProductCategoriesController(_logger, _repository);

            // Act
            var productCategory  = A.New <ProductCategoryForPostDto>();
            var result           = controller.Add(productCategory);
            var retrievedElement = result.ValidateResponseAndCastTo <ProductCategoryDto, CreatedAtRouteResult>
                                       ((int)HttpStatusCodes.Created);

            retrievedElement.Name.Should().Be(productCategory.Name);
            retrievedElement.Id.Should().NotBe(0);
        }