public void Index_Returns200AndTheCorrectView()
        {
            var controller = new HomeController();
            var actionResult = (ViewResult)controller.Index();

            Assert.That(actionResult, Is.Not.Null);
            Assert.That(actionResult.ViewName, Is.EqualTo("Index"));
        }
        public void TalkNotFound_Returns200AndModelWithErrorMessage()
        {
            var controller = new HomeController();
            var actionResult = (ViewResult)controller.TalkNotFound("12345");
            var modelResult = (GetFeedbackFormViewModel)actionResult.Model;

            Assert.That(actionResult, Is.Not.Null);
            Assert.That(actionResult.ViewName, Is.EqualTo("Index"));
            Assert.That(modelResult.EasyAccessKey, Is.EqualTo("12345"));
            Assert.That(modelResult.EasyAccessKeyErrorMessage, Is.EqualTo("Talk not found"));
        }
        private static IList<ValidationResult> CheckForValidationErrors(HomeController controller, GetFeedbackFormViewModel model)
        {
            var validationErrors = ViewModelValidation.Validate(model);

            if (validationErrors.Count > 0)
            {
                controller.ViewData.ModelState.AddModelError(nameof(model.EasyAccessKey), validationErrors[0].ErrorMessage);
            }

            return validationErrors;
        }
        public void ThenItRedirectsForValidEasyAccessKeyIds(string easyAccessKey)
        {
            var model = new GetFeedbackFormViewModel() { EasyAccessKey = easyAccessKey };

            var controller = new HomeController();
            var actionResult = (RedirectToActionResult)controller.CheckEasyAccessKey(model);

            Assert.That(actionResult, Is.Not.Null);
            Assert.That(actionResult.ActionName, Is.EqualTo("Index"));
            Assert.That(actionResult.ControllerName, Is.EqualTo("feedback"));
            Assert.That(actionResult.RouteValues["easyAccessKey"], Is.EqualTo(easyAccessKey));
        }
        public void OtherwiseItHandlesInvalidValues(string easyAccessKey, string expectedMessage)
        {
            var model = new GetFeedbackFormViewModel() { EasyAccessKey = easyAccessKey };
            var controller = new HomeController();

            var validationErrors = CheckForValidationErrors(controller, model);

            var actionResult = (ViewResult)controller.CheckEasyAccessKey(model);
            var modelState = controller.ModelState;

            Assert.That(validationErrors.Count, Is.EqualTo(1));
            Assert.That(validationErrors[0].ErrorMessage, Is.EqualTo(expectedMessage));

            Assert.That(actionResult.ViewName, Is.EqualTo("Index"));
        }