コード例 #1
0
        public async Task GetAllAsync()
        {
            // Arrange
            var mockStudents = new Mock <IStudentService>();

            mockStudents.Setup(repo => repo.GetByIdAsync(Guid.Parse(StudentId)))
            .Returns(Task.FromResult(new Student
            {
                Name = "Test Student"
            }));

            var mockEmployees = new Mock <IEmployeeService>();

            mockEmployees.Setup(repo => repo.GetByIdAsync(Guid.Parse(TeacherId)))
            .Returns(Task.FromResult(new Employee
            {
                Name = "Test Employee"
            }));

            var mockRepo = new Mock <IGroupRepository>();

            mockRepo.Setup(repo => repo.GetAll()).Returns(GetGroups());

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(uow => uow.Groups).Returns(mockRepo.Object);

            var provider = new GroupProvider(mockUnitOfWork.Object, mockStudents.Object, mockEmployees.Object, CreateMapper());

            // Act
            var result = await provider.GetAllAsync(1, 1);

            // Assert
            Assert.NotNull(result);

            var firstGroup = result.Values.FirstOrDefault();

            Assert.Equal("Test Group", firstGroup.Name);

            Assert.NotNull(firstGroup.Teacher);
            Assert.IsType <Employee>(firstGroup.Teacher);
            Assert.Equal("Test Employee", firstGroup.Teacher.Name);

            Assert.NotEmpty(firstGroup.Students);
            Assert.IsType <Student>(firstGroup.Students.First());
            Assert.Equal("Test Student", firstGroup.Students.First().Name);
        }