コード例 #1
0
        public void When_getting_a_product_category_with_a_valid_id_it_should_return_a_valid_element()
        {
            // Arrange
            var controller      = new ProductCategoriesController(_logger, _repository);
            var originalElement = ValidDataHelper.GetValidProductCategoryDto(controller);

            // Act
            var result           = controller.GetProductCategory(originalElement.Id);
            var retrievedElement = result.ValidateResponseAndCastTo <ProductCategoryDto, OkObjectResult>((int)HttpStatusCodes.Ok);

            // Assert
            retrievedElement.ShouldBeEquivalentTo(originalElement);
        }
コード例 #2
0
        public void When_deleting_a_product_category_the_query_for_that_id_should_return_a_not_found_code()
        {
            // Arrange
            var controller      = new ProductCategoriesController(_logger, _repository);
            var originalElement = ValidDataHelper.GetValidProductCategoryDto(controller);

            // Act
            var result    = controller.Delete(originalElement.Id);
            var getResult = controller.GetProductCategory(originalElement.Id);

            // Asset
            result.Should().BeOfType <NoContentResult>();
            getResult.Should().BeOfType <NotFoundResult>();
        }
コード例 #3
0
        public void When_adding_a_new_valid_product_the_new_element_should_be_returned_with_valid_values()
        {
            // Arrange
            var controller         = new ProductsController(_logger, _repository);
            var categoryController = new ProductCategoriesController(_categoryLogger, _productCategoryRepository);
            var category           = ValidDataHelper.GetValidProductCategoryDto(categoryController);
            var product            = A.New <ProductForPostDto>();

            product.ProductCategoryId = category.Id;

            // Act
            var result           = controller.Add(product);
            var retrievedElement = result.ValidateResponseAndCastTo <ProductDto, CreatedAtRouteResult>
                                       ((int)HttpStatusCodes.Created);

            retrievedElement.Name.Should().Be(product.Name);
            retrievedElement.Id.Should().NotBe(0);
        }
コード例 #4
0
        public void When_updating_a_product_the_query_for_that_id_should_return_the_updated_element()
        {
            // Arrange
            var controller         = new ProductsController(_logger, _repository);
            var originalElement    = ValidDataHelper.GetValidProductDto(controller);
            var categoryController = new ProductCategoriesController(_categoryLogger, _productCategoryRepository);
            var category           = ValidDataHelper.GetValidProductCategoryDto(categoryController, false);
            var updatedValue       = A.New <ProductForPostDto>();

            updatedValue.ProductCategoryId = category.Id;
            AutoMapper.Mapper.Map(updatedValue, originalElement);

            // Act
            var result         = controller.Update(originalElement.Id, updatedValue);
            var getResult      = controller.GetProduct(originalElement.Id);
            var retrievedValue = getResult.ValidateResponseAndCastTo <ProductDto, OkObjectResult>
                                     ((int)HttpStatusCodes.Ok);

            // Asset
            result.Should().BeOfType <NoContentResult>();
            retrievedValue.ShouldBeEquivalentTo(originalElement);
        }
コード例 #5
0
        public void When_updating_a_product_category_the_query_for_that_id_should_return_the_updated_element()
        {
            // Arrange
            var controller      = new ProductCategoriesController(_logger, _repository);
            var originalElement = ValidDataHelper.GetValidProductCategoryDto(controller);

            originalElement.Name = $"UpdatedValue for Id={originalElement.Id}";
            var updatedValue = new ProductCategoryForPostDto()
            {
                Name = originalElement.Name
            };

            // Act
            var result         = controller.Update(originalElement.Id, updatedValue);
            var getResult      = controller.GetProductCategory(originalElement.Id);
            var retrievedValue = getResult.ValidateResponseAndCastTo <ProductCategoryDto, OkObjectResult>
                                     ((int)HttpStatusCodes.Ok);

            // Asset
            result.Should().BeOfType <NoContentResult>();
            retrievedValue.ShouldBeEquivalentTo(originalElement);
        }