public virtual ActionResult Index(ErrorData error = null)
 {
     if (error == null)
     {
         error = new ErrorData();
     }
     if (String.IsNullOrWhiteSpace(error.ErrorMessage))
     {
         error.ErrorMessage = "An error occurred while processing your request.";
     }
     if (error.ReturnUrl == null || !urlHelper.IsSafe(error.ReturnUrl))
     {
         error.ReturnUrl = urlHelper.Action(MVC.Classic.Index());
     }
     return View(Views.Index, error);
 }
        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.");
            }
        }