Defining RedirectToHomePage in a RouterController

 Given a RouterController
 When RedirectToHomePage 
 Should Redirect the Response to HomePageUrl

Test Code using Static Constructs

    [TestClass]
    public class Given_RouterController {

        RouterController Subject;

        readonly Response Response = Create.TestObjectFor<Response>();

        [TestInitialize]
        public void Setup() {
        
            Subject = Create.TestObjectFor<RouterController>(Response);
        }

        [TestMethod]
        public void When_RedirectToHomePage_Should_Redirect_the_Response_to_HomePageUrl() {

            Subject.RedirectToHomePage();
            Then.Should(Response).Redirect(Settings.HomePageUrl);
        }
    }

Test Code using Extensions Constructs

    [TestClass]
    public class Given_RouterController {

        RouterController Subject;

        readonly Response Response = Create.TestObjectFor<Response>();

        [TestInitialize]
        public void Setup() {
        
            Subject = Create.TestObjectFor<RouterController>(Response);
        }

        [TestMethod]
        public void When_RedirectToHomePage_Should_Redirect_the_Response_to_HomePageUrl() {

            Subject.RedirectToHomePage();
            Response.Should().Redirect(Settings.HomePageUrl);
        }
    }

Production Code

    public class RouterController {

        Response Response;

        public RouterController(Response Response) {
            this.Response = Response;
        }

        public void RedirectToHomePage() {
            Response.Redirect(Settings.HomePageUrl);
        }
    }

    public interface Response {

        void Redirect(string url);
    }

Last edited Nov 5, 2008 at 8:20 AM by mikemps, version 1

Comments

No comments yet.