Defining AddComment in a CommentController

 Given a CommentController
 When CreateComment
 Should setup the Comment with the values from the View

Test Code

    [TestClass]
    public class Given_CommentController_When_CreateComment : BehaviorOf<CommentController> {

        [TestMethod]
        public void Should_setup_BlogEntry() {
            var ExpectedCommentBlogEntry = new BlogEntry();
            
            Given.View.BlogEntry = ExpectedCommentBlogEntry;
            When.CreateComment();
            Assert.AreSame(ExpectedCommentBlogEntry, Actual.Comment.BlogEntry);
        }

        [TestMethod]
        public void Should_setup_Content() {
            var ExpectedCommentContent = "comment content";

            Given.View.Content = ExpectedCommentContent;
            When.CreateComment();
            Assert.AreSame(ExpectedCommentContent, Actual.Comment.Content);
        }

        [TestMethod]
        public void Should_setup_Author() {
            var ExpectedCommentAuthor = "comment author";

            Given.View.Author = ExpectedCommentAuthor;
            When.CreateComment();
            Assert.AreSame(ExpectedCommentAuthor, Actual.Comment.Author);
        }
    }

Production Code

    public class CommentController {

        public Comment View { get; set; }
        public Comment Comment { get; set; }

        public void CreateComment() { 
            Comment = Domain.ObjectFactory.NewComment(
                View.BlogEntry, View.Content, View.Author);
        }
    }

    public interface Comment {

        BlogEntry BlogEntry { get; set; }
        string Content { get; set; }
        string Author { get; set; }
    }

    public class BlogEntry { }

Last edited Nov 5, 2008 at 8:20 PM by mikemps, version 3

Comments

No comments yet.