コード例 #1
0
        public async Task EditProductShouldEditProperties()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var product = new Product
            {
                ProductName      = "Test Product",
                ShortDescription = "Test Product",
                WebsitePrice     = 23,
            };

            context.Products.Add(product);
            await context.SaveChangesAsync();

            var mockInventoryService = new Mock <IInventoryService>();
            var service = new ProductsService(context, mockInventoryService.Object);

            var editedProduct = new ProductDetailsInputModel {
                Id = product.Id, ProductName = "Edited", ShortDescription = "Edited", WebsitePrice = 100,
            };
            await service.EditProductAsync <ProductDetailsViewModel, ProductDetailsInputModel>(editedProduct);

            var dbProduct = context.Products.FirstOrDefault();

            Assert.Equal(editedProduct.ProductName, dbProduct.ProductName);
            Assert.Equal(editedProduct.ShortDescription, dbProduct.ShortDescription);
            Assert.Equal(editedProduct.WebsitePrice, dbProduct.WebsitePrice);
        }
コード例 #2
0
        public async Task <IActionResult> ProductDetails(ProductDetailsInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.ProductDetails(input.Id));
            }

            await this.productService.EditProductAsync <ProductDetailsViewModel, ProductDetailsInputModel>(input);

            this.TempData["success"] = true;
            return(this.ProductDetails(input.Id));
        }