示例#1
0
        public void TestComputeTagsWithFault()
        {
            // Create few Post to enter into the database.
            var post1 = new Post()
            {
                Title    = "My First Post",
                Body     = "This isn't a very long post.",
                Tags     = new List <string>(),
                Comments = new List <Comment>
                {
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 1),
                          Email      = "*****@*****.**",
                          Body       = "This article is too short!"
                      } },
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 2),
                          Email      = "*****@*****.**",
                          Body       = "I agree with Jake."
                      } }
                }
            };

            var post2 = new Post()
            {
                Title    = "My Second Post",
                Body     = "This isn't a very long post either.",
                Tags     = new List <string>(),
                Comments = new List <Comment>
                {
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 3),
                          Email      = "*****@*****.**",
                          Body       = "Why are you wasting your time!"
                      } },
                }
            };

            // Insert the posts into the DB
            PostAccess.CreatePost(post1);
            PostAccess.CreatePost(post2);

            // Compute tags for posts
            using (new FaultInjection.FaultInjection(new RandomlyFaultQueryAndUpdatesTestScenario(), this))
            {
                PostAccess.ComputeTags(new[] { post1.Title });
            }

            // Get the post
            var postsWithTag = PostAccess.GetPosts();

            // Verify the acceptance criteria
            Assert.AreEqual(2, postsWithTag.Count());
            Assert.IsTrue(postsWithTag.First(p => p.Title == post1.Title).Tags.Count > 0);
            Assert.IsTrue(postsWithTag.First(p => p.Title == post2.Title).Tags.Count == 0);
        }
示例#2
0
        public void TestPostFunctionality()
        {
            // Create few Post to enter into the database.
            const string title = "My First Post";
            var          post1 = new Post()
            {
                Title    = title,
                Body     = "This isn't a very long post.",
                Tags     = new List <string>(),
                Comments = new List <Comment>
                {
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 1),
                          Email      = "*****@*****.**",
                          Body       = "This article is too short!"
                      } },
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 2),
                          Email      = "*****@*****.**",
                          Body       = "I agree with Jake."
                      } }
                }
            };

            var post2 = new Post()
            {
                Title    = "My Second Post",
                Body     = "This isn't a very long post either.",
                Tags     = new List <string>(),
                Comments = new List <Comment>
                {
                    { new Comment()
                      {
                          TimePosted = new DateTime(2013, 1, 3),
                          Email      = "*****@*****.**",
                          Body       = "Why are you wasting your time!"
                      } },
                }
            };

            // Insert the posts into the DB
            PostAccess.CreatePost(post1);
            PostAccess.CreatePost(post2);

            // Get a post
            var posts = PostAccess.FindPostWithCommentsBy("sara");

            // Verify the acceptance criteria
            Assert.AreEqual(1, posts.Count());
            Assert.AreEqual(title, posts.First());

            // Compute tags for posts
            PostAccess.ComputeTags(new[] { post1.Title });

            // Get the post
            var postsWithTag = PostAccess.GetPosts();

            // Verify the acceptance criteria
            Assert.AreEqual(2, postsWithTag.Count());
            Assert.IsTrue(postsWithTag.First(p => p.Title == post1.Title).Tags.Count > 0);
            Assert.IsTrue(postsWithTag.First(p => p.Title == post2.Title).Tags.Count == 0);
        }