Defining AddComment in a CommentController

 Given a CommentController
 When adding a Comment
 Should create the Comment
 Should add the Comment to the Repository

Test Code using Static Constructs

    [TestClass]
    public class Given_CommentController_When_AddComment {

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

        [TestInitialize]
        public void Setup() {
        
            Subject.AddComment();
        }

        [TestMethod]
        public void Should_CreateComment() {

            Then.Should(Subject).CreateComment();
        }

        [TestMethod]
        public void Should_AddCommentToRepo() {

            Then.Should(Subject).AddCommentToRepo();
        }        
    }

Test Code using Extensions Constructs

    [TestClass]
    public class Given_CommentController_When_AddComment {

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

        [TestInitialize]
        public void Setup() {
        
            Subject.AddComment();
        }

        [TestMethod]
        public void Should_CreateComment() {

            Subject.Should().CreateComment();
        }

        [TestMethod]
        public void Should_AddCommentToRepo() {

            Subject.Should().AddCommentToRepo();
        }        
    }

Production Code

    public class CommentController {

        public void AddComment() {
            CreateComment();
            AddCommentToRepo();
        }

        public virtual void CreateComment() { }

        public virtual void AddCommentToRepo() { }

    }

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

Comments

No comments yet.