public void ShouldDisplayDefaultErrorMessageIfErrorNotProvided()
        {
            IUrlHelper helper = Substitute.For<IUrlHelper>();
            string returnUrl = "/return/url";
            helper.Action(Arg.Any<ActionResult>()).Returns(returnUrl);
            using (ErrorController controller = new ErrorController(helper))
            {
                ActionResult result = controller.Index();

                ErrorData model = ActionResultHelper.AssertViewWithModel<ErrorData>(result, controller.Views.Index);

                Assert.AreEqual("An error occurred while processing your request.", model.ErrorMessage, "The wrong error message was set.");
                Assert.AreEqual(returnUrl, model.ReturnUrl, "The wrong return URL was set.");
            }
        }
        public void ShouldChangeReturnUrlIfNotSafe()
        {
            IUrlHelper helper = Substitute.For<IUrlHelper>();
            helper.IsSafe(Arg.Any<string>()).Returns(false);
            string returnUrl = "/return/url";
            helper.Action(Arg.Any<ActionResult>()).Returns(returnUrl);
            using (ErrorController controller = new ErrorController(helper))
            {
                ErrorData error = new ErrorData()
                {
                    ErrorMessage = "Custom error message",
                    ReturnUrl = @"http://www.google.com",
                };
                ActionResult result = controller.Index(error);

                ErrorData model = ActionResultHelper.AssertViewWithModel<ErrorData>(result, controller.Views.Index);

                Assert.AreEqual(error.ErrorMessage, model.ErrorMessage, "The wrong error message was set.");
                Assert.AreEqual(returnUrl, model.ReturnUrl, "The wrong return URL was set.");
            }
        }
        public void ShouldUseGivenErrorMessageAndReturnUrlIfProvided()
        {
            IUrlHelper helper = Substitute.For<IUrlHelper>();
            helper.IsSafe(Arg.Any<String>()).Returns(true);
            using (ErrorController controller = new ErrorController(helper))
            {
                ErrorData error = new ErrorData()
                {
                    ErrorMessage = "Custom error message",
                    ReturnUrl = "/return/url",
                };
                ActionResult result = controller.Index(error);

                ErrorData model = ActionResultHelper.AssertViewWithModel<ErrorData>(result, controller.Views.Index);

                Assert.AreEqual(error.ErrorMessage, model.ErrorMessage, "The wrong error message was set.");
                Assert.AreEqual(error.ReturnUrl, model.ReturnUrl, "The wrong return URL was set.");
            }
        }