public ActionResult ContactUs(ContactUsModel contactUsModel) { if (ModelState.IsValid) { Mapper.CreateMap<ContactUsModel, ContactUsDetailsDto>(); var contactUsDetailsDto = Mapper.Map<ContactUsModel, ContactUsDetailsDto>(contactUsModel); IList<string> errorMessages = new List<string>(); if (!_contactUsService.Insert( contactUsDetailsDto, (CurrentUser != null) ? CurrentUser.UserId : (int?)null, ref errorMessages)) { ModelState.AddModelErrors(errorMessages); } else { return RedirectToAction("ContactUsSuccessful"); } } // Reaching this point means something went wrong. return View(contactUsModel); }
public ActionResult ContactUs() { if (CurrentUser != null) { var contactUsModel = new ContactUsModel { Name = CurrentUser.FullName, EmailAddress = CurrentUser.EmailAddress }; return View(contactUsModel); } return View(); }
public void Basic_ContactUs_Post() { //var mockClaimsPrincipal = new Mock<ClaimsPrincipal>(); //var mockHttpContext = new Mock<HttpContextBase>(); //mockHttpContext.Setup(x => x.User).Returns(mockClaimsPrincipal); var contactUsModel = new ContactUsModel { EmailAddress = string.Empty, Name = string.Empty, Message = string.Empty }; var result = _homeController.ContactUs(contactUsModel) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual(result.ViewName, string.Empty); Assert.False(_homeController.ModelState.IsValid); Assert.AreEqual(_homeController.ModelState[string.Empty].Errors[0].ErrorMessage, "The email address and/or password provided is incorrect."); }