public void UpdateHappyPathTest() { //arrange _mockContactsService = new Mock <IContactsService>(); _mockContactsService.Setup(r => r.Update(It.IsAny <ContactRequestDTO>(), It.IsAny <int>())).Returns(true); _mockContactsService.Setup(r => r.FindOne(It.IsAny <int>())).Returns(contactResponseDTO); var controller = new ContactsController(_mockContactsService.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = controller.Update(contactRequest, 1); //assert Assert.IsNotNull(actual); Assert.AreEqual(contactResponseDTO.name.first, actual.Value.name.first); _mockContactsService.Verify(mock => mock.Update(It.IsAny <ContactRequestDTO>(), It.IsAny <int>()), Times.Once()); _mockContactsService.Verify(mock => mock.FindOne(It.IsAny <int>()), Times.Once()); }
public Kobelco.ContactRequest SaveContactUsRequest(ContactRequestDTO dto) { using (var c = new DataConnection()) { var entity = c.CreateNew <Kobelco.ContactRequest>(); entity.Id = Guid.NewGuid(); entity.DateSubmitted = DateTime.Now; entity.FirstName = dto.FirstName; entity.LastName = dto.LastName; entity.Email = dto.Email; entity.Phone = dto.Phone; entity.Company = dto.Company; entity.Address = dto.Address; entity.City = dto.City; entity.State = dto.State; entity.Zip = dto.Zip; entity.InquiryType = dto.InquiryType; entity.Product = dto.Product; entity.SerialNumber = dto.SerialNumber; entity.Message = dto.Comments; c.Add(entity); return(entity); } }
public void InsertBadRequestTest() { //arrange _mockContactsService = new Mock <IContactsService>(); var controller = new ContactsController(_mockContactsService.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = controller.Insert(contactRequest); //assert var result = actual.Result as BadRequestObjectResult; Assert.IsNotNull(actual); Assert.AreEqual("Request Body Malformed", result.Value); }
private string FormatMessageBody(ContactRequestDTO entity) { var template = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplates/ContactUsTemplate.html")); var result = Engine.Razor.RunCompile(template, "ContactRequestSubmit", entity.GetType(), entity); return(result); }
public ContactsEntity convertRequestToEntity(ContactRequestDTO contact) { List <PhoneEntity> phones = new List <PhoneEntity>(); foreach (ContactPhoneDTO phoneDTO in contact.phone) { PhoneEntity phoneEntity = new PhoneEntity { type = phoneDTO.type, number = phoneDTO.number }; phones.Add(phoneEntity); } ContactsEntity contactEntity = new ContactsEntity { first = contact.name.first, middle = contact.name.middle, last = contact.name.last, state = contact.address.state, street = contact.address.street, city = contact.address.city, zip = contact.address.zip, phones = phones, email = contact.email }; return(contactEntity); }
public ActionResult <ContactResponseDTO> Update(ContactRequestDTO dto, int id) { var result = _contactsService.Update(dto, id); if (result) { return(_contactsService.FindOne(id)); } else { return(NotFound("Contact Not Found for ID: " + id)); } }
public ActionResult <ContactResponseDTO> Insert(ContactRequestDTO dto) { var contactResponseDTO = _contactsService.Insert(dto); if (contactResponseDTO != null) { return(contactResponseDTO); } else { return(BadRequest("Request Body Malformed")); } }
public bool Update(ContactRequestDTO dto, int id) { var foundRecord = _contactsRepo.FindOne(id); if (foundRecord != null) { var entityToUpdate = _contactsMapper.convertRequestToEntity(dto); entityToUpdate.Id = id; return(_contactsRepo.Update(entityToUpdate)); } return(false); }
public Kobelco.ContactRequest PostRequest(ContactRequestDTO dto) { CaptchaUtility captchaUtility = new CaptchaUtility(); string recaptchaSecret = ConfigurationManager.AppSettings["recaptchaSecretKey"]; captchaUtility.ValidateCaptcha(dto.CaptchaResponse, recaptchaSecret); ContactRequestDataLogic dataLogic = new ContactRequestDataLogic(); Kobelco.ContactRequest entity = dataLogic.SaveContactUsRequest(dto); dataLogic.SendNotificationEmail(dto); return(entity); }
public ContactResponseDTO Insert(ContactRequestDTO contact) { //TODO need to rethink for bad request submission - //is it even possible to send a bad request currently? (no integer id) ContactsEntity contactsEntity = _contactsMapper.convertRequestToEntity(contact); var id = _contactsRepo.Insert(contactsEntity); var foundInsert = _contactsRepo.FindOne(id); ContactResponseDTO contactResponseDTO = _contactsMapper.convertEntityToDTO(foundInsert); return(contactResponseDTO); }
public void SendNotificationEmail(ContactRequestDTO entity) { string fromEmail = ConfigurationManager.AppSettings["MailFromAddress"].ToString(); string toEmail = ConfigurationManager.AppSettings["ContactUsToAddress"].ToString(); string subject = "New Contact Us Submission"; string messageBody = FormatMessageBody(entity); try { MailUtility mail = new MailUtility(); mail.SendContactRequestEmail(fromEmail, toEmail, subject, messageBody); } catch (Exception ex) { Composite.Core.Log.LogError("Error sending notification email. re: " + entity.Email, ex); } }
public void UpdateNotFoundTest() { //arrange var service = new ContactsService(_mockContactsRepo.Object, _mockContactsMapper.Object); _mockContactsRepo.Setup(r => r.FindOne(It.IsAny <int>())); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = service.Update(contactRequest, 1); //assert _mockContactsRepo.Verify(mock => mock.Update(It.IsAny <ContactsEntity>()), Times.Never()); Assert.IsFalse(actual); }
public void UpdateNotFoundTest() { //arrange _mockContactsService = new Mock <IContactsService>(); var controller = new ContactsController(_mockContactsService.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = controller.Update(contactRequest, 1); //assert var result = actual.Result as NotFoundObjectResult; Assert.AreEqual("Contact Not Found for ID: 1", result.Value); }
public void convertRequestToEntityHappyPathTest() { //arrange var mapper = new ContactsMapper(); ContactRequestDTO request = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = mapper.convertRequestToEntity(request); //assert Assert.AreEqual(contactsEntity.first, actual.first); Assert.AreEqual(contactsEntity.middle, actual.middle); Assert.AreEqual(contactsEntity.last, actual.last); Assert.AreEqual(contactsEntity.email, actual.email); }
public void InsertHappyPathTest() { //arrange _mockContactsMapper.Setup(r => r.convertRequestToEntity(It.IsAny <ContactRequestDTO>())).Returns(contactsEntity); _mockContactsRepo.Setup(r => r.Insert(It.IsAny <ContactsEntity>())).Returns(1); _mockContactsMapper.Setup(r => r.convertEntityToDTO(It.IsAny <ContactsEntity>())).Returns(contactResponseDTO); var service = new ContactsService(_mockContactsRepo.Object, _mockContactsMapper.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = service.Insert(contactRequest); //assert Assert.IsNotNull(actual); Assert.AreEqual(contactResponseDTO, actual); }
public void UpdateHappyPathTest() { //arrange _mockContactsRepo.Setup(r => r.FindOne(It.IsAny <int>())).Returns(contactsEntity); _mockContactsRepo.Setup(r => r.Update(It.IsAny <ContactsEntity>())).Returns(true); var service = new ContactsService(_mockContactsRepo.Object, _mockContactsMapper.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = service.Update(contactRequest, 1); //assert _mockContactsRepo.Verify(mock => mock.Update(contactsEntity), Times.Once()); Assert.IsTrue(actual); }
public void InsertHappyPathTest() { //arrange _mockContactsService = new Mock <IContactsService>(); _mockContactsService.Setup(r => r.Insert(It.IsAny <ContactRequestDTO>())).Returns(contactResponseDTO); var controller = new ContactsController(_mockContactsService.Object); ContactRequestDTO contactRequest = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = controller.Insert(contactRequest); //assert Assert.IsNotNull(actual); Assert.AreEqual(contactResponseDTO, actual.Value); }