public void FindCommentedByUser_Should_Return_Correct_Result()
        {
            var story1 = CreateStory();
            var story2 = CreateStory();
            var story3 = CreateStory();

            Stories.AddRange(new[] { story1 as Story, story2 as Story, story3 as Story });

            var user = _factory.CreateUser("commenter", "*****@*****.**", "xxxxxx");

            Stories.ForEach(s => Comments.Add(new StoryComment {
                User = (User)user, Story = s, IPAddress = "192.168.0.1", CreatedAt = SystemTime.Now().AddDays(-3), HtmlBody = "<p>This is a comment</p>", TextBody = "This is a comment."
            }));

            var pagedResult = _storyRepository.FindCommentedByUser(user.Id, 0, 10);

            Assert.Equal(3, pagedResult.Result.Count);
            Assert.Equal(3, pagedResult.Total);
        }
Пример #2
0
        public void FindCommentedByUser_Should_Return_Correct_Result()
        {
            using (BeginTransaction())
            {
                GenerateStories(true, false, true);

                _database.SubmitChanges();
                var userName = CreateNewUser().UserName;
                var stories  = _database.StoryDataSource.Where(s => s.User.UserName == userName);

                var newUser     = (User)_domainFactory.CreateUser("commentUser", "*****@*****.**", "Pa$$w0rd");
                var anotherUser = (User)_domainFactory.CreateUser("anothercommentUser", "*****@*****.**", "Pa$$w0rd");
                var rnd         = new Random();
                stories.ForEach(s => s.StoryCommentsInternal.Add((StoryComment)_domainFactory.CreateComment(s, "content", SystemTime.Now().AddDays(rnd.Next(-10, -1)), newUser, "192.168.0.1")));
                stories.ForEach(s => s.StoryCommentsInternal.Add((StoryComment)_domainFactory.CreateComment(s, "content2", SystemTime.Now().AddDays(rnd.Next(-10, -1)), newUser, "192.168.0.4")));
                stories.ForEach(s => s.StoryCommentsInternal.Add((StoryComment)_domainFactory.CreateComment(s, "content2", SystemTime.Now().AddDays(rnd.Next(-10, -1)), anotherUser, "192.168.0.4")));
                _database.SubmitChanges();

                var pagedResult = _storyRepository.FindCommentedByUser(newUser.Id, 0, 5);

                Assert.Equal(5, pagedResult.Result.Count);
                Assert.Equal(10, pagedResult.Total);
            }
        }