コード例 #1
0
        public async Task AddNewProductFromInputModelTests()
        {
            //Arrange
            var mapperConfig = new MapperConfiguration(x => x.AddProfile(new MappingProfile()));
            var mapper       = mapperConfig.CreateMapper();

            var productService = new ProductService(this.context, mapper);

            var firstProduct = new AddNewProductBindingModel
            {
                CategoryIdString = "CategoryId",
                Description      = "Some Description",
                Name             = "FirstProductName",
                Price            = 12.2m,
                ProductUrl       = "URL"
            };

            var secondProduct = new AddNewProductBindingModel
            {
                CategoryIdString = "CategoryId",
                Description      = "Some Description",
                Name             = "SecondProductName",
                Price            = 22.2m,
                ProductUrl       = "URL"
            };

            //Act
            Assert.Equal(0, this.context.Products.Count());

            await productService.AddNewProductFromInputModel(firstProduct);

            Assert.Equal(1, this.context.Products.Count());

            Assert.Equal("FirstProductName", this.context.Products.First().Name);

            await productService.AddNewProductFromInputModel(secondProduct);

            //Assert
            Assert.Equal(2, this.context.Products.Count());
        }