Пример #1
0
        public void Client_Lists_Include_Correct_Page_Numbers()
        {
            // ARRANGE: if there are 5 clients in the repository...
            // create fake clients to insert to fake db
            Client[] clients = new Client[]
            {
                new Client { FirstName = "FName1" },
                new Client { FirstName = "FName2" },
                new Client { FirstName = "FName3" },
                new Client { FirstName = "FName4" },
                new Client { FirstName = "FName5" }
            };
            // mock db and have it return the fake records
            var mockRepository = new Mock<IClientRepository>();
            mockRepository.Setup(x => x.GetClientsForUser("BenR")).Returns(clients.AsQueryable());
            // make db return fake user
            mockRepository.Setup(x => x.GetUser("BenR")).Returns(new User { UserName = "******" });
            var controller = new ClientsController(mockRepository.Object, UnitTestHelpers.CreateMockLoggedInUser("BenR")) { PageSize = 3 };

            // ACT: ... and the user asks for the second page...
            var result = controller.List(2);

            // ASSERT: they see page links matching the following??
            var viewModel = (ClientsListViewModel)result.ViewData.Model;
            PagingInfo pagingInfo = viewModel.PagingInfo;
            pagingInfo.CurrentPage.ShouldEqual(2);
            pagingInfo.ItemsPerPage.ShouldEqual(3);
            pagingInfo.TotalItems.ShouldEqual(5);
            pagingInfo.TotalPages.ShouldEqual(2);
        }
Пример #2
0
        public void Can_View_A_Single_Page_Of_Clients()
        {
            // ARRANGE: if user is logged in and there are 5 clients in the repository...
            // create fake clients to insert to fake db
            Client[] clients = new Client[]
            {
                new Client { FirstName = "FName1" },
                new Client { FirstName = "FName2" },
                new Client { FirstName = "FName3" },
                new Client { FirstName = "FName4" },
                new Client { FirstName = "FName5" }
            };

            // mock db and have it return the fake records
            var repository = new Mock<IClientRepository>();
            repository.Setup(x => x.GetClientsForUser("TeamFortress2User")).Returns(clients.AsQueryable());
            // make db return fake user
            repository.Setup(x => x.GetUser("TeamFortress2User")).Returns(new User { UserName = "******" });

            // create controller
            var controller = new ClientsController(repository.Object, UnitTestHelpers.CreateMockLoggedInUser("TeamFortress2User"));
            controller.PageSize = 3;

            // ACT: and the user asks for the second page...
            var result = controller.List(2);

            // ASSERT: ...the user sees the last two clients
            var viewModel = (ClientsListViewModel)result.ViewData.Model;
            var displayedClients = viewModel.Clients;
            displayedClients.Count.ShouldEqual(2);
            displayedClients[0].FirstName.ShouldEqual("FName4");
            displayedClients[1].FirstName.ShouldEqual("FName5");
        }