public void It_Validates_The_Course_Id() { var command = new DisenrollStudentCommand(Guid.NewGuid(), Guid.Empty, "A"); var result = validator.Validate(command); AssertHasValidationError(result, "CourseId"); }
public async Task <IActionResult> Disenroll( [FromRoute] Guid studentId, [FromBody] DisenrollStudentRequest request) { var command = new DisenrollStudentCommand(studentId, request.CourseId, request.Comment); var result = await mediator.Send(command); return(FromPresenter(new DisenrollStudentPresenter(result))); }
public async Task It_Returns_A_Failure_If_Course_Not_Found() { var student = new Student( new StudentName("Jordan Walker"), new EmailAddress("*****@*****.**") ); await studentRepositorySpy.Add(student); var command = new DisenrollStudentCommand(student.Id, Guid.NewGuid(), "Comment."); var result = await handler.Handle(command, new CancellationToken()); Assert.True(result.IsFailure); Assert.IsType <CourseNotFoundError>(result.Error); }
public async Task It_Returns_A_Failure_If_Student_Not_Found() { var course = new Course( new CourseTitle("Philsophy"), new Credits(1) ); await courseRepositorySpy.Add(course); var command = new DisenrollStudentCommand(Guid.NewGuid(), course.Id, "Comment."); var result = await handler.Handle(command, new CancellationToken()); Assert.True(result.IsFailure); Assert.IsType <StudentNotFoundError>(result.Error); }
public void It_Validates_The_Comment() { DisenrollStudentCommand command; Result result; command = new DisenrollStudentCommand(Guid.NewGuid(), Guid.NewGuid(), null); result = validator.Validate(command); AssertHasValidationError(result, "Comment"); command = new DisenrollStudentCommand(Guid.NewGuid(), Guid.NewGuid(), string.Empty); result = validator.Validate(command); AssertHasValidationError(result, "Comment"); command = new DisenrollStudentCommand(Guid.NewGuid(), Guid.NewGuid(), " "); result = validator.Validate(command); AssertHasValidationError(result, "Comment"); }
public async Task It_Returns_An_Error_If_Student_Is_Not_Enrolled_In_Course() { var student = new Student( new StudentName("Jordan Walker"), new EmailAddress("*****@*****.**") ); var course = new Course( new CourseTitle("Philsophy"), new Credits(1) ); await studentRepositorySpy.Add(student); await courseRepositorySpy.Add(course); var command = new DisenrollStudentCommand(student.Id, course.Id, "Comment."); var result = await handler.Handle(command, new CancellationToken()); Assert.True(result.IsFailure); }
public async Task It_Enrolls_The_Student() { var student = new Student( new StudentName("Jordan Walker"), new EmailAddress("*****@*****.**") ); var course = new Course( new CourseTitle("Philsophy"), new Credits(1) ); student.Enroll(course, Grade.A); await studentRepositorySpy.Add(student); await courseRepositorySpy.Add(course); var command = new DisenrollStudentCommand(student.Id, course.Id, "Comment."); var result = await handler.Handle(command, new CancellationToken()); Assert.False(student.AlreadyEnrolledIn(course)); Assert.True(result.IsSuccess); Assert.True(unitOfWorkSpy.WasCommited); }