public void GetStudent() { var repository = new FakeStudentRepository(new DbContext("JustMock sucks")); for (int i = 1; i <= 3; i++) { repository.students.Add(new Student().AddId(i)); } var controller = new StudentsController(repository); SetupController(controller); var returned = controller.Get(3); Assert.IsTrue(returned.Id == 3); }
public void GetMarkWithMock() { var repository = Mock.Create<DbStudentRepository>(); bool itemIsAdded = false; var student = new Student() .AddFirstName("I") .AddLastName("Mock") .AddId(0).AddMarks("math", 5.5, 3) ; Mock.Arrange(() => repository.Add(Arg.IsAny<Student>())) .DoInstead(() => { itemIsAdded = true; }) .Returns(student); var controller = new StudentsController(repository); SetupController(controller); controller.Post(student); Assert.IsTrue(itemIsAdded == true); }
public void GetStudentMarks() { var repository = new FakeStudentRepository(new DbContext("JustMock sucks")); for (int i = 1; i <= 3; i++) { repository.students.Add(new Student() { Marks = new HashSet<Mark>(Enumerable.Repeat<Mark>(new Mark() { Subject = "math", Value = 5.5, StudentId = i }, 1)) }.AddId(i)); } repository.students.Add(new Student() { Marks = new HashSet<Mark>(Enumerable.Repeat<Mark>(new Mark() { Subject = "math", Value = 3, StudentId = 4 }, 1)) }.AddId(4)); var controller = new StudentsController(repository); SetupController(controller); var returned = controller.Get("math", 4); Assert.IsTrue(returned.Count() == 3); }
public void PostStudent() { var repository = new FakeStudentRepository(new DbContext("JustMock sucks")); var student = new Student(); var controller = new StudentsController(repository); SetupController(controller); controller.Post(student); Assert.IsTrue(repository.students.Count == 1); }