Defining Process in a RouterController

 Given a RouterController
 When Process
 Should Transfer BlogEntries to BlogEntryPage 
 Should Redirect to HomePage by default

Test Code using Static Constructs

    [TestClass]
    public class Given_RouterController_When_Process {

        readonly RouterController Subject = Create.TestObjectFor<RouterController>();

        [TestMethod]
        public void Should_Transfer_BlogEntries_to_BlogEntryPage() {
            
            Given.That(Subject).IsBlogEntry.WillReturn(true);
            Subject.Process();
            Then.Should(Subject).TransferToBlogEntryPage();
        }
        
        [TestMethod]
        public void Should_Redirect_to_HomePage_by_default() {

            Subject.Process();
            Then.Should(Subject).RedirectToHomePage();
        }
    }

Test Code using Extensions Constructs

    [TestClass]
    public class Given_RouterController_When_Process {

        readonly RouterController Subject = Create.TestObjectFor<RouterController>();

        [TestMethod]
        public void Should_Transfer_BlogEntries_to_BlogEntryPage() {
            
            Subject.Given().IsBlogEntry.WillReturn(true);
            Subject.Process();
            Subject.Should().TransferToBlogEntryPage();
        }
        
        [TestMethod]
        public void Should_Redirect_to_HomePage_by_default() {

            Subject.Process();
            Subject.Should().RedirectToHomePage();
        }
    }

Production Code

    public class RouterController : Controller<RouterService, RouterView> {

        public void Process(string request) { 
            if (IsBlogEntry) TransferToBlogEntryPage();
            else RedirectToHomePage();
        }

        public virtual bool IsBlogEntry { 
            get { throw new NotImplementedException(); }
        }

        public virtual void TransferToBlogEntryPage() {}

        public virtual void RedirectToHomePage() {}

    }

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

Comments

No comments yet.