Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- // Student
- Mock<IStudent> studentMock = new Mock<IStudent>();
- studentMock.SetupAllProperties();
- IStudent student = studentMock.Object;
- student.Name = "Student Name";
- student.Age = 18;
- // Student Collection
- IList<IStudent> backingList = new List<IStudent>();
- Mock<IStudentCollection> studentCollectionMock = new Mock<IStudentCollection>();
- studentCollectionMock.SetupAllProperties();
- studentCollectionMock.Setup(sc => sc.GetEnumerator()).Returns(backingList.GetEnumerator());
- studentCollectionMock.Setup(sc => sc.Add(It.IsAny<IStudent>())).Callback<IStudent>((s) => backingList.Add(s));
- studentCollectionMock.Setup(sc => sc.Count).Returns(() => backingList.Count);
- studentCollectionMock.Setup(sc => sc[It.IsAny<int>()]).Returns<int>(i => backingList.ElementAt(i));
- studentCollectionMock.Setup(sc => sc.GetEnumerator()).Returns(() => backingList.GetEnumerator());
- IStudentCollection students = studentCollectionMock.Object;
- // School
- Mock<ISchool> schoolMock = new Mock<ISchool>();
- schoolMock.SetupAllProperties();
- ISchool school = schoolMock.Object;
- school.Name = "School Name";
- school.Students = students;
- school.Students.Add(student);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement