Exemplo n.º 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 Guid AddBooking(IBooking booking)
 {
     var command = new AddBookingCommand(booking);
     var result = _processor.ProcessCommand(command);
     if (result.EventsWereEmitted)
     {
         return command.CreatedGuid;
     }
     throw new CreationFailedException(command.CreatedGuid, typeof (IBooking));
 }
 public Guid AddBooking(DateTimeOffset checkIn, DateTimeOffset checkOut, bool paid, Guid customerId,
     params Guid[] rooms)
 {
     var command = new AddBookingCommand(checkIn, checkOut, paid, customerId, rooms);
     var result = _processor.ProcessCommand(command);
     if (result.EventsWereEmitted)
     {
         return command.CreatedGuid;
     }
     throw new CreationFailedException(command.CreatedGuid, typeof (IBooking));
 }
Exemplo n.º 4
0
        private static void AddSuccesfulBooking()
        {
            var command1 = new AddBookingCommand()
            {
                UserId     = "Homer",
                Period     = new DateRange(DateTime.Today, DateTime.Today.AddDays(4)),
                ResourceId = 1
            };

            _engine.Execute(command1);
        }
Exemplo n.º 5
0
        private static void TryAddConflictingBooking()
        {
            var command2 = new AddBookingCommand()
            {
                UserId     = "Bart",
                Period     = new DateRange(DateTime.Today.AddDays(2), DateTime.Today.AddDays(6)),
                ResourceId = 1
            };

            try
            {
                _engine.Execute(command2);
            }
            catch (CommandAbortedException ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public void GivenNoGuestFullNameAndPhoneNumberProvided_WhenAddBooking_ShouldThrowError()
        {
            // Arrange
            var LAddBookingCommand = new AddBookingCommand
            {
                GuestFullName    = null,
                GuestPhoneNumber = null,
                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(2);
            LResult.Errors[0].ErrorCode.Should().Be(nameof(ValidationCodes.REQUIRED));
            LResult.Errors[1].ErrorCode.Should().Be(nameof(ValidationCodes.REQUIRED));
        }
Exemplo n.º 9
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));
            }
Exemplo n.º 10
0
 public void Initialize()
 {
     AddBookingCommand = new AddBookingCommand(this);
 }