Пример #1
0
        public async Task GivenAllDataProvided_WhenAddBooking_ShouldAddEntity()
        {
            // Arrange
            var LAddBookingCommand = new AddBookingCommand
            {
                GuestFullName    = StringProvider.GetRandomString(),
                GuestPhoneNumber = StringProvider.GetRandomString(),
                BedroomsNumber   = 1,
                DateFrom         = FDateTimeService.Now.AddDays(5),
                DateTo           = FDateTimeService.Now.AddDays(15)
            };

            var LDatabaseContext = GetTestDatabaseContext();

            await RoomsFactory(10, LDatabaseContext);

            var LAddBookingCommandHandler = new AddBookingCommandHandler(LDatabaseContext);

            // Act
            await LAddBookingCommandHandler.Handle(LAddBookingCommand, CancellationToken.None);

            // Assert
            var LBookingEntity = LDatabaseContext.Bookings.ToList();

            LBookingEntity.Should().HaveCount(1);
            LBookingEntity[0].GuestFullName.Should().Be(LAddBookingCommand.GuestFullName);
            LBookingEntity[0].GuestPhoneNumber.Should().Be(LAddBookingCommand.GuestPhoneNumber);
            LBookingEntity[0].DateFrom.Should().BeSameDateAs(LAddBookingCommand.DateFrom);
            LBookingEntity[0].DateTo.Should().BeSameDateAs(LAddBookingCommand.DateTo);
        }
        public async Task GivenCorrectId_WhenRemoveBooking_ShouldSucceed()
        {
            // Arrange
            var LDatabaseContext             = GetTestDatabaseContext();
            var LRemoveBookingCommandHandler = new RemoveBookingCommandHandler(LDatabaseContext);

            var LRoom = new Rooms
            {
                RoomNumber = 101,
                Bedrooms   = 3
            };

            await LDatabaseContext.Rooms.AddAsync(LRoom);

            await LDatabaseContext.SaveChangesAsync();

            var LBookings = new List <Bookings>
            {
                new ()
                {
                    RoomId           = LRoom.Id,
                    GuestFullName    = StringProvider.GetRandomString(),
                    GuestPhoneNumber = StringProvider.GetRandomString(9),
                    DateFrom         = FDateTimeService.Now.AddDays(5),
                    DateTo           = FDateTimeService.Now.AddDays(15)
                },
                new ()
                {
                    RoomId           = LRoom.Id,
                    GuestFullName    = StringProvider.GetRandomString(),
                    GuestPhoneNumber = StringProvider.GetRandomString(9),
                    DateFrom         = FDateTimeService.Now.AddDays(1),
                    DateTo           = FDateTimeService.Now.AddDays(3)
                }
            };

            await LDatabaseContext.Bookings.AddRangeAsync(LBookings);

            await LDatabaseContext.SaveChangesAsync();

            var LBookingOne = LBookings[0].Id;
            var LBookingTwo = LBookings[1].Id;

            // Act
            await LRemoveBookingCommandHandler
            .Handle(new RemoveBookingCommand { Id = LBookingTwo }, CancellationToken.None);

            // Assert
            var LAssertDbContext = GetTestDatabaseContext();
            var LArticlesEntity  = await LAssertDbContext.Bookings.FindAsync(LBookingTwo);

            LArticlesEntity.Should().BeNull();
        }
    }
        public async Task WhenGetRoomsInfo_ShouldReturnsCollection()
        {
            // Arrange
            var LDatabaseContext          = GetTestDatabaseContext();
            var LGetRoomsInfoQueryHandler = new GetRoomsInfoQueryHandler(LDatabaseContext);

            var LRoom = new Rooms
            {
                RoomNumber = 101,
                Bedrooms   = 3
            };

            await LDatabaseContext.Rooms.AddAsync(LRoom);

            await LDatabaseContext.SaveChangesAsync();

            var LBookings = new List <Bookings>
            {
                new ()
                {
                    RoomId           = LRoom.Id,
                    GuestFullName    = StringProvider.GetRandomString(),
                    GuestPhoneNumber = StringProvider.GetRandomString(9),
                    DateFrom         = FDateTimeService.Now.AddDays(5),
                    DateTo           = FDateTimeService.Now.AddDays(15)
                },
                new ()
                {
                    RoomId           = LRoom.Id,
                    GuestFullName    = StringProvider.GetRandomString(),
                    GuestPhoneNumber = StringProvider.GetRandomString(9),
                    DateFrom         = FDateTimeService.Now.AddDays(1),
                    DateTo           = FDateTimeService.Now.AddDays(3)
                }
            };

            await LDatabaseContext.Bookings.AddRangeAsync(LBookings);

            await LDatabaseContext.SaveChangesAsync();

            // Act
            var LResults = (await LGetRoomsInfoQueryHandler
                            .Handle(new GetRoomsInfoQuery(), CancellationToken.None))
                           .ToList();

            // Assert
            LResults.Should().NotBeNull();
            LResults.Should().HaveCount(1);
            LResults[0].Info.Should().Be("1 room with 3 bedrooms.");
        }
    }
Пример #4
0
        public void GivenAllFieldsAreCorrect_WhenAddBooking_ShouldSucceed()
        {
            // Arrange
            var LAddBookingCommand = new AddBookingCommand
            {
                GuestFullName    = StringProvider.GetRandomString(),
                GuestPhoneNumber = StringProvider.GetRandomString(9),
                BedroomsNumber   = 1,
                DateFrom         = FDateTimeService.Now.AddDays(10),
                DateTo           = FDateTimeService.Now.AddDays(20)
            };

            // Act
            var LValidator = new AddBookingCommandValidator(FDateTimeService);
            var LResult    = LValidator.Validate(LAddBookingCommand);

            // Assert
            LResult.Errors.Should().BeEmpty();
        }
Пример #5
0
        public void GivenGuestPhoneNumberTooLong_WhenAddBooking_ShouldThrowError()
        {
            // Arrange
            var LAddBookingCommand = new AddBookingCommand
            {
                GuestFullName    = StringProvider.GetRandomString(),
                GuestPhoneNumber = StringProvider.GetRandomString(15),
                BedroomsNumber   = 1,
                DateFrom         = FDateTimeService.Now.AddDays(10),
                DateTo           = FDateTimeService.Now.AddDays(20)
            };

            // Act
            var LValidator = new AddBookingCommandValidator(FDateTimeService);
            var LResult    = LValidator.Validate(LAddBookingCommand);

            // Assert
            LResult.Errors.Count.Should().Be(1);
            LResult.Errors[0].ErrorCode.Should().Be(nameof(ValidationCodes.PHONE_NUMBER_TOO_LONG));
        }
Пример #6
0
        public void GivenDateFromAndDateToAreSame_WhenAddBooking_ShouldThrowError(DateTime ADateFrom, DateTime ADateTo, TestCaseDays ACase)
        {
            // Arrange
            var LAddBookingCommand = new AddBookingCommand
            {
                GuestFullName    = StringProvider.GetRandomString(),
                GuestPhoneNumber = StringProvider.GetRandomString(9),
                BedroomsNumber   = 1,
                DateFrom         = ADateFrom,
                DateTo           = ADateTo
            };

            // Act
            var LValidator = new AddBookingCommandValidator(FDateTimeService);
            var LResult    = LValidator.Validate(LAddBookingCommand);

            // Assert
            if (ACase is TestCaseDays.Present or TestCaseDays.Future)
            {
                LResult.Errors.Count.Should().Be(1);
                LResult.Errors[0].ErrorCode.Should().Be(nameof(ValidationCodes.START_DATE_AND_END_DATE_CANNOT_BE_SAME));
            }