Exemple #1
0
        public async Task Should_update_grade()
        {
            // create course
            var createCourseCommand = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var createCourseCommandHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);

            var courseResult = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None);

            // Create student
            var createStudentCommand = new CreateStudentCommand()
            {
                Id          = Guid.NewGuid(),
                FirstName   = "Milos",
                LastName    = "Stojkovic",
                Address     = "Bata Noleta 31",
                City        = "Sokobanja",
                DateOfBirth = new DateTime(1991, 3, 18),
                State       = "Srbija",
                Gender      = 0
            };

            var createStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context);

            var studentResult = await createStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None);

            var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand()
            {
                Id         = createStudentCommand.Id,
                CourseCode = createCourseCommand.Code,
                Grade      = (int)Domain.Enumerations.Grade.Seven
            };

            var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);
            var result = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None);

            result.ShouldBe(true);

            var enrollment = await this.context.Enrollment
                             .FirstOrDefaultAsync(e => e.Course.Code == createOrUpdateEnrollmentCommand.CourseCode && e.Student.Id == createOrUpdateEnrollmentCommand.Id, CancellationToken.None);

            enrollment.Grade.ShouldBe(Domain.Enumerations.Grade.Seven);

            createOrUpdateEnrollmentCommand.Grade = (int)Domain.Enumerations.Grade.Eight;
            var updateResult = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None);

            updateResult.ShouldBe(true);
            var updatedEnrollment = await this.context.Enrollment
                                    .FirstOrDefaultAsync(e => e.Course.Code == createOrUpdateEnrollmentCommand.CourseCode && e.Student.Id == createOrUpdateEnrollmentCommand.Id, CancellationToken.None);

            updatedEnrollment.Grade.ShouldBe(Domain.Enumerations.Grade.Eight);
        }
        public async Task Should_throw_delete_failure_exception()
        {
            // create course
            var createCourseCommand = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 1,
                Name        = "Course 1",
                Description = "Test"
            };

            var createCourseCommandHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);
            var commandResult = await createCourseCommandHandler.Handle(createCourseCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            // Create student
            var createStudentCommand = new CreateStudentCommand()
            {
                Id          = Guid.NewGuid(),
                FirstName   = "Milos",
                LastName    = "Stojkovic",
                Address     = "Bata Noleta 31",
                City        = "Sokobanja",
                DateOfBirth = new DateTime(1991, 3, 18),
                State       = "Srbija",
                Gender      = 0
            };

            var createStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context);

            commandResult = await createStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand()
            {
                Id         = createStudentCommand.Id,
                CourseCode = createCourseCommand.Code,
                Grade      = (int)Domain.Enumerations.Grade.Seven
            };

            var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);

            commandResult = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None);

            commandResult.ShouldBe(true);

            var deleteStudentCommand = new DeleteStudentCommand()
            {
                Id = createStudentCommand.Id
            };

            var deleteStudentCommandHandler = new DeleteStudentCommandHandler(this.context);
            await Assert.ThrowsAsync <DeleteFailureException>(() => deleteStudentCommandHandler.Handle(deleteStudentCommand, CancellationToken.None));
        }
Exemple #3
0
        public async Task Should_throw_not_argument_exception()
        {
            var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand()
            {
                Id         = Guid.NewGuid(),
                CourseCode = 9999,
                Grade      = (int)Domain.Enumerations.Grade.Six
            };

            var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);

            await Assert.ThrowsAsync <NotFoundException>(() => createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None));
        }
        public async Task Should_return_sutdents_with_passed_coruces()
        {
            // create course
            var courseQuery = new CreateCourseCommand()
            {
                Id          = Guid.NewGuid(),
                Code        = 5,
                Name        = "Course 2",
                Description = "Test"
            };

            var courseHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);

            var courseResult = await courseHandler.Handle(courseQuery, CancellationToken.None);

            // Create student
            var createStudentCommand = new CreateStudentCommand()
            {
                Id          = Guid.NewGuid(),
                FirstName   = "Milos",
                LastName    = "Stojkovic",
                Address     = "Bata Noleta 31",
                City        = "Sokobanja",
                DateOfBirth = new DateTime(1991, 3, 18),
                State       = "Srbija",
                Gender      = 0
            };

            var createStudentCommandHandler = new CreateStudentCommandHandler(this.autoMapper, this.context);

            var studentResult = await createStudentCommandHandler.Handle(createStudentCommand, CancellationToken.None);

            var createOrUpdateEnrollmentCommand = new CreateOrUpdateEnrollmentCommand()
            {
                Id         = createStudentCommand.Id,
                CourseCode = courseQuery.Code,
                Grade      = (int)Domain.Enumerations.Grade.Seven
            };

            var createOrUpdateEnrollmentCommandHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);
            var enrollmentResult = await createOrUpdateEnrollmentCommandHandler.Handle(createOrUpdateEnrollmentCommand, CancellationToken.None);

            enrollmentResult.ShouldBe(true);

            var query   = new GetStudentsWithPassedCoursesQuery();
            var handler = new GetStudentsWithPassedCoursesQueryHandler(this.autoMapper, this.context);
            var result  = await handler.Handle(query, CancellationToken.None);

            result.Where(s => s.Id == createStudentCommand.Id).Count().ShouldBe(1);
        }
        public async Task Should_return_filter_Students()
        {
            var firstStudentId  = Guid.NewGuid();
            var secondStudentId = Guid.NewGuid();

            // enrollment added 1
            {
                // create course
                var courseQuery = new CreateCourseCommand()
                {
                    Id          = Guid.NewGuid(),
                    Code        = 2,
                    Name        = "Course 2",
                    Description = "Test"
                };

                var courseHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);
                var courseResult  = await courseHandler.Handle(courseQuery, CancellationToken.None);

                // Create student
                var studentQuery = new CreateStudentCommand()
                {
                    Id          = firstStudentId,
                    FirstName   = "Milos",
                    LastName    = "Stojkovic",
                    Address     = "Bata Noleta 31",
                    City        = "Sokobanja",
                    DateOfBirth = new DateTime(1991, 3, 18),
                    State       = "Srbija",
                    Gender      = 0
                };

                var studenthandler = new CreateStudentCommandHandler(this.autoMapper, this.context);
                var studentResult  = await studenthandler.Handle(studentQuery, CancellationToken.None);

                studentResult.ShouldBe(true);

                var enrollmentQuery = new CreateOrUpdateEnrollmentCommand()
                {
                    Id         = studentQuery.Id,
                    CourseCode = courseQuery.Code,
                    Grade      = (int)Domain.Enumerations.Grade.Seven
                };

                var enrollmentHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);
                var enrollmentResult  = await enrollmentHandler.Handle(enrollmentQuery, CancellationToken.None);

                enrollmentResult.ShouldBe(true);
            }

            // enrollment added 2
            {
                // create course
                var courseQuery = new CreateCourseCommand()
                {
                    Id          = Guid.NewGuid(),
                    Code        = 3,
                    Name        = "Course 2",
                    Description = "Test"
                };

                var courseHandler = new CreateCourseCommandHandler(this.autoMapper, this.context);
                var courseResult  = await courseHandler.Handle(courseQuery, CancellationToken.None);

                // Create student
                var studentQuery = new CreateStudentCommand()
                {
                    Id          = secondStudentId,
                    FirstName   = "Jelica",
                    LastName    = "Ilica",
                    Address     = "Bata Noleta 31",
                    City        = "Sokobanja",
                    DateOfBirth = new DateTime(1991, 3, 18),
                    State       = "Srbija",
                    Gender      = 0
                };

                var studenthandler = new CreateStudentCommandHandler(this.autoMapper, this.context);
                var studentResult  = await studenthandler.Handle(studentQuery, CancellationToken.None);

                studentResult.ShouldBe(true);

                var enrollmentQuery = new CreateOrUpdateEnrollmentCommand()
                {
                    Id         = studentQuery.Id,
                    CourseCode = courseQuery.Code,
                    Grade      = (int)Domain.Enumerations.Grade.Seven
                };

                var enrollmentHandler = new CreateOrUpdateEnrollmentCommandHandler(this.context);
                var enrollmentResult  = await enrollmentHandler.Handle(enrollmentQuery, CancellationToken.None);

                enrollmentResult.ShouldBe(true);
            }

            var query = new GetStudentsWithPassedCoursesQuery()
            {
                FilterByFullName = "Milos"
            };

            var handler = new GetStudentsWithPassedCoursesQueryHandler(this.autoMapper, this.context);
            var result  = await handler.Handle(query, CancellationToken.None);

            result.Where(s => s.Id == firstStudentId).Count().ShouldBe(1);

            query = new GetStudentsWithPassedCoursesQuery()
            {
                FilterByFullName = ""
            };

            handler = new GetStudentsWithPassedCoursesQueryHandler(this.autoMapper, this.context);
            result  = await handler.Handle(query, CancellationToken.None);

            result.Where(s => s.Id == firstStudentId || s.Id == secondStudentId).Count().ShouldBe(2);
        }