protected override void InitializeMockData() { desicion = new Desicion { Id = 1, Name = "Rejected" }; _mockControl = new QualityControl(_user) { Id = 1, Name = "High tolerances", Status = QualityControlStatus.Open, Defect = new Defect { Name = "DI110", Description = "Out of tolerances" }, Product = new Product { Name = "Blade", Description = "blade fb1" } }; controls = new List <QualityControl> { _mockControl, new QualityControl { Name = "Documental deviation", Description = "Prox p40", Product = new Product { Name = "CFM Fan Blade" }, Defect = new Defect { Name = "DEQ" }, Inspection = new Inspection { Desicion = desicion } } }; viewModel = new QualityControlViewModel { Name = "High tolerances", Description = "Dimensions DI310 and C220 out of upper tolerance.", Serial = "SN18972123", Defect = 1, Product = 1 }; detailViewModel = new QualityControlDetailViewModel { Id = 1, Name = "No-conforming dimensions", Description = "Dimension DI110 is out of upper tolerance." }; expectedRedirectValues = new RouteValueDictionary { { "action", "Index" }, { "controller", "QualityControl" } }; }
public async Task Update_ExistingQualityControl() { // Arrange var dto = new QualityControlDetailViewModel { Id = 1, Name = "No-conforming dimensions", Description = "Dimension DI110 is out of upper tolerance." }; // Act var result = await _controller.UpdateControl(dto) as ActionResult; // Assert var redirectResult = result.As <RedirectToRouteResult>(); redirectResult.RouteValues.Should().Equals(expectedRedirectValues); }
public async Task <ActionResult> UpdateControl(QualityControlDetailViewModel model) { var control = await _unitOfWork.QualityControlRepository.FindByIdAsync(model.Id); if (control == null) { return(HttpNotFound()); } var user = await _unitOfWork.UserRepository.FindByIdAsync(GetUserId()); try { control.Update(user, model.Name, model.Description); await _unitOfWork.SaveChangesAsync(); } catch (Exception ex) { await LogExceptionAsync(ex); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message)); } return(RedirectToAction("Index", "QualityControl")); }