Ejemplo n.º 1
0
        public void It_Validates_The_Course_Id()
        {
            var command = new DisenrollStudentCommand(Guid.NewGuid(), Guid.Empty, "A");
            var result  = validator.Validate(command);

            AssertHasValidationError(result, "CourseId");
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }