public ActionResult CreateProfile(ProfileDM profileDM) { if (profileDM.DateOfBirth.Date > DateTime.Now.AddYears(-18).Date || profileDM.DateOfBirth.Date < DateTime.Now.AddYears(-80).Date) { ModelState.AddModelError("DateOfBirth", "Неверная дата"); } if (profileDM.DateOfExpiry.Date < DateTime.Now.Date) { ModelState.AddModelError("DateOfExpiry", "Неверная дата"); } if (profileDM.DateOfIssue.Date > DateTime.Now.Date || profileDM.DateOfIssue.Date < DateTime.Now.AddYears(-50).Date) { ModelState.AddModelError("DateOfIssue", "Неверная дата"); } if (ModelState.IsValid) { ProfileDTO profileDTO = _identityMapperDM.ToProfileDTO.Map <ProfileDM, ProfileDTO>(profileDM); profileDTO.User = new User() { Id = User.Identity.GetUserId() }; _clientService.CreateProfile(profileDTO); _logWriter.CreateLog("Добавил паспортные данные", User.Identity.GetUserId()); return(RedirectToAction("ShowProfile")); } return(View(profileDM)); }
public void CreateProfileRedirectToShowProfile() { var model = new ProfileDM() { DateOfBirth = DateTime.Now.AddYears(-20), DateOfExpiry = DateTime.Now.AddYears(1), DateOfIssue = DateTime.Now.AddYears(-1) }; _mockIdentityMapper.Setup(x => x.ToProfileDTO.Map <ProfileDM, ProfileDTO>(model)) .Returns(new ProfileDTO()); RedirectToRouteResult result = _controller.CreateProfile(model) as RedirectToRouteResult; Assert.AreEqual(result.RouteValues["action"], "ShowProfile"); }