Example #1
0
        public void Can_Filter_Clients()
        {
            // Arrange
             // - create the mock repository
             Mock<IClientRepository> mock = new Mock<IClientRepository>();
             mock.Setup(m => m.Clients).Returns(new Client[] {
            new Client {ClientId = 1, ContractNumber = "C1", Address = "A1"},
            new Client {ClientId = 2, ContractNumber = "C2", Address = "A2"},
            new Client {ClientId = 3, ContractNumber = "C3", Address = "A3"},
            new Client {ClientId = 4, ContractNumber = "C4", Address = "A2"},
            new Client {ClientId = 5, ContractNumber = "C5", Address = "A1"}
            }.AsQueryable());

             // Arrange - create a controller and make the page size 3 items
             ClientController controller = new ClientController(mock.Object);
             controller.PageSize = 3;

             // Action
             Client[] result = ((ClientsListViewModel)controller.List("A2", 1).Model)
               .Clients.ToArray();

             // Assert
             Assert.AreEqual(result.Length, 2);
             Assert.IsTrue(result[0].ContractNumber == "C2" && result[0].Address == "A2");
             Assert.IsTrue(result[1].ContractNumber == "C4" && result[1].Address == "A2");
        }
Example #2
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
             Mock<IClientRepository> mock = new Mock<IClientRepository>();
             mock.Setup(m => m.Clients).Returns(new Client[] {
            new Client {ClientId = 1, ContractNumber = "C1"},
            new Client {ClientId = 2, ContractNumber = "C2"},
            new Client {ClientId = 3, ContractNumber = "C3"},
            new Client {ClientId = 4, ContractNumber = "C4"},
            new Client {ClientId = 5, ContractNumber = "C5"}
            }.AsQueryable());

             // Arrange
             ClientController controller = new ClientController(mock.Object);
             controller.PageSize = 3;

             // Act
             ClientsListViewModel result = (ClientsListViewModel)controller.List(null, 2).Model;

             // Assert
             PagingInfo pageInfo = result.PagingInfo;
             Assert.AreEqual(pageInfo.CurrentPage, 2);
             Assert.AreEqual(pageInfo.ItemsPerPage, 3);
             Assert.AreEqual(pageInfo.TotalItems, 5);
             Assert.AreEqual(pageInfo.TotalPages, 2);
        }
Example #3
0
        public void Can_Paginate()
        {
            // Arrange
                Mock<IClientRepository> mock = new Mock<IClientRepository>();
                mock.Setup(m => m.Clients).Returns(new Client[] {
            new Client {ClientId = 1, ContractNumber = "C1"},
            new Client {ClientId = 2, ContractNumber = "C2"},
            new Client {ClientId = 3, ContractNumber = "C3"},
            new Client {ClientId = 4, ContractNumber = "C4"},
            new Client {ClientId = 5, ContractNumber = "C5"}
               }.AsQueryable());
                ClientController controller = new ClientController(mock.Object);

                controller.PageSize = 3;
                // Act

                ClientsListViewModel result = (ClientsListViewModel)controller.List(null, 2).Model;

                // Assert
                Client[] clientArray = result.Clients.ToArray();
                Assert.IsTrue(clientArray.Length == 2);
                Assert.AreEqual(clientArray[0].ContractNumber, "C4");
                Assert.AreEqual(clientArray[1].ContractNumber, "C5");
        }