Exemplo n.º 1
0
        public void AddNewCommentToPostTest_TestsThatANewPosttIsSavedToTheDatbaseCorrectly_VerifiesByRetrievingSavedObject()
        {
            IPostRepository postRepository = _kernel.Get <IPostRepository>();
            string          title          = "Post # 1";
            string          description    = "Description of Post # 1";
            string          category       = "Category of Post # 1";
            string          email          = "*****@*****.**";
            Post            post           = new Post(title, description, category, email);

            postRepository.Add(post);
            var retrievedPost = postRepository.GetById(post.Id);

            Assert.NotNull(retrievedPost);
            Assert.AreEqual(title, retrievedPost.Title);
            Assert.AreEqual(description, retrievedPost.Description);
            Assert.AreEqual(category, retrievedPost.Category);

            // Now add a new comment
            var authorId = "GandalfTheWhite";
            var text     = "I have returned to finish the job";

            post.AddNewComment(authorId, text);
            postRepository.Update(post);
            retrievedPost = postRepository.GetById(post.Id);
            Assert.NotNull(retrievedPost);
            Assert.AreEqual(1, retrievedPost.Comments.Count);
            Assert.AreEqual(authorId, retrievedPost.Comments[0].AuthorEmail);
            Assert.AreEqual(text, retrievedPost.Comments[0].Text);
        }