public void CanCreateCommand_From_ProductDTO() { var productDTO = new ProductDTO() { Id = 1, Name = "Test", Description = "TestDescr", CategoryId = 12, Price = 142m }; var actual = EditProductCommand.FromProduct(productDTO); Assert.AreEqual(productDTO.Id, actual.Id); Assert.AreEqual(productDTO.Name, actual.Name); Assert.AreEqual(productDTO.Price, actual.Price); Assert.AreEqual(productDTO.Description, actual.Description); Assert.AreEqual(productDTO.CategoryId, actual.CategoryId); }
public async Task <IActionResult> EditProduct(int id) { var product = await Mediator.Handle(new GetProductByIdQuery() { ProductId = id }); if (product is null) { return(NotFound()); } var categories = await Mediator.Handle(new GetAllCategories()); var model = new EditProductViewModel() { Command = EditProductCommand.FromProduct(product), Categories = categories }; return(View(model)); }