Beispiel #1
0
        public void When_getting_a_product_with_a_valid_id_it_should_return_a_valid_element()
        {
            // Arrange
            var controller      = new ProductsController(_logger, _repository);
            var originalElement = ValidDataHelper.GetValidProductDto(controller);

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

            // Assert
            retrievedElement.ShouldBeEquivalentTo(originalElement);
        }
Beispiel #2
0
        public void When_deleting_a_product_the_query_for_that_id_should_return_a_not_found_code()
        {
            // Arrange
            var controller      = new ProductsController(_logger, _repository);
            var originalElement = ValidDataHelper.GetValidProductDto(controller);

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

            // Asset
            result.Should().BeOfType <NoContentResult>();
            getResult.Should().BeOfType <NotFoundResult>();
        }
Beispiel #3
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);
        }