示例#1
0
        public void TestRecentCommentsReturnsPartialView()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            var commentHistory = new List <CommentHistory>();
            for (int i = 0; i < 10; i++)
            {
                commentHistory.Add(CreateValidEntities.CommentHistory(i + 1));
                commentHistory[i].AccessUserId = "Me";
                commentHistory[i].DateCreated  = DateTime.UtcNow.ToPacificTime().Date.AddDays(i);
            }
            commentHistory[8].AccessUserId = "NotMe";

            new FakeCommentHistory(0, QueryRepositoryFactory.CommentHistoryRepository, commentHistory, false);

            #endregion Arrange

            #region Act
            var results = Controller.RecentComments()
                          .AssertPartialViewRendered()
                          .WithViewData <IList <CommentHistory> >();
            #endregion Act

            #region Assert
            Assert.IsNotNull(results);
            Assert.AreEqual(5, results.Count());
            Assert.AreEqual("Comment10", results[0].Comment);
            Assert.AreEqual("Comment8", results[1].Comment);
            Assert.AreEqual("Comment7", results[2].Comment);
            Assert.AreEqual("Comment6", results[3].Comment);
            Assert.AreEqual("Comment5", results[4].Comment);
            #endregion Assert
        }