Пример #1
0
        public void CourseEnrollmentCommand_Validate_InvalidCommand(bool generateValidGuid,
                                                                    string studentName,
                                                                    int studentAge)
        {
            var id      = generateValidGuid ? Guid.NewGuid() : Guid.Empty;
            var command = new CourseEnrollmentCommand()
            {
                CourseId    = id,
                StudentAge  = studentAge,
                StudentName = studentName
            };

            Action validation = () => command.Validate().Wait();

            validation.Should().Throw <ValidationException>();
        }
Пример #2
0
        public async Task CourseEnrollmentCommandHandler_Handle_NewStudent()
        {
            // Arrange
            var courseId = Guid.NewGuid();
            var handler  = MockHelper.GetRequestHandler(courseId);

            var command = new CourseEnrollmentCommand()
            {
                CourseId    = courseId,
                StudentAge  = 16,
                StudentName = "Carl"
            };

            // Act

            var result = await handler.Handle(command, default);

            // Assert
            result.Should().BeTrue();
        }
Пример #3
0
        public void CourseEnrollmentCommandHandler_Handle_InexistentCourse()
        {
            // Arrange
            var courseId = Guid.NewGuid();

            var handler = MockHelper.GetRequestHandler();

            var command = new CourseEnrollmentCommand()
            {
                CourseId    = courseId,
                StudentAge  = 24,
                StudentName = "William"
            };

            // Act

            Action handle = () => handler.Handle(command, default).Wait();

            // Assert
            handle.Should().Throw <ElementNotFoundException>();
        }
Пример #4
0
        public void CourseEnrollmentCommandHandler_Handle_CourseFull()
        {
            // Arrange
            var courseId = Guid.NewGuid();

            var handler = MockHelper.GetRequestHandler(courseId, capacity: 1);

            var command = new CourseEnrollmentCommand()
            {
                CourseId    = courseId,
                StudentAge  = 24,
                StudentName = "William"
            };

            // Act

            Action handle = () => handler.Handle(command, default).Wait();

            // Assert
            handle.Should().Throw <CourseLimitException>();
        }
Пример #5
0
        public void CourseEnrollmentCommandHandler_Handle_DoubleApplication()
        {
            // Arrange
            var courseId = Guid.NewGuid();
            var billId   = Guid.NewGuid();

            var handler = MockHelper.GetRequestHandler(courseId, billId);

            var command = new CourseEnrollmentCommand()
            {
                CourseId    = courseId,
                StudentAge  = 25,
                StudentName = "Bill"
            };

            // Act

            Action handle = () => handler.Handle(command, default).Wait();

            // Assert
            handle.Should().Throw <DoubleApplicationException>();
        }