public void Can_Index_Search() { Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>(); mock.Setup(s => s.StudentRepo.GetStudentQueryable()).Returns(studentsList.AsQueryable()); StudentController controller = new StudentController(mock.Object); IEnumerable<Student> resutl = (IEnumerable<Student>)controller.Index("Name_desc", "J", null, null).Model; Student[] student = resutl.ToArray(); Assert.AreEqual(student[0].FirstMidName, "Jan"); Assert.AreEqual(student[1].FirstMidName, "John"); }
public void Details_Action_Get_Correct_Details() { Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>(); mock.Setup(s => s.StudentRepo.GetById(It.IsAny<int>())).Returns(student4); StudentController controller = new StudentController(mock.Object); ViewResult vr = controller.Details(4) as ViewResult; Student result = (Student)vr.Model; Assert.AreEqual(result.FirstMidName, "Adam"); Assert.AreEqual(result.LastName, "Freeman"); }
public void Can_Display_List_Of_Students() { Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>(); mock.Setup(s => s.StudentRepo.GetStudentQueryable()).Returns(studentsList.AsQueryable()); StudentController controller = new StudentController(mock.Object); ViewResult vr = controller.List() as ViewResult; IEnumerable<Student> result = (IEnumerable<Student>)vr.Model; Student[] stud = result.ToArray(); Assert.AreEqual(stud[0].FirstMidName, "Daniel"); Assert.IsTrue(result.Count() == 4); }
public void Initialize() { AutoMapperConfig.Init(); studentslist = (new Student[] { new Student { Id = 1, LastName = "Student1" }, new Student { Id = 2, LastName = "Student2" }, new Student { Id = 3, LastName = "Student3" }, new Student { Id = 4, LastName = "Student4" }, new Student { Id = 5, LastName = "Student5" } }).AsQueryable(); studentsrepo = new Mock<IStudentsRepository>(); studentsrepo.Setup(repo => repo.GetAll()) .Returns(studentslist); studentsrepo.Setup(repo => repo.GetById(It.IsAny<int>())) .Returns((int id) => studentslist.Where(s => s.Id == id).SingleOrDefault()); uow = new Mock<ISchoolUow>(); uow.Setup(uow => uow.Students).Returns(studentsrepo.Object); controller = new StudentController(uow.Object); }
public void Details_Thorw_HttpNotFound() { Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>(); Student student = null; mock.Setup(s => s.StudentRepo.GetById(It.IsAny<int>())).Returns(student); StudentController controller = new StudentController(mock.Object); var result = controller.Details(0) as HttpNotFoundResult; Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, 404); }