public void Can_Retrieve_Image_Data() { Employee prod = new Employee { EmployeeId = 2, Name = "Test", ImageData = new byte[] { }, ImageMimeType = "image/png" }; Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>(); mock.Setup(m => m.Employees).Returns(new Employee[] { new Employee {EmployeeId = 1, Name = "P1"}, prod, new Employee {EmployeeId = 3, Name = "P3"}, }.AsQueryable); EmployeeController target = new EmployeeController(mock.Object); ActionResult result = target.GetImage(2); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(FileResult)); Assert.AreEqual(prod.ImageMimeType, ((FileResult)result).ContentType); }
public void Cannot_Retrieve_Image_Data_For_Invalid_ID() { Mock<IEmployeeRepository> mock = new Mock<IEmployeeRepository>(); mock.Setup(m => m.Employees).Returns(new Employee[] { new Employee {EmployeeId = 1, Name = "P1"}, new Employee {EmployeeId = 2, Name = "P2"}, }.AsQueryable); EmployeeController target = new EmployeeController(mock.Object); ActionResult result = target.GetImage(100); Assert.IsNull(result); }
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"); }
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"); }
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); }
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); }