public async Task EditAsyncShouldEditCostCorrectly() { // Arrange var inputModel = new AddCostEditInputModel { Id = 1, Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, }; var cost = new AdditionalCost { Id = 1, Name = "Print 2", Description = "Drawings Many", PricePerQuantity = 10.50M, Quantity = 20, }; await this.PlanItDbContext.AdditionalCosts.AddAsync(cost); await this.PlanItDbContext.SaveChangesAsync(); // Act var expected = new AdditionalCost { Id = 1, Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, TotalCost = 5.5M * 20, }; var actual = await this.AdditionalCostsService .EditAsync<AddCostEditInputModel>(inputModel); // Assert Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Description, actual.Description); Assert.Equal(expected.PricePerQuantity, actual.PricePerQuantity); Assert.Equal(expected.Quantity, actual.Quantity); Assert.Equal(expected.TotalCost, actual.TotalCost); }
public async Task <IActionResult> Edit(int id, AddCostEditInputModel inputModel) { if (id != inputModel.Id) { return(this.NotFound()); } var cost = await this.additionalCostsService .GetByIdAsync <AddCostViewModel>(inputModel.Id); if (cost == null) { return(this.NotFound()); } if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.additionalCostsService.EditAsync <AddCostEditInputModel>(inputModel); return(this.RedirectToAction(nameof(this.CostsByProject), new { projectId = cost.ProjectId })); }