コード例 #1
0
        public void Can_Filter_Employees()
        {
            Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>();
            mock.Setup(m => m.Employees).Returns(new Employee[]
            {
                new Employee {EmployeeId = 1, Name = "Employee1", Status = "Active"},
                new Employee {EmployeeId = 2, Name = "Employee2", Status = "Inactive"},
                new Employee {EmployeeId = 3, Name = "Employee3", Status = "Active"},
                new Employee {EmployeeId = 4, Name = "Employee4", Status = "Inactive"},
                new Employee {EmployeeId = 5, Name = "Employee5", Status = "Active"},
            }.AsQueryable());

            EmployeeController controller = new EmployeeController(mock.Object);

            controller.PageSize = 3;

            Employee[] result = ((EmployeesListViewModel)controller.List("Inactive", 1).Model)
               .Employees.ToArray();

            // Assert
            Assert.AreEqual(result.Length, 2);
            Assert.IsTrue(result[0].Name == "Employee2" && result[0].Status == "Inactive");
            Assert.IsTrue(result[1].Name == "Employee4" && result[1].Status == "Inactive");
        }
コード例 #2
0
        public void Can_Paginate()
        {
            Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>();
            mock.Setup(m => m.Employees).Returns(new Employee[]
            {
                new Employee {EmployeeId = 1, Name = "Employee1"},
                new Employee {EmployeeId = 2, Name = "Employee2"},
                new Employee {EmployeeId = 3, Name = "Employee3"},
                new Employee {EmployeeId = 4, Name = "Employee4"},
                new Employee {EmployeeId = 5, Name = "Employee5"},
            }.AsQueryable());

            EmployeeController controller = new EmployeeController(mock.Object);

            controller.PageSize = 3;

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

            Employee[] prodArray = result.Employees.ToArray();
            Assert.IsTrue(prodArray.Length == 2);
            Assert.AreEqual(prodArray[0].Name, "Employee4");
            Assert.AreEqual(prodArray[1].Name, "Employee5");
        }
コード例 #3
0
        public void Generate_Category_Specific_Employees_Count()
        {
            Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>();
            mock.Setup(m => m.Employees).Returns(new Employee[]
            {
                new Employee {EmployeeId = 1, Name = "Employee1", Status = "Active"},
                new Employee {EmployeeId = 2, Name = "Employee2", Status = "Inactive"},
                new Employee {EmployeeId = 3, Name = "Employee3", Status = "Active"},
                new Employee {EmployeeId = 4, Name = "Employee4", Status = "Inactive"},
                new Employee {EmployeeId = 5, Name = "Employee5", Status = "Inactive"},
            }.AsQueryable);

            EmployeeController target = new EmployeeController(mock.Object);
            target.PageSize = 3;

            int res1 = ((EmployeesListViewModel)target.List("Active").Model).PagingInfo.TotalItems;
            int res2 = ((EmployeesListViewModel)target.List("Inactive").Model).PagingInfo.TotalItems;
            int resAll = ((EmployeesListViewModel)target.List(null).Model).PagingInfo.TotalItems;

            Assert.AreEqual(res1, 2);
            Assert.AreEqual(res2, 3);
            Assert.AreEqual(resAll, 5);
        }
コード例 #4
0
        public void Can_Send_Pagination_View_Model()
        {
            Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>();
            mock.Setup(m => m.Employees).Returns(new Employee[]
            {
                new Employee {EmployeeId = 1, Name = "Employee1"},
                new Employee {EmployeeId = 2, Name = "Employee2"},
                new Employee {EmployeeId = 3, Name = "Employee3"},
                new Employee {EmployeeId = 4, Name = "Employee4"},
                new Employee {EmployeeId = 5, Name = "Employee5"},
            }.AsQueryable());

            EmployeeController controller = new EmployeeController(mock.Object);

            controller.PageSize = 3;

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

            PagingInfo pagingInfo = result.PagingInfo;
            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }