Defining RedirectToHomePage in a RouterController

 Given a RouterController
 When RedirectToHomePage 
 Should Redirect the Response to HomePageUrl
 Should not Redirect if the OriginUrl was HomePageUrl

Test Code

    [TestClass]
    public class Given_RouterController : BehaviorOf<RouterController> {

        [TestMethod]
        public void When_RedirectToHomePage_Should_redirect_Response_to_HomePageUrl() {
            
            Given.OriginUrl = "unknown page";
            When.RedirectToHomePage();
            Should.Response.Redirect(Settings.HomePageUrl);
        }

        [TestMethod]
        public void When_RedirectToHomePage_Should_not_Redirect_if_OriginUrl_is_HomePage() {

            Given.OriginUrl = Settings.HomePageUrl;
            When.RedirectToHomePage();
            ShouldNot.Response.Redirect(Settings.HomePageUrl);
        }
    }

Production Code

    public class RouterController {

        public Response Response { get; set; }
        public string OriginUrl { get; set; }

        public void RedirectToHomePage() {
            if (OriginUrl.Equals(Settings.HomePageUrl)) return;
            Response.Redirect(Settings.HomePageUrl);
        }
    }

    public interface Response {

        void Redirect(string url);
    }
  }

Last edited Nov 5, 2008 at 5:43 AM by mikemps, version 3

Comments

No comments yet.