public async Task <IActionResult> Add(CreateSectionTypeViewModel pCreateModel) { if (!this.ModelState.IsValid) { pCreateModel.Errors = this.ModelState.Values.SelectMany(val => val.Errors).Select(err => err.ErrorMessage).ToList(); return(View(pCreateModel)); } // map to Dto var lDtoToCreate = Mapping.Mapper.Map <CreateSectionTypeDto>(pCreateModel); await this._referenceServices.CreateSectionType(lDtoToCreate); return(RedirectToAction("Index", new { successMessage = "SectionType successfully created" })); }
public async Task TestAddFailure() { CreateSectionTypeViewModel lCreateSectionTypeViewModel = new CreateSectionTypeViewModel() { Name = "England" }; this.sectionTypeController.ModelState.AddModelError("aa", "error"); IActionResult lResult = await this.sectionTypeController.Add(lCreateSectionTypeViewModel); ViewResult lViewResult = lResult as ViewResult; var lViewModel = lViewResult.Model as CreateSectionTypeViewModel; Assert.AreEqual("England", lViewModel.Name); await this.ReferenceServices.Received(0).CreateSectionType(Arg.Any <CreateSectionTypeDto>()); }
public async Task TestAdd() { this.ReferenceServices.CreateSectionType(Arg.Any <CreateSectionTypeDto>()).Returns(new SectionTypeDto { Id = 50 }); CreateSectionTypeViewModel lCreateSectionTypeViewModel = new CreateSectionTypeViewModel() { Name = "England" }; IActionResult lResult = await this.sectionTypeController.Add(lCreateSectionTypeViewModel); RedirectToActionResult lViewResult = lResult as RedirectToActionResult; Assert.AreEqual("SectionType successfully created", lViewResult.RouteValues["successMessage"]); await this.ReferenceServices.Received(1).CreateSectionType(Arg.Is <CreateSectionTypeDto>(dto => dto.Name == "England")); }