Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. static void Main()
  2. {
  3. // Student
  4. Mock<IStudent> studentMock = new Mock<IStudent>();
  5. studentMock.SetupAllProperties();
  6.  
  7. IStudent student = studentMock.Object;
  8. student.Name = "Student Name";
  9. student.Age = 18;
  10.  
  11. // Student Collection
  12. IList<IStudent> backingList = new List<IStudent>();
  13.  
  14. Mock<IStudentCollection> studentCollectionMock = new Mock<IStudentCollection>();
  15. studentCollectionMock.SetupAllProperties();
  16. studentCollectionMock.Setup(sc => sc.GetEnumerator()).Returns(backingList.GetEnumerator());
  17. studentCollectionMock.Setup(sc => sc.Add(It.IsAny<IStudent>())).Callback<IStudent>((s) => backingList.Add(s));
  18. studentCollectionMock.Setup(sc => sc.Count).Returns(() => backingList.Count);
  19. studentCollectionMock.Setup(sc => sc[It.IsAny<int>()]).Returns<int>(i => backingList.ElementAt(i));
  20. studentCollectionMock.Setup(sc => sc.GetEnumerator()).Returns(() => backingList.GetEnumerator());
  21.  
  22. IStudentCollection students = studentCollectionMock.Object;
  23.  
  24. // School
  25. Mock<ISchool> schoolMock = new Mock<ISchool>();
  26. schoolMock.SetupAllProperties();
  27.  
  28. ISchool school = schoolMock.Object;
  29. school.Name = "School Name";
  30. school.Students = students;
  31. school.Students.Add(student);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement