public void ModifyBookingWithMisMatchBusinessThrowsException()
            {
                // Arrange
                const long BUSINESS_ID = 2;
                const long MISMATCHED_BUSINESS_ID = 5;

                // Stub the BusinessCache to have the businesses to be used by our service method
                CacheHelper.StubBusinessCacheMultipleBusiness(new List<long> { MISMATCHED_BUSINESS_ID, BUSINESS_ID });

                // invalidate the cache so we make sure both our businesses are loaded into the cache
                Cache.Business.Invalidate();

                //Set up a Guest for the booking
                var guest = new GuestDto { Id = 23, BusinessId = BUSINESS_ID, Surname = "Doe" };

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    Guest = guest,
                    RoomId = 1
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.ModifyBooking(MISMATCHED_BUSINESS_ID, false, bookingDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30000 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30000", ex.Code, "The Validation exception is not returning the right error code");
                }
                finally
                {
                    // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                    CacheHelper.ReAssignBusinessDaoToBusinessCache();

                }
            }
            public void ModifyBookingWithExpectedResult()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                //Set up a Guest for the booking
                var guest = new GuestDto { Id = 23, BusinessId = BUSINESS_ID, Surname = "Doe" };

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    Order = new OrderDto
                    {
                        Id = 5,
                        OfflineSourceCode = OfflineSourceEnum.Web.GetCode(),
                        CustomerCultureCode = "en-GB",
                        CustomerCurrencyCode = "GBP"
                    },
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    Guest = guest,
                    RoomId = 1
                };

                var stubBookingManager = MockRepository.GenerateStub<IBookingManager>();

                PropertyManagementSystemService.BookingManager = stubBookingManager;

                stubBookingManager.Stub(c => c.ModifyBooking(Arg<bool>.Is.Equal(false), Arg<Booking>.Is.Anything)).Return(DataTransferObjectsConverter.ConvertBookingDtoToBooking(bookingDto));

                // Stub the BusinessCache to be used by our service method
                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID);

                // invalidate the cache so we make sure our business is loaded into the cache
                Cache.Business.Invalidate();

                // Act
                BookingDto modifyBookingResult = PropertyManagementSystemService.ModifyBooking(BUSINESS_ID, false, bookingDto);

                // Assert
                Assert.IsNotNull(modifyBookingResult, "booking was not modified successfully");
                stubBookingManager.VerifyAllExpectations();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
            public void ModifyBookingWithInvalidBusinessThrowsException()
            {
                // Arrange
                const long BUSINESS_ID = 123456;

                //Set up a Guest for the booking
                var guest = new GuestDto { Id = 23, BusinessId = BUSINESS_ID, Surname = "Doe" };

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    Guest = guest,
                    RoomId = 1
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.ModifyBooking(BUSINESS_ID, false, bookingDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30001 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30001", ex.Code, "The Validation exception is not returning the right error code");
                }
            }
            public void CreateBookingMismatchedBusinessIdThrowsValidationException()
            {
                // Arrange
                // Parameters for the invoke
                const long BUSINESS_ID = 2;
                const long MISMATCHED_BUSINESS_ID = 5;

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    Guest =
                        new GuestDto { Id = 1, BusinessId = BUSINESS_ID, Surname = "Test Guest", Email = "*****@*****.**" },
                    StartDate = new DateTime(2012, 2, 1, 0, 0, 0, DateTimeKind.Utc),
                    EndDate = new DateTime(2012, 2, 2, 0, 0, 0, DateTimeKind.Utc),
                    NumberOfAdults = 2,
                    NumberOfChildren = 1,
                    Cost = new decimal(120.5),
                    BookingStatusCode = BookingStatusType.CONFIRMED,
                    RoomTypeId = 1,
                    RoomId = 1,
                    RatePlanId = 1,
                    CheckinStatusCode = CheckinStatusOptions.NOTCHECKEDIN,
                    Notes = "Testing note",
                    BookingScenarioType = BookingScenarioTypeEnumDto.OnAccountBooking
                };

                // Stub the BusinessCache to be used by our service method
                CacheHelper.StubBusinessCacheSingleBusiness(MISMATCHED_BUSINESS_ID);

                // invalidate the cache so we make sure our business is loaded into the cache
                Cache.Business.Invalidate();

                try
                {
                    // Act
                    PropertyManagementSystemService.CreateBooking(MISMATCHED_BUSINESS_ID, bookingDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30000 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30000", ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
                finally
                {
                    // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                    CacheHelper.ReAssignBusinessDaoToBusinessCache();
                }
            }
            public void CreateBookingWithIncorrectRateTypeCodeThrowsException()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID);
                PropertyManagementSystemService.RoomInformationManager = new RoomInformationManager();
                PropertyManagementSystemService.BookingManager = new BookingManager();

                var mockOrderManager = new Mock<IOrderManager>();

                //Set up a Guest for the booking
                var guest = new GuestDto { Id = 23, BusinessId = BUSINESS_ID, Surname = "Doe" };

                const string BAD_CODE = "ThisIsABadCode";

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    Id = 1,
                    OrderId = 5,
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    Guest = guest,
                    RoomId = 1,
                    RoomTypeId = 1,
                    RatePlanId = 1,
                    NumberOfAdults = 1,
                    NumberOfChildren = 0,
                    RateTypeCode = BAD_CODE
                };

                mockOrderManager.Setup(o => o.GetByKey(bookingDto.OrderId.Value, It.IsAny<string>()))
                                .Returns(new Order {Id = bookingDto.OrderId});

                PropertyManagementSystemService.OrderManager = mockOrderManager.Object;

                // Act
                try
                {
                    PropertyManagementSystemService.CreateBooking(BUSINESS_ID, bookingDto);

                    // Assert
                    Assert.Fail("Exception with code SRVEX30046 should have been thrown");
                }
                catch (ValidationException vex)
                {
                    Assert.AreEqual("SRVEX30046", vex.Code, "Validation exception of type SRVEX30046 was not thrown");
                    mockOrderManager.VerifyAll();
                }
                finally
                {
                    CacheHelper.ReAssignBusinessDaoToBusinessCache();
                    PropertyManagementSystemService.GuestManager = new GuestManager();
                    PropertyManagementSystemService.OrderManager = new OrderManager();
                }
            }
            public void CreateBookingCreatesBooking()
            {
                // Arrange
                const long BUSINESS_ID = 1;

                // Stub the BusinessCache to be used by our service method
                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID);

                // invalidate the cache so we make sure our business is loaded into the cache
                Cache.Business.Invalidate();

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    OrderId = 4,
                    Order = new OrderDto
                    {
                        Id = 4,
                        OfflineSourceCode = OfflineSourceEnum.Web.GetCode(),
                        LeadGuest = new GuestDto { BusinessId = BUSINESS_ID, Surname = "Test Guest", Email = "*****@*****.**" }
                    },
                    Guest =
                        new GuestDto
                        {BusinessId = BUSINESS_ID, Surname = "Test Guest", Email = "*****@*****.**"},
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    NumberOfAdults = 2,
                    RoomTypeId = 1,
                    RoomId = 1,
                    RatePlanId = 1,
                    BookingStatusCode = BookingStatusType.TENTATIVE,
                    BookingScenarioType = BookingScenarioTypeEnumDto.OnAccountBooking
                };
                var orderMock = new Order
                {
                    Id = bookingDto.OrderId
                };

                var bookingManager = new Mock<IBookingManager>();
                var orderManager = new Mock<IOrderManager>();

                orderManager.Setup(o => o.GetByKey(It.Is<int>(i => i == bookingDto.OrderId), It.IsAny<string>())).Returns(orderMock);
                bookingManager.Setup(x => x.CreateBooking(It.IsAny<Booking>(), It.Is<Order>(o => o.Id == orderMock.Id)));

                PropertyManagementSystemService.BookingManager = bookingManager.Object;
                PropertyManagementSystemService.OrderManager = orderManager.Object;

                // Act
                PropertyManagementSystemService.CreateBooking(BUSINESS_ID, bookingDto);

                // Assert
                bookingManager.VerifyAll();
                orderManager.VerifyAll();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
            public void CreateBookingInvalidBusinessIdThrowsValidationException()
            {
                // Arrange
                // businessId that we know will never exist
                const long BUSINESS_ID = -100011110010000;

                var bookingDto = new BookingDto
                {
                    BusinessId = BUSINESS_ID,
                    Guest =
                        new GuestDto { Id = 1, BusinessId = BUSINESS_ID, Surname = "Test Guest", Email = "*****@*****.**" },
                    StartDate = DateTime.Now,
                    EndDate = DateTime.Now.AddDays(1),
                    NumberOfAdults = 2,
                    RoomTypeId = 1,
                    RoomId = 1,
                    RatePlanId = 1,
                    BookingStatusCode = BookingStatusType.TENTATIVE,
                    BookingScenarioType = BookingScenarioTypeEnumDto.OnAccountBooking,
                };

                try
                {
                    // Act
                    PropertyManagementSystemService.CreateBooking(BUSINESS_ID, bookingDto);

                    // Assert
                    Assert.Fail("An exception SRVEX30001 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30001", ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
 public decimal? GetCancellationCharge(BookingDto booking)
 {
     Booking modelBooking = DataTransferObjectsConverter.ConvertBookingDtoToBooking(booking);
     return bookingManager.GetCancellationChargeByBooking(modelBooking);
 }
        public BookingDto ModifyBooking(long businessId, bool forceModify, BookingDto bookingDto)
        {
            // Make sure the current user has access to this business
            CheckAccessRights(bookingDto.BusinessId);
            //Validate that the business exists
            if (Cache.Business.TryGetValue(bookingDto.BusinessId) == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30001, "PropertyManagementSystemService.ModifyBooking", additionalDescriptionParameters: (new object[] { bookingDto.BusinessId })));
            }

            // Validate if the business matches the business on the booking
            if (businessId != bookingDto.BusinessId)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30000, "PropertyManagementSystemService.ModifyBooking", additionalDescriptionParameters: (new object[] { businessId, bookingDto.BusinessId }), arguments: new object[] { businessId, bookingDto }));
            }

            Booking modifyBooking = DataTransferObjectsConverter.ConvertBookingDtoToBooking(bookingDto);
            Booking modifiedBooking = bookingManager.ModifyBooking(forceModify, modifyBooking);

            return modifiedBooking != null ? Mapper.Map<BookingDto>(modifiedBooking) : null;
        }
        public BookingDto CreateBooking(long businessId, BookingDto booking)
        {
            // Make sure the current user has access to this business
            CheckAccessRights(businessId);

            if (Cache.Business.TryGetValue(businessId) == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30001,
                                                                             "PropertyManagementSystemService.CreateBooking",
                                                                             additionalDescriptionParameters:
                                                                                 (new object[] { businessId })));
            }

            // Validate if the business matches the business on the booking
            if (businessId != booking.BusinessId)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30000,
                                                                             "PropertyManagementSystemService.CreateBooking",
                                                                             additionalDescriptionParameters:
                                                                                 (new object[] { businessId, booking.BusinessId }),
                                                                             arguments:
                                                                                 new object[] { businessId, booking }));
            }

            // get the order, if not present throw validation exception
            if (booking.OrderId.HasValue == false)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30018,
                                                                            "PropertyManagementSystemService.CreateBooking",
                                                                             additionalDescriptionParameters:
                                                                                 (new object[] { businessId, booking.BusinessId }),
                                                                             arguments:
                                                                                 new object[] { businessId, booking }));
            }

            Order order = orderManager.GetByKey(booking.OrderId.Value);

            // Convert to Model
            Booking internalBooking = DataTransferObjectsConverter.ConvertBookingDtoToBooking(booking);

            internalBooking.CheckinStatus = new EnumEntity { Code = CheckinStatusOptions.NOTCHECKEDIN };
            
            //Create the booking, order will be present already
            bookingManager.CreateBooking(internalBooking, order);

            if (internalBooking.Id != null)
            {
                // Return the updated bookingDto (make sure to get the full object from database since the BookingReference is only generated in SQL code)
                return Mapper.Map<BookingDto>(bookingManager.GetByKey((int) internalBooking.Id));
            }
            return null;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Converts CancellationDetailDto to CancellationDetail
 /// </summary>
 /// <param name="bookingDto">Booking with the cancellation Details</param>
 /// <returns>CancellationDetailDto</returns>
 public static CancellationDetail ConvertBookingCancellationDetailDtoToModel(BookingDto bookingDto)
 {
     return new CancellationDetail
     {
         CancellationType = Mapper.Map<CancellationTypeEnumDto, CancellationTypeEnum>(bookingDto.CancellationType),
         CancellationChargeType = Mapper.Map<CancellationChargeTypeEnumDto, CancellationChargeTypeEnum>(bookingDto.CancellationChargeType),
         CancellationChargeValue = bookingDto.CancellationChargeValue,
         CancellationCharge = bookingDto.CancellationCharge,
         CancellationWindowHours = bookingDto.CancellationWindowHours,
         DefaultCheckinDateTime = bookingDto.DefaultCheckinDatetime,
         DefaultCheckoutDateTime = bookingDto.DefaultCheckoutDatetime
     };
 }
Exemplo n.º 12
0
 /// <summary>
 /// Converts Booking object to Booking DTO
 /// </summary>
 /// <param name="booking">Booking to convert</param>
 /// <returns>Converted Booking DTO</returns>
 public static Booking ConvertBookingDtoToBooking(BookingDto booking)
 {
     return new Booking
     {
         Id = booking.Id,
         BusinessId = booking.BusinessId,
         BookingReferenceNumber = booking.BookingReferenceNumber,
         StartDate = booking.StartDate,
         EndDate = booking.EndDate,
         NumberOfAdults = booking.NumberOfAdults,
         NumberOfChildren = booking.NumberOfChildren,
         PreCancellationCost = booking.PreCancellationCost,
         Cost = booking.Cost,
         RoomTypeId = booking.RoomTypeId,
         RoomTypeDescription = booking.RoomTypeDescription,
         RoomId = booking.RoomId,
         RatePlanId = booking.RatePlanId,
         CheckinStatus = ConvertCodeAndNameToEnumEntity(booking.CheckinStatusCode),
         EffectiveCheckInDateLT = booking.CheckInDateLT,
         EffectiveCheckOutDateLT = booking.CheckOutDateLT,
         EstimatedTimeOfArrival = booking.EstimatedTimeOfArrival,
         BookingScenarioType = (BookingScenarioTypeEnum)booking.BookingScenarioType,
         Notes = booking.Notes,
         Guest = Mapper.Map<Guest>(booking.Guest),
         BookingStatus = ConvertCodeAndNameToEnumEntity(booking.BookingStatusCode),
         CreatedByUserId = booking.CreatedByUserId,
         CreatedDateTime = booking.CreatedDateTime,
         RateType = ConvertCodeAndNameToEnumEntity(booking.RateTypeCode),
         BoardBasis = EnumExtensions.ParseEnumFromCode<BoardBasisTypeEnum>(booking.BoardBasisCode),
         IsOverBooking = booking.IsOverBooking,
         CancellationDetails = ConvertBookingCancellationDetailDtoToModel(booking),
         IsAvailabilityIgnored = booking.IsAvailabilityIgnored,
         OrderId = booking.OrderId.HasValue ? booking.OrderId.Value : 0,
         Order = booking.Order != null ? ConvertOrderDtoToOrder(booking.Order) : null
     };
 }