public void Email_FailModelValidationIfEmailIsMissing()
        {
            var sut = new Contact { Name = NameValue, Subject = SubjectValue, Email = null, Message = MessageValue };

            int errorCount = Model.Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
        public void Email_GenerateTheCorrectErrorMessageIfEmailIsMissing()
        {
            var sut = new Contact { Name = NameValue, Subject = SubjectValue, Email = null, Message = MessageValue };

            IList<ValidationResult> result = Model.Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Email is required", errorMessage);
        }
        public void Message_ErrorMessageDisplayedIfCharsOver500()
        {
            var chars501 = new string('a', 501);

            var sut = new Contact { Name = NameValue, Subject = SubjectValue, Email = EmailValue, Message = chars501 };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Max of 500 characters allowed", errorMessage);
        }
        public ActionResult Contact(Contact contact)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    MessagingService.Contact = contact;
                    MessagingService.Message();

                    RedirectToAction("ContactConfirmed");
                }
                catch (Exception)
                {
                    RedirectToAction("ContactFailed");
                }
            }
            return View("ContactConfirmed");
        }
        public void Message_FailModelValidationIfMessageIsAnEmptyString()
        {
            var sut = new Contact { Name = NameValue, Subject = SubjectValue, Email = EmailValue, Message = string.Empty };

            int errorCount = Model.Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
        public void Subject_GenerateTheCorrectErrorMessageIfSubjectIsAnEmptyString()
        {
            var sut = new Contact { Name = NameValue, Subject = string.Empty, Email = EmailValue, Message = MessageValue };

            IList<ValidationResult> result = Model.Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Subject is required", errorMessage);
        }