Example #1
0
        public async Task CanPaginate()
        {
            //Arrange
            Mock <IAgentRepository> mock = new Mock <IAgentRepository>();

            mock.Setup(agentsRepo => agentsRepo.GetAgentsIncludeGroupAsync()).ReturnsAsync(new List <Agent>
            {
                new Agent {
                    Id = 1, Login = "******", Name = "Agent1"
                },
                new Agent {
                    Id = 2, Login = "******", Name = "Agent2"
                },
                new Agent {
                    Id = 3, Login = "******", Name = "Agent3"
                },
                new Agent {
                    Id = 4, Login = "******", Name = "Agent4"
                },
                new Agent {
                    Id = 5, Login = "******", Name = "Agent5"
                },
                new Agent {
                    Id = 6, Login = "******", Name = "Agent6"
                },
                new Agent {
                    Id = 7, Login = "******", Name = "Agent7"
                }
            });

            mock.Setup(agentsRepo => agentsRepo.GetGroupsAsync()).ReturnsAsync(new List <Group>
            {
                new Group {
                    Id = 1, Name = "Group1"
                },
                new Group {
                    Id = 2, Name = "Group2"
                }
            });

            AgentsController controller = new AgentsController(mock.Object);

            AgentsIndexViewModel agentsIndexModel = new AgentsIndexViewModel
            {
                Page = 2
            };


            //Act
            var resultView = await controller.Index(agentsIndexModel) as ViewResult;

            AgentsIndexViewModel result = (AgentsIndexViewModel)resultView.Model;

            //Accert
            Assert.IsTrue(result.PagedAgents.Count == 2);
            Assert.AreEqual("Login6", result.PagedAgents.ToList()[0].Login);
            Assert.AreEqual("Agent7", result.PagedAgents.ToList()[1].Name);
        }