Defining Process in a RouterController

 Given a RouterController
 When Process fails
 Should throw exception if checking IsBlogEntry fails 
 Should throw exception if When redirecting to HomePage fails

Test Code

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

        readonly Exception ExpectedException = new Exception();

        void AssertThatProcessThrowsException() {
            try {
                When.Process();
                Assert.Fail(Helper.ShouldHaveThrownException);
            } catch (Exception ActualException) {
                Assert.AreSame(ExpectedException, ActualException);
            }
        }

        [TestMethod]
        public void Should_throw_exception_if_checking_IsBlogEntry_fails() {
            
            Given.IsBlogEntry.WillThrow(ExpectedException);
            AssertThatProcessThrowsException();
        }
        
        [TestMethod]
        public void Should_throw_exception_if_redirecting_to_HomePage_fails() {

            Given.RedirectToHomePage(); WillThrow(ExpectedException);
            AssertThatProcessThrowsException();
        }
    }

Production Code

    public class RouterController {

        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 1:42 PM by mikemps, version 4

Comments

No comments yet.