[TestCase("Name", "", "Phone", "Message")] // passing test, no email public void CanAddContacts(string addName, string addEmail, string addPhone, string addMessage) // ----------------------ADD CONTACT { var contactRepo = ContactRepositoryFactory.GetContactRepository(); var addContact = new Contact() { Name = addName, Email = addEmail, Phone = addPhone, Message = addMessage }; Contact returnedContact = contactRepo.AddContact(addContact); if (returnedContact != null) { Assert.AreEqual(4, contactRepo.GetContacts().Count()); Assert.AreEqual(4, contactRepo.GetContacts()[3].ContactID); Assert.AreEqual("Name", contactRepo.GetContacts()[3].Name); Assert.AreEqual("Message", contactRepo.GetContacts()[3].Message); } else { Assert.AreEqual(3, contactRepo.GetContacts().Count()); } }
public ActionResult Contact(Contact addContact) { if (ModelState.IsValid) { ContactRepositoryFactory.GetContactRepository().AddContact(addContact); return(RedirectToAction("Index")); } else { return(View(addContact)); } }
public ActionResult Contact(ContactViewModel contactViewModel) { if (ModelState.IsValid) { var repo = ContactRepositoryFactory.GetContactRepository(); var contact = new Contact() { Name = contactViewModel.Name, Email = contactViewModel.Email, Phone = contactViewModel.Phone, Message = contactViewModel.Message }; repo.AddContact(contact); return(RedirectToAction("Index", "Home")); } else // found errors, so return back with same model object { return(View(contactViewModel)); } }