示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        public ActionResult Contact(Contact contact)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    MessagingService.Contact = contact;
                    MessagingService.Message();

                    RedirectToAction("ContactConfirmed");
                }
                catch (Exception)
                {
                    RedirectToAction("ContactFailed");
                }
            }
            return View("ContactConfirmed");
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }