public void CheckInCheckOutInValidBookingThrowsValidationException() { // Arrange var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, OrderDao = orderDao.Object }; const int BOOKING_ID = 1; const long BUSINESS_ID = 1; bookingDao.Setup(b => b.GetByKey(BOOKING_ID, It.IsAny<string>())); try { // Act bookingManager.CheckInCheckOutBooking(BOOKING_ID, BUSINESS_ID, CheckinStatusOptions.CHECKEDIN); // Assert Assert.Fail("An exception SRVEX30010 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30010", ex.Code, "The Validation exception is not returning the right error code"); bookingDao.VerifyAll(); // make sure order get isn't called orderDao.Verify(o => o.GetByKey(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>()), Times.Never); } }
public void ModifyExistingBookingWithEndDateEarlierThanStartDateThrowsValidationException() { // Arrange var bookingManager = new BookingManager(); var orderDao = new Mock<IOrderDao>(); bookingManager.OrderDao = orderDao.Object; var guest = new Guest { Surname = "Smith", Id = 1 }; var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, true); //Make sure we set the end date earlier than the start date updatedBooking.EndDate = updatedBooking.StartDate.AddDays(-1); orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = updatedBooking.OrderId }); // ACT try { // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30002 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30002", ex.Code, "The Validation exception SRVEX30002 is not returned"); orderDao.VerifyAll(); } }
public void ModifyBookingWithoutMockingIsSuccessful() { using (new TestDataHelper(TestDataQueriesLimited.PopulateBookingsAndCloseOutsTestData, TestDataQueriesLimited.CleanupTestData)) { // Arrange var serviceWithoutMock = new LimitedMobileService { DisableAccessRightsCheck = true, FakeAuthenticationForDebugging = true }; Cache.Business.Invalidate(); var bookingManager = new BookingManager {BookingDao = new BookingDao()}; var roomsAvailabilityDao = new RoomsAvailabilityDao(); const long BUSINESS_ID = 1; const int BOOKING_ID = 1; const bool FORCE_MODIFY = false; const int ROOM_ID = 1; // Fetch the booking to modify Booking bookingToModify = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID); BookingDto bookingToModifyDto = LimitedDataTransferObjectsConverter.ConvertBookingToDto(bookingToModify); Assert.IsNotNull(bookingToModifyDto, "booking was null after fetch"); // Update Room availability to false because the script PopulateBookingsAndCloseOutsTestData does not update availability roomsAvailabilityDao.UpdateRoomAvailability(bookingToModifyDto.BusinessId, bookingToModifyDto.RoomId, bookingToModifyDto.StartDateUTC, bookingToModifyDto.EndDateUTC, false, new Guid("11111111-1111-1111-1111-111111111111")); // Get availability before Modifying the booking RoomsAvailability roomsAvailabilityBefore = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID, ROOM_ID, bookingToModifyDto.StartDateUTC.Year); // modify start / end date DateTime startDate = bookingToModifyDto.StartDateUTC; DateTime endDate = bookingToModifyDto.EndDateUTC; bookingToModifyDto.StartDateUTC = new DateTime(DateTime.UtcNow.Year + 1, bookingToModifyDto.StartDateUTC.Month, bookingToModifyDto.StartDateUTC.Day); bookingToModifyDto.EndDateUTC = new DateTime(DateTime.UtcNow.Year + 1, bookingToModifyDto.EndDateUTC.Month, bookingToModifyDto.EndDateUTC.Day); DateTime modifiedStartDate = bookingToModifyDto.StartDateUTC; DateTime modifiedEndDate = bookingToModifyDto.EndDateUTC; Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityBefore, startDate.DayOfYear, endDate.DayOfYear), "The rooms for the dates booked are available in the old date range."); // Act bool isSuccess = serviceWithoutMock.ModifyBooking(BUSINESS_ID, FORCE_MODIFY, bookingToModifyDto); // Assert Assert.IsTrue(isSuccess, "Booking is not Modified successfully."); Booking bookingAfterModify = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID); Assert.AreEqual(modifiedStartDate, bookingAfterModify.StartDateUTC, "Booking Start date after modify is incorrect."); Assert.AreEqual(modifiedEndDate, bookingAfterModify.EndDateUTC, "Booking End date after modify is incorrect."); // Check Rooms availability after Modify RoomsAvailability roomsAvailabilityAfter = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID, bookingAfterModify.RoomId, bookingToModifyDto.EndDateUTC.Year); Assert.IsTrue(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, startDate.DayOfYear, modifiedStartDate.DayOfYear), "Make sure availability has changed for the room."); // Check if the rooms are not available for the new range of dates. Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, bookingAfterModify.StartDateUTC.DayOfYear, bookingAfterModify.EndDateUTC.DayOfYear), "The rooms for the dates booked are available."); } }
public void ConfirmProvisionalBookingInvalidRatePlanThrowsValidationException() { // Arrange const int BOOKING_ID = 1; const long BUSINESS_ID = 100011110010000; var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, OrderDao = orderDao.Object }; // Provisional booking with invalid RatePlan var booking = BookingBuilder.SetupSimpleBooking(); booking.RatePlanId = null; var order = new Order { Id = booking.OrderId, OfflineSourceEnum = OfflineSourceEnum.Web, OrderSourceCode = SourceType.Pms.GetCode() }; bookingDao.Setup(b => b.GetByKey(booking.Id.Value, string.Empty)).Returns(booking); orderDao.Setup(o => o.GetByKey(booking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())).Returns(order); try { // Act // Call ConfirmProvisionalBooking method on BookingManager bookingManager.ConfirmTentativeBooking(BOOKING_ID, BUSINESS_ID); // Assert Assert.Fail("An exception SRVEX30008 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30008", ex.Code, "The exception code thrown is not the expected."); orderDao.VerifyAll(); bookingDao.VerifyAll(); } }
public void ConfirmProvisionalBookingWithoutBookingReferenceNumberThrowsValidationException() { // Arrange const int BOOKING_ID = 1; const long BUSINESS_ID = 100011110010000; var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, OrderDao = orderDao.Object }; // Provisional booking without BookingReferenceNumber var booking = BookingBuilder.SetupSimpleBooking(); booking.BookingReferenceNumber = null; var order = new Order { Id = booking.OrderId }; bookingDao.Setup(b => b.GetByKey(BOOKING_ID, It.IsAny<string>())).Returns(booking); orderDao.Setup(o => o.GetByKey(booking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())).Returns(order); try { // Act // Call ConfirmProvisionalBooking method on BookingManager bookingManager.ConfirmTentativeBooking(BOOKING_ID, BUSINESS_ID); // Assert Assert.Fail("An exception SRVEX30030 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30030", ex.Code, "The exception code thrown is not the expected."); } }
public void ConfirmProvisionalBookingValidBookingDoesNotThrowException() { // Arrange const int BOOKING_ID = 1; const long BUSINESS_ID = 100011110010000; var bookingDao = MockRepository.GenerateMock<IBookingDao>(); var orderDao = MockRepository.GenerateMock<IOrderDao>(); var notificationManager = MockRepository.GenerateMock<INotificationManager>(); CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID); // Invalidate the cache so we make sure our business is loaded into the cache Cache.Business.Invalidate(); var bookingManager = new BookingManager { BookingDao = bookingDao, OrderDao = orderDao, NotificationManager = notificationManager }; var booking = BookingBuilder.SetupSimpleBooking(); booking.BookingScenarioType = BookingScenarioTypeEnum.PayOnArrival; booking.BusinessId = BUSINESS_ID; bookingDao.Expect(b => b.GetByKey(Arg<int>.Is.Equal(booking.Id), Arg<string>.Is.Anything)).Return(booking); bookingDao.Expect(c => c.ConfirmBooking(Arg<int>.Is.Equal(booking.Id), Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)); notificationManager.Expect( n => n.AddPoaNotificationMessage(Arg<long>.Is.Equal(BUSINESS_ID), Arg<Booking>.Is.Equal(booking), Arg<string>.Is.Anything)); notificationManager.Expect( n => n.AddCollectPoaNotificationMessage(Arg<long>.Is.Equal(BUSINESS_ID), Arg<Booking>.Is.Equal(booking), Arg<string>.Is.Anything)); // Act // Call ConfirmProvisionalBooking method on BookingManager bookingManager.ConfirmTentativeBooking(BOOKING_ID, BUSINESS_ID); // Assert bookingDao.VerifyAllExpectations(); orderDao.VerifyAllExpectations(); notificationManager.VerifyAllExpectations(); CacheHelper.ReAssignBusinessDaoToBusinessCache(); }
public void CreateBookingWithInvalidRateTypeThrowsValidationException() { // Arrange var bookingManager = new BookingManager(); var booking = new Booking { BusinessId = 1, Guest = new Guest {Id = 23, 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), BookingStatus = new EnumEntity {Code = BookingStatusType.CONFIRMED}, RoomTypeId = 1, RoomId = 1, RatePlanId = 1, Notes = "Testing note", RateType = new EnumEntity {Code = "BAD"}, BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking }; var order = new Order { OfflineSourceEnum = OfflineSourceEnum.Web, Id = booking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), CustomerCurrencyCode = "GBP" }; try { // Act bookingManager.CreateBooking(booking, order); // Assert Assert.Fail("An exception of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30046", ex.Code, "The Validation exception is not returning the right error code"); } }
public void GetByKeyWithValidBookingIdReturnsValidBooking() { // Arrange const int BOOKING_ID = 1; const int ORDER_ID = 1; var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, OrderDao = orderDao.Object }; var bookingReturnedByDao = BookingBuilder.SetupSimpleBooking(isTentative: false); var order = new Order { Id = ORDER_ID }; bookingDao.Setup(b => b.GetByKey(BOOKING_ID, It.IsAny<string>())).Returns(bookingReturnedByDao); orderDao.Setup(o => o.GetByKey(bookingReturnedByDao.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())).Returns(order); // Act var bookingReturnedByManager = bookingManager.GetByKey(BOOKING_ID); // Assert Assert.IsNotNull(bookingReturnedByManager, "Booking is null."); Assert.AreEqual(bookingReturnedByDao, bookingReturnedByManager, "Booking returned is not correct."); bookingDao.VerifyAll(); orderDao.VerifyAll(); }
public void GetByRoomExpectSuccess() { // Arrange const int BUSINESS_ID = 1; const int ROOM_ID = 1; var bookingManager = new BookingManager(); var bookingReturnedByDao = new Booking { Id = 1, BusinessId = BUSINESS_ID, BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking, BookingStatus = new EnumEntity { Code = BookingStatusType.CONFIRMED }, Guest = new Guest(), RoomId = ROOM_ID, RoomTypeId = 1, RatePlanId = 1, Cost = new decimal(10), StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddDays(1), NumberOfAdults = 1 }; var bookingDao = MockRepository.GenerateMock<IBookingDao>(); bookingManager.BookingDao = bookingDao; bookingDao.Stub(b => b.GetByRoom(ROOM_ID)).Return(new List<Booking>{bookingReturnedByDao}); // Act var bookingsReturnedByManager = bookingManager.GetByRoom(ROOM_ID); // Assert Assert.IsNotNull(bookingsReturnedByManager, "Booking is null."); Assert.AreEqual(bookingReturnedByDao, bookingsReturnedByManager[0], "Bookings returned is incorrect."); }
public void ModifyBookingToCancelledStateThrowsValidationException() { // Arrange var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { OrderDao = orderDao.Object }; var guest = new Guest { Surname = "Smith", Id = 1 }; var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, true); //Make it a cancelled booking updatedBooking.BookingStatus = new EnumEntity { Code = BookingStatusType.CANCELLED }; orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = updatedBooking.OrderId }); // ACT try { // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30040 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30040", ex.Code, "The Validation exception SRVEX30040 is not returned"); orderDao.VerifyAll(); } }
public void ModifyBookingWithInvalidRateTypeThrowsValidationException() { // Arrange var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { OrderDao = orderDao.Object }; var guest = new Guest { Surname = "Smith", Id = 1 }; var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, true); //Update the rate type updatedBooking.RateType = new EnumEntity {Code = "BAD"}; orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = updatedBooking.OrderId }); try { // Act bookingManager.ModifyBooking(true, updatedBooking); // Assert Assert.Fail("An exception of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30046", ex.Code, "The Validation exception is not returning the right error code"); orderDao.VerifyAll(); } }
public void ModifyExistingBookingThatIsCancelledThrowsValidationException() { // Arrange var bookingDao = new Mock<IBookingDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object }; var orderDao = new Mock<IOrderDao>(); bookingManager.OrderDao = orderDao.Object; var guest = new Guest { Surname = "Smith", Id = 1 }; var originalBooking = BookingBuilder.SetupSimpleBooking(guest, false); originalBooking.BookingStatus = new EnumEntity { Code = BookingStatusType.CANCELLED }; bookingDao.Setup(b => b.GetByKey(1, "")).Returns(originalBooking); var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, false); orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order {Id = updatedBooking.OrderId}); //Make a simple edit of days changing updatedBooking.StartDate = updatedBooking.StartDate.AddDays(-1); // ACT try { // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30040 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30040", ex.Code, "The Validation exception SRVEX30040 is not returned"); bookingDao.VerifyAll(); orderDao.VerifyAll(); } }
public void ModifyExistingWLSBookingReducingCostThrowsException() { // Arrange var bookingManager = new BookingManager(); var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); bookingManager.BookingDao = bookingDao.Object; bookingManager.OrderDao = orderDao.Object; var guest = new Guest { Surname = "Smith", Id = 1 }; var originalBooking = BookingBuilder.SetupSimpleBooking(guest, false); originalBooking.CancellationDetails.CancellationType = CancellationTypeEnum.NonRefundable; var updatedBooking = originalBooking.Clone(); bookingDao.Setup(b => b.GetByKey(originalBooking.Id.Value, It.IsAny<string>())).Returns(originalBooking); orderDao.Setup(o => o.GetByKey(originalBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = originalBooking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), IntegrationType = IntegrationTypeEnum.WhiteLabel }); // Act try { updatedBooking.Cost = 5; // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30145 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30145", ex.Code, "The Validation exception SRVEX30145 is not returned"); orderDao.VerifyAll(); } }
public void ModifyExistingOTABookingThrowsValidationException() { // Arrange var bookingManager = new BookingManager(); var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); bookingManager.BookingDao = bookingDao.Object; bookingManager.OrderDao = orderDao.Object; var guest = new Guest { Surname = "Smith", Id = 1 }; var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, false); bookingDao.Setup(b => b.GetByKey(updatedBooking.Id.Value, It.IsAny<string>())).Returns(updatedBooking); orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = updatedBooking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), IntegrationType = IntegrationTypeEnum.RequestResponse }); // Act try { updatedBooking.RoomTypeId = 999; // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30133 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30133", ex.Code, "The Validation exception SRVEX30133 is not returned"); orderDao.VerifyAll(); } }
public void ProcessAllBookingsByCheckInDateAndChannelScenarioIsSuccessful() { const BookingScenarioTypeEnum CHANNEL_SCENARIO = BookingScenarioTypeEnum.VPayment; const string EVENT_NOTES = "Auto generated notes"; const int BOOKING_ID = 1; var checkinDate = DateTime.Today; var bookingDao = new Mock<IBookingDao>(); var eventTrackingManager = new Mock<IEventTrackingManager>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, EventTrackingManager = eventTrackingManager.Object }; var bookingIds = new List<int> { 1 }; bookingDao.Setup(b => b.GetBookingIdsByCheckInDateAndChannelScenario(It.Is<DateTime>(i => i == checkinDate), It.Is<BookingScenarioTypeEnum>(i => i == CHANNEL_SCENARIO))).Returns(bookingIds); eventTrackingManager.Setup( e => e.CreateBookingEvent(It.Is<int>(i => i == BOOKING_ID), It.Is<BookingEventType>(i => i == BookingEventType.Modified), It.Is<string>(i => i == EVENT_NOTES))); var processCount = bookingManager.ProcessAllBookingsByCheckInDateAndChannelScenario(checkinDate, CHANNEL_SCENARIO, EVENT_NOTES); Assert.AreEqual(1, processCount, "Invalid number of bookings processed"); bookingDao.VerifyAll(); eventTrackingManager.VerifyAll(); }
public void GetByRoomWithInValidRoomIdReturnsNull() { // Arrange const int ROOM_ID = 1; var bookingManager = new BookingManager(); var bookingDao = MockRepository.GenerateMock<IBookingDao>(); bookingManager.BookingDao = bookingDao; bookingDao.Stub(b => b.GetByKey(ROOM_ID)).Return(null); // Act var bookingsReturnedByManager = bookingManager.GetByRoom(ROOM_ID); // Assert Assert.IsNull(bookingsReturnedByManager, "Bookings is not null."); }
public void ViewCcDetailsIsSuccessful() { // Arrange var bookingManager = new BookingManager(); var eventTrackingManager = new Mock<IEventTrackingManager>(); //Check if the message is trying to be saved (create an event with the booking id, type cc viewed and message that is something like"user with username has seen the cc details for booking id blahblah") eventTrackingManager.Setup(b => b.CreateBookingEvent(It.Is<int>(i => i == BOOKING_ID), It.Is<BookingEventType>(i => i == BookingEventType.CcTokenViewed), It.IsRegex(string.Format("{1}{0}{1}", BOOKING_ID, ANYTHING)))); bookingManager.EventTrackingManager = eventTrackingManager.Object; // Act bookingManager.ViewCcDetails(BOOKING_ID); // Assert eventTrackingManager.VerifyAll(); }
public void AcceptBookingRecordsEventWithCorrectBookingId() { // Arrange const int BOOKING_ID = 123; var eventTrackingManager = new Mock<IEventTrackingManager>(); eventTrackingManager.Setup(b => b.CreateBookingEvent(It.Is<int>(i => i == BOOKING_ID), It.Is<BookingEventType>(i => i == BookingEventType.Accepted), It.IsAny<string>())); var bookingManager = new BookingManager { EventTrackingManager = eventTrackingManager.Object }; // Act bookingManager.AcceptBooking(BOOKING_ID); // Assert eventTrackingManager.VerifyAll(); }
public void CreateBookingWithSendConfirmationEmailUncheckedDoesNotEmailConfirmation() { // Arrange var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var emailManager = new Mock<IEmailManager>(); var guestManager = new Mock<IGuestManager>(); var cancellationPoliciesManager = new Mock<ICancellationPoliciesManager>(); var bookingManager = new BookingManager { EmailManager = emailManager.Object, BookingDao = bookingDao.Object, OrderDao = orderDao.Object, GuestManager = guestManager.Object, CancellationPoliciesManager = cancellationPoliciesManager.Object }; var booking = new Booking { BusinessId = 1, OrderId = 1, Guest = new Guest { Id = 23, Surname = "Test Guest", Email = "*****@*****.**", IsConfirmationEmailToBeSent = false }, 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), BookingStatus = new EnumEntity { Code = BookingStatusType.CONFIRMED }, RoomTypeId = 1, RoomId = 1, RatePlanId = 1, Notes = "Testing note", BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking, RateType = new EnumEntity { Code = RateType.BEST_AVAILABLE_RATE } }; var order = new Order { OfflineSourceEnum = OfflineSourceEnum.Web, Id = booking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), CustomerCurrencyCode = "GBP" }; bookingDao.Setup(b => b.Create(booking, order)).Callback(delegate { booking.Id = 1; }); cancellationPoliciesManager.Setup(cm => cm.GetRatePlanCancellationRule(It.IsAny<CancellationPolicyRequest>(), booking.RatePlanId)).Returns(new CancellationRule()); // Act bookingManager.CreateBooking(booking, order); // Assert bookingDao.VerifyAll(); orderDao.VerifyAll(); emailManager.Verify(e => e.SendConfirmationEmails(It.IsAny<Order>()), Times.Never()); }
public void ModifyBookingNoteRecordsEventWithCorrectBookingId() { // Arrange const int BOOKING_ID = 123; const string BOOKING_NOTE = "Test123"; var bookingDao = new Mock<IBookingDao>(); var eventTrackingManager = new Mock<IEventTrackingManager>(); bookingDao.Setup(b => b.ModifyBookingNote(It.Is<int>(i => i == BOOKING_ID), It.Is<string>(i => i == BOOKING_NOTE))).Returns(true); eventTrackingManager.Setup(b => b.CreateBookingEvent(It.Is<int>(i => i == BOOKING_ID), It.Is<BookingEventType>(i => i == BookingEventType.Modified), It.IsAny<string>())); var bookingManager = new BookingManager { EventTrackingManager = eventTrackingManager.Object, BookingDao = bookingDao.Object }; // Act var status = bookingManager.ModifyBookingNote(BOOKING_ID, BOOKING_NOTE); // Assert Assert.IsTrue(status, "Booking Note was not updated"); bookingDao.VerifyAll(); eventTrackingManager.VerifyAll(); }
public void CreateBookingNoEmailAndSendConfirmationEmailCheckedThrowsValidationException() { // Arrange var bookingManager = new BookingManager { BookingDao = MockRepository.GenerateStub<IBookingDao>() }; var booking = new Booking { BusinessId = 1, OrderId = 1, Guest = new Guest { Id = 23, Surname = "Test Guest", IsConfirmationEmailToBeSent = true }, 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), BookingStatus = new EnumEntity { Code = BookingStatusType.CONFIRMED }, RoomTypeId = 1, RoomId = 1, RatePlanId = 1, Notes = "Testing note", RateType = new EnumEntity { Code = "BAR" }, BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking }; var order = new Order { OfflineSourceEnum = OfflineSourceEnum.Web, Id = booking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), CustomerCurrencyCode = "GBP" }; try { // Act bookingManager.CreateBooking(booking, order); // Assert Assert.Fail("An exception of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30110", ex.Code, "The Validation exception is not returning the right error code"); } }
public void GetBookingFeesWithValidOrderExpectBookingDaoCalled() { //Arrange const int ORDER_ID = 1; const string CULTURE_CODE = "en-GB"; var bookingFees = new List<BookingFee> { new BookingFee { ItemTypeCode = ItemTypeEnum.RoomNight }, new BookingFee { ItemTypeCode = ItemTypeEnum.Dinner } }; var bookingManager = new BookingManager(); var bookingDao = new Mock<IBookingDao>(); bookingManager.BookingDao = bookingDao.Object; bookingDao.Setup(b => b.GetBookingFees(ORDER_ID, CULTURE_CODE)).Returns(bookingFees); // Act var bookingFeesReturned = bookingManager.GetBookingFees(ORDER_ID, CULTURE_CODE); // Assert Assert.IsNotNull(bookingFeesReturned, "BookingFees are null."); Assert.AreEqual(bookingFees, bookingFeesReturned, "BookingFees return are not correct."); bookingDao.VerifyAll(); }
public void ConfirmProvisionalBookingValidNonOtaBookingSendsConfirmEmail() { // Arrange const int BOOKING_ID = 1; const long BUSINESS_ID = 100011110010000; var bookingDao = MockRepository.GenerateMock<IBookingDao>(); var orderDao = MockRepository.GenerateMock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao, OrderDao = orderDao }; var booking = BookingBuilder.SetupSimpleBooking(); bookingDao.Expect(b => b.GetByKey(Arg<int>.Is.Equal(booking.Id), Arg<string>.Is.Anything)).Return(booking); bookingDao.Expect(c => c.ConfirmBooking(Arg<int>.Is.Equal(booking.Id), Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)); // Act // Call ConfirmProvisionalBooking method on BookingManager bookingManager.ConfirmTentativeBooking(BOOKING_ID, BUSINESS_ID); // Assert bookingDao.VerifyAllExpectations(); orderDao.VerifyAllExpectations(); }
public void CreateBookingInvalidStartEndDateThrowsValidationException() { // Arrange var bookingDao = new Mock<IBookingDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object }; var booking = new Booking { OrderId = 5, BusinessId = 1, Guest = new Guest { Id = 23, Surname = "Test Guest", Email = "*****@*****.**" }, StartDate = new DateTime(2012, 2, 2, 0, 0, 0, DateTimeKind.Utc), EndDate = new DateTime(2012, 2, 1, 0, 0, 0, DateTimeKind.Utc), NumberOfAdults = 2, NumberOfChildren = 1, Cost = new decimal(120.5), BookingStatus = new EnumEntity { Code = BookingStatusType.CONFIRMED }, RoomTypeId = 1, RoomId = 1, RatePlanId = 1, Notes = "Testing note", BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking }; var order = new Order { OfflineSourceEnum = OfflineSourceEnum.Web, Id = booking.OrderId, OrderSourceCode = SourceType.Online.GetCode(), CustomerCurrencyCode = "GBP" }; bookingManager.BookingDao = bookingDao.Object; try { // Act bookingManager.CreateBooking(booking, order); // Assert Assert.Fail("An exception SRVEX30002 of type ValidationException should have been thrown"); } catch (ValidationException ex) { // Assert Assert.AreEqual("SRVEX30002", ex.Code, "The Validation exception is not returning the right error code"); bookingDao.Verify(b => b.Create(booking, order), Times.Never); } // Make sure this is reset for future tests bookingManager.BookingDao = new BookingDao(); }
public void CheckInCheckOutValidBookingReturnsUpdatedBooking() { // Arrange var bookingDao = new Mock<IBookingDao>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, OrderDao = orderDao.Object }; var booking = BookingBuilder.SetupSimpleBooking(); booking.BookingStatus = new EnumEntity {Code = BookingStatusType.CONFIRMED}; booking.CheckinStatus = new EnumEntity {Code = CheckinStatusOptions.CHECKEDIN}; booking.BookingScenarioType = BookingScenarioTypeEnum.OnAccountBooking; var order = new Order { Id = booking.OrderId, OfflineSourceEnum = OfflineSourceEnum.Web, OrderSourceCode = SourceType.Pms.GetCode() }; bookingDao.Setup(b => b.GetByKey(booking.Id.Value, string.Empty)).Returns(booking); orderDao.Setup(o => o.GetByKey(booking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())).Returns(order); bookingDao.Setup(b => b.CheckInCheckOutBooking(It.Is<Booking>(book => book == booking), It.Is<EnumEntity>(ee => ee.Code == CheckinStatusOptions.CHECKEDIN), It.IsAny<string>())).Returns(booking); // Act Booking updatedBooking = bookingManager.CheckInCheckOutBooking(1, 1, CheckinStatusOptions.CHECKEDIN); // Assert Assert.AreEqual(CheckinStatusOptions.CHECKEDIN, updatedBooking.CheckinStatus.Code, "Check in status of the booking is not updated as expected."); bookingDao.VerifyAll(); orderDao.VerifyAll(); }
public void RequestCancelNonExistentBooking_ExpectExceptionThrown() { // Arrange var bookingManager = new BookingManager(); var requestCancelBooking = new RequestCancelBooking() {BookingId = -1}; try { // Act bookingManager.RequestCancelBooking(requestCancelBooking, new Booking()); // Assert Assert.Fail("An exception SRVEX30095 of type ValidationException should have been thrown"); } catch (ExpectedResultException ex) { // Assert Assert.AreEqual("SRVEX30095", ex.Code, "The exception code thrown is not the expected."); } }
/// <summary> /// default, assumes null for existing booking manager /// </summary> public AvailabilityManager() { bookingManager = new BookingManager(existingAvailabilityManager: this); }
public void RequestCancelExistingBookingIsSuccessful() { // Arrange var bookingDao = new Mock<IBookingDao>(); var emailManagerMock = new Mock<IEmailManager>(); var orderDao = new Mock<IOrderDao>(); var bookingManager = new BookingManager { BookingDao = bookingDao.Object, EmailManager = emailManagerMock.Object, OrderDao = orderDao.Object }; var requestCancelBooking = new RequestCancelBooking { BookingId = 1, BusinessContactedGuest = true, CancellationRequestAction = CancellationRequestAction.ChargedFullBookingValue, CancellationRequestReason = CancellationReasonEnum.CardDeclined, Notes = "unit test notes" }; var order = new Order { Id = 1, OrderSourceCode = SourceType.Online.GetCode(), IntegrationType = IntegrationTypeEnum.Push }; orderDao.Setup(o => o.GetByKey(It.Is<int>(i => i == order.Id), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())).Returns(order); bookingDao.Setup(c => c.RequestCancelBooking(requestCancelBooking)).Returns(true); emailManagerMock.Setup(e => e.SendCancellationRequestEmail(requestCancelBooking, It.IsAny<Booking>(), It.Is<Order>(o => o.Id == order.Id))).Returns(true); //Act bookingManager.RequestCancelBooking(requestCancelBooking, new Booking { Id = 1, OrderId = 1 }); // Assert bookingDao.VerifyAll(); emailManagerMock.VerifyAll(); orderDao.VerifyAll(); }
public void CancelBookingWithoutMockingIsSuccessful() { using (new TestDataHelper(TestDataQueriesLimited.PopulateCheckInCheckOutBookingTestData, TestDataQueriesLimited.CleanupTestData)) { // Arrange var serviceWithoutMock = new LimitedMobileService { DisableAccessRightsCheck = true, FakeAuthenticationForDebugging = true }; var bookingManager = new BookingManager {BookingDao = new BookingDao()}; var roomsAvailabilityDao = new RoomsAvailabilityDao(); const long BUSINESS_ID = 11111; const int BOOKING_ID = 1; const bool USER_OPTION_TO_REFUND = false; DateTime startDate = DateTime.Now; DateTime endDate = DateTime.Now.AddDays(1); const int ROOM_ID = 1; // Update Room availability to false because the script PopulateCheckInCheckOutBookingTestData does not update availability roomsAvailabilityDao.UpdateRoomAvailability(BUSINESS_ID, ROOM_ID, startDate, endDate, false, new Guid("11111111-1111-1111-1111-111111111111")); // Get availability before cancelling the booking RoomsAvailability roomsAvailabilityBefore = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID, ROOM_ID, startDate.Year); Assert.IsFalse(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityBefore, startDate.DayOfYear, endDate.DayOfYear), "The rooms for the dates booked are available."); // TODO UPDATE THIS TO REFERENCE THE NEW AUDITING DAO AND METHODS ONCE THE NEW AUDITING HAS BEEN IMPLEMENTED // Check Audit records before cancellation // Search recent tables. Recent tables hold information temporarily until AuditServiceTask service can pick it up and move it to the history table //List<BookingRecordAudit> auditRecordsBeforeCancellation = auditDao.GetAllForRecentTable(0); //if (auditRecordsBeforeCancellation.Count == 0) //{ // auditRecordsBeforeCancellation = auditDao.GetAllForRecentTable(1); //} //Assert.AreNotEqual(0, auditRecordsBeforeCancellation.Count, "There are no booking audit records created in the database."); //// Get audit records related to update. AuditActionTypeId = 2 indicates update. //List<BookingRecordAudit> auditRecordsBeforeCancellationSpecificToBooking = // auditRecordsBeforeCancellation.FindAll(b => b.BookingReferenceNumber == "REF0001" && b.AuditActionTypeId == 2); //Assert.AreEqual(0, auditRecordsBeforeCancellationSpecificToBooking.Count, "Booking audit records for cancellation should be null."); // Act bool isSuccess = serviceWithoutMock.CancelBooking(BUSINESS_ID, BOOKING_ID, USER_OPTION_TO_REFUND); // Assert Assert.IsTrue(isSuccess, "Booking is not cancelled successfully."); Booking bookingAfterCancellation = bookingManager.GetByKey(BOOKING_ID, BUSINESS_ID); Assert.AreEqual(BookingStatusType.Cancelled, bookingAfterCancellation.BookingStatus, "Booking Status after cancelling is incorrect."); Assert.IsTrue(bookingAfterCancellation.IsCancelled, "The booking is not yet cancelled."); // Check Rooms availability after cancellation RoomsAvailability roomsAvailabilityAfter = roomsAvailabilityDao.GetByRoomIdAndYear(BUSINESS_ID, bookingAfterCancellation.RoomId, DateTime.UtcNow.Year); Assert.IsFalse(RoomAvailabilityHelper.IsAvailabilityTheSame(roomsAvailabilityBefore, roomsAvailabilityAfter), "Make sure availability has changed for the room."); // Check if the rooms are available again. Assert.IsTrue(RoomAvailabilityHelper.AreAllRoomsInRangeAvailable(roomsAvailabilityAfter, bookingAfterCancellation.StartDateUTC.DayOfYear, bookingAfterCancellation.EndDateUTC.DayOfYear), "The rooms for the dates booked are unavailable."); // TODO UPDATE THIS TO REFERENCE THE NEW AUDITING DAO AND METHODS ONCE THE NEW AUDITING HAS BEEN IMPLEMENTED // Audit table should be updated to record cancellation event. // Search recent tables. Recent tables hold information temporarily until AuditServiceTask service can pick it up and move it to the history table //List<BookingRecordAudit> auditRecordsAfterCancellation = auditDao.GetAllForRecentTable(0); //if(auditRecordsAfterCancellation.Count == 0) //{ // auditRecordsAfterCancellation = auditDao.GetAllForRecentTable(1); //} //Assert.AreNotEqual(0, auditRecordsAfterCancellation.Count, "There are no booking audit records created in the database."); //// Get audit records related to update. AuditActionTypeId = 2 indicates update. //List<BookingRecordAudit> auditRecordsAfterCancellationSpecificToBooking = // auditRecordsAfterCancellation.FindAll(b => b.BookingReferenceNumber == "REF0001" && b.AuditActionTypeId == 2); //Assert.IsNotNull(auditRecordsAfterCancellationSpecificToBooking, "Booking audit records for cancellation is null."); //Assert.AreNotEqual(0, auditRecordsAfterCancellationSpecificToBooking.Count, "Total number of booking audit records created in the database for the cancelled booking is incorrect."); //foreach (BookingRecordAudit bookingRecordAudit in auditRecordsAfterCancellationSpecificToBooking) //{ // // Check OldIsCancelled field // Assert.IsNotNull(bookingRecordAudit.OldIsCancelled, "OldIsCancelled field should have a value."); // Assert.IsFalse(bookingRecordAudit.OldIsCancelled.Value, "OldIsCancelled field should be false."); // // Check IsCancelled field // Assert.IsNotNull(bookingRecordAudit.IsCancelled, "IsCancelled field should have a value."); // Assert.IsTrue(bookingRecordAudit.IsCancelled.Value, "IsCancelled field should be true."); // // Check if UpdatedByUserId and LastUpdatedDateTimeUTC fields are updated correctly. // Assert.AreNotEqual(Guid.Empty, bookingRecordAudit.UpdatedByUserId, "UpdatedByUserId field should have a value."); // Assert.AreNotEqual(DateTime.MinValue, bookingRecordAudit.LastUpdatedDateTimeUTC, "LastUpdatedDateTimeUTC field should be true."); //} } }
public void ModifyExistingBookingWithNoIdThrowsValidationException() { // Arrange var bookingManager = new BookingManager(); var orderDao = new Mock<IOrderDao>(); bookingManager.OrderDao = orderDao.Object; var guest = new Guest { Surname = "Smith", Id = 1 }; var updatedBooking = BookingBuilder.SetupSimpleBooking(guest, true); updatedBooking.Id = null; orderDao.Setup(o => o.GetByKey(updatedBooking.OrderId, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<GetOrderWithBookingsByEnum>())) .Returns(new Order { Id = updatedBooking.OrderId }); // ACT try { // Modify booking Record bookingManager.ModifyBooking(false, updatedBooking); //Assert Assert.Fail("exception SRVEX30041 of type ValidationException should have been thrown"); } catch (ValidationException ex) { Assert.AreEqual("SRVEX30041", ex.Code, "The Validation exception SRVEX30041 is not returned"); orderDao.VerifyAll(); } }