コード例 #1
0
        public void ShouldListAuthorsWithPagination()
        {
            UsingSession((session) =>
                {
                    var controller = new AuthorsController(new Repository(session));
                    Enumerable.Range(1, 9)
                              .ToList()
                              .ForEach(i => controller.Create(new Author {Name = "Author " + i, Biography = "Biography " + i}));
                });

            UsingSession((session) =>
            {
                WaitForTheLastWrite<Author>(session);
                var controller = new AuthorsController(new Repository(session));
                var viewResult = controller.List(1, 4);
                var authors = (IPagedList<Author>)(viewResult.Model);
                Assert.AreEqual(4, authors.Count);
                Assert.AreEqual(3, authors.PageCount);
            });
        }
コード例 #2
0
        public void ShouldListAuthors()
        {
            var author1 = new Author()
                {
                    Name = "Author1",
                    Biography = "Biography1",
                    PictureUrl = "myPicture1.jpg",
                    CreatedAt = DateTime.UtcNow
                };

            var author2 = new Author()
                {
                    Name = "Author2",
                    Biography = "Biography2",
                    PictureUrl = "myPicture2.jpg",
                    CreatedAt = DateTime.UtcNow.AddDays(-1)
                };

            UsingSession((session) =>
                {
                    var controller = new AuthorsController(new Repository(session));
                    controller.Create(author1);
                    controller.Create(author2);
                });

            UsingSession((session) =>
                {
                    WaitForTheLastWrite<Author>(session);
                    var controller = new AuthorsController(new Repository(session));
                    var viewResult = controller.List();
                    var authors = (IPagedList<Author>)(viewResult.Model);

                    Assert.AreEqual("", viewResult.MasterName);
                    Assert.AreEqual("Authors", viewResult.ViewBag.Title);

                    Assert.AreEqual(2, authors.Count);
                    AuthorsContollerTestHelper.AssertEqual(author1, authors.ElementAt(0));
                    AuthorsContollerTestHelper.AssertEqual(author2, authors.ElementAt(1));
                });
        }