public async void SignupCourse_Success([Frozen] Mock <ICourseRepository> repository, CourseSignupCommand command, Course course, User user, CoursesCommandService sut) { // Arrange repository.Setup(o => o.GetCourse(command.CourseId)).ReturnsAsync(course); repository.Setup(o => o.GetUser(command.InputData.StudentId)).ReturnsAsync(user); int preSignUpUserCount = course.UserCourses.Count; // Act SignupCourseResponse result = await sut.SignupCourse(command); // Assert int postSignUpUserCount = course.UserCourses.Count; postSignUpUserCount.Should().Be(preSignUpUserCount + 1, "because user is added to the course"); result.Success.Should().BeTrue("because result is success"); }
public async Task <SignupCourseResponse> SignupCourse(CourseSignupCommand command) { SignupCourseResponse result = new SignupCourseResponse(); Course course = await CourseRepository.GetCourse(command.CourseId); if (course == null) { throw new Exception($"Course not found. CourseId: {command.CourseId}"); } User user = await CourseRepository.GetUser(command.InputData.StudentId); if (user == null) { throw new Exception($"User not found. UserId: {command.InputData.StudentId}"); } course.Signup(user); await UnitOfWork.Commit(); result.Success = true; return(result); }