Esempio n. 1
0
        /// <summary>
        /// Create BookingEvent
        /// </summary>
        public void Create(BookingEvent bookingEvent)
        {
            var createdByUserId = AuditFieldsHelper.GetUserId();
            var bookingEventId = new StoredProcedures.Booking.InsertBookingEventMapper().Execute(bookingEvent, createdByUserId);

            bookingEvent.Id = bookingEventId;
        }
Esempio n. 2
0
        /// <summary>
        /// Create a booking event
        /// </summary>
        /// <param name="bookingId">Id of Booking</param>
        /// <param name="eventType">Event Type</param>
        /// <param name="notes">Notes for event</param>
        public void CreateBookingEvent(int bookingId, BookingEventType eventType, string notes = null)
        {
            var bookingEvent = new BookingEvent
            {
                BookingId = bookingId,
                EventType = new EnumEntity { Code = eventType.GetCode() },
                Notes = notes
            };

            bookingEventDao.Create(bookingEvent);
        }
Esempio n. 3
0
        public int Execute(BookingEvent bookingEvent, Guid createdByUserId)
        {
            // in parameters
            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(Parameters.BookingId, bookingEvent.BookingId),
                DbHelper.CreateParameter(Parameters.BookingEventTypeCode, bookingEvent.EventType.Code),
                DbHelper.CreateParameter(Parameters.Reference, bookingEvent.Reference),
                DbHelper.CreateParameter(Parameters.Notes, bookingEvent.Notes),
                DbHelper.CreateParameter(Parameters.CreatedByUserId, createdByUserId)
            };

            // out parameters
            SqlParameter id;
            parameters.Add(id = DbHelper.CreateParameterOut<int>(OutParameters.Id, SqlDbType.Int));

            DbHelper.ExecuteNonQueryCommand(this, parameters);

            return DbHelper.ParameterValue<int>(id);
        }
Esempio n. 4
0
            public void CreateTransactionModelForInvoiceRequestReturnsTransactionModelCorrectly()
            {
                #region Arrange

                // Arrange
                IBookingDao bookingDaoMock = MockRepository.GenerateMock<IBookingDao>();
                IBusinessDao businessDaoMock = MockRepository.GenerateMock<IBusinessDao>();
                IOrderDao orderDaoMock = MockRepository.GenerateMock<IOrderDao>();
                IOrderReferenceDao orderReferenceMock = MockRepository.GenerateMock<IOrderReferenceDao>();
                IChannelDao channelDaoMock = MockRepository.GenerateMock<IChannelDao>();
                ICountryDao countryDaoMock = MockRepository.GenerateMock<ICountryDao>();
                IBookingEventDao bookingEventDaoMock = MockRepository.GenerateMock<IBookingEventDao>();
                IBookingEventDataDao bookingEventDataDaoMock = MockRepository.GenerateMock<IBookingEventDataDao>();
                IBookingItemDao bookingItemDaoMock = MockRepository.GenerateMock<IBookingItemDao>();
                IPaymentEventDao paymentEventDaoMock = MockRepository.GenerateMock<IPaymentEventDao>();
                IPaymentDao paymentDaoMock = MockRepository.GenerateMock<IPaymentDao>();
                ISettlementHelper settlementHelperMock = MockRepository.GenerateMock<ISettlementHelper>();

                bool forceProcess = true;

                Booking bookingMock = new Booking
                                          {
                                              Id = GOOD_BOOKING_ID,
                                              OrderId = GOOD_ORDER_ID,
                                              BusinessId = GOOD_BUSINESS_ID,
                                              BookingReferenceNumber = GOOD_BOOKING_REF
                                          };

                Model.Business.Business businessMock = new Model.Business.Business
                                                           {
                                                               Id = GOOD_BUSINESS_ID
                                                           };

                Order orderMock = new Order
                                      {
                                          Id = GOOD_ORDER_ID,
                                          Bookings = new List<Model.Booking.Booking> {bookingMock},
                                          ChannelId = GOOD_CHANNEL_ID
                                      };

                Channel channelMock = new Channel
                                          {
                                              Id = GOOD_CHANNEL_ID,
                                              DistributorId = GOOD_CHANNEL_BUSINESS_ID
                                          };

                Model.Business.Business channelBusinessMock = new Model.Business.Business
                                                                  {
                                                                      Id = GOOD_CHANNEL_BUSINESS_ID
                                                                  };

                Country countryMock = new Country
                                          {
                                              Id = GOOD_COUNTRY_ID,
                                              IsoChar2Code = UK_COUNTRY_CODE
                                          };

                BookingEvent bookingEventMock = new BookingEvent
                                                    {
                                                        Id = GOOD_EVENT_ID,
                                                        BookingId = GOOD_BOOKING_ID
                                                    };
                List<BookingEventData> bookingEventDataMock = new List<BookingEventData>();
                var bookingPaymentMock = new Model.Booking.Payment
                                                 {
                                                     Id = GOOD_PAYMENT_ID
                                                 };

                var paymentListMock = new List<Model.Booking.Payment> { bookingPaymentMock };

                List<BookingItem> bookingItemMock = new List<BookingItem>();
                List<PaymentEvent> paymentEventListMock = new List<PaymentEvent>();
                List<SettlementPaymentDto> settlementPaymentDtosMock = new List<SettlementPaymentDto>();

                bookingDaoMock.Expect(bd => bd.GetByKey(Arg<int>.Is.Equal(GOOD_BOOKING_ID), Arg<string>.Is.Anything)).Return(bookingMock).Repeat.Never();
                businessDaoMock.Expect(bu => bu.GetByKey(Arg<long>.Is.Equal(bookingMock.BusinessId), Arg<string>.Is.Equal(string.Empty))).Return(businessMock).Repeat.Once();
                orderDaoMock.Expect(od => od.GetOrderWithBookingsByKey(Arg<int>.Is.Equal(GOOD_ORDER_ID), Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<GetOrderWithBookingsByEnum>.Is.Equal(GetOrderWithBookingsByEnum.Id))).Return(orderMock).Repeat.Once();
                orderReferenceMock.Expect(
                    or =>
                    or.GetByOrderIdAndReferenceType(Arg<int>.Is.Equal(GOOD_ORDER_ID),
                                                    Arg<ReferenceTypeEnum>.Is.Equal(ReferenceTypeEnum.EcommerceReservation)))
                                  .Return(null)
                                  .Repeat.Once();
                channelDaoMock.Expect(cd => cd.GetById(Arg<int>.Is.Equal(orderMock.ChannelId.Value)))
                    .Return(channelMock)
                    .Repeat.Once();

                businessDaoMock.Expect(bu => bu.GetByKey(Arg<long>.Is.Equal(channelMock.DistributorId.Value), Arg<string>.Is.Equal(string.Empty)))
                    .Return(channelBusinessMock)
                    .Repeat.Once();
                countryDaoMock.Expect(cod => cod.GetByBusiness(Arg<long>.Is.Equal(bookingMock.BusinessId)))
                    .Return(countryMock)
                    .Repeat.Once();

                bookingEventDaoMock.Expect(bed => bed.GetByKey(GOOD_EVENT_ID)).Return(bookingEventMock).Repeat.Once();
                bookingEventDataDaoMock.Expect(bedd => bedd.GetAllByEventId(Arg<int>.Is.Equal(bookingEventMock.Id)))
                    .Return(bookingEventDataMock)
                    .Repeat.Once();

                paymentDaoMock.Expect(pd => pd.GetPaymentsByOrder(Arg<int>.Is.Equal(GOOD_ORDER_ID)))
                    .Return(paymentListMock)
                    .Repeat.Once();


                // settlement manager mocks of inner methods
                SettlementManager settlementManagerMock = MockRepository.GeneratePartialMock<SettlementManager>();

                settlementManagerMock.Expect(
                    sm =>
                    sm.GetPaymentByTypeAndSource(Arg<IEnumerable<Model.Booking.Payment>>.List.ContainsAll(paymentListMock),
                                                 Arg<PaymentTypeEnum>.Is.Equal(PaymentTypeEnum.Payment),
                                                 Arg<PaymentSourceEnum>.Is.Equal(PaymentSourceEnum.Online)))
                    .Return(bookingPaymentMock).Repeat.Once();

                bookingItemDaoMock.Expect(bid => bid.GetByBooking(Arg<int>.Is.Equal(GOOD_BOOKING_ID)))
                    .Return(bookingItemMock)
                    .Repeat.Once();

                paymentEventDaoMock.Expect(ped => ped.GetByPaymentId(Arg<int>.Is.Equal(bookingPaymentMock.Id)))
                    .Return(paymentEventListMock)
                    .Repeat.Once();

                settlementManagerMock.Expect(
                    smm =>
                    smm.GetSettlementPayment(
                        Arg<PaymentRequest>.Matches(
                            pr => pr.BookingReferenceCode == bookingMock.BookingReferenceNumber &&
                                  pr.IsoCountryCode == countryMock.IsoChar2Code)))
                    .Return(settlementPaymentDtosMock)
                    .Repeat.Once();

                settlementManagerMock.Expect(
                    sem =>
                    sem.SetLineItemsOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                       Arg<List<SettlementPaymentDto>>.Is.Anything,
                                                       Arg<Order>.Matches(
                                                           o =>
                                                           o.Id == orderMock.Id && o.ChannelId == orderMock.ChannelId &&
                                                           o.Bookings != null &&
                                                           o.Bookings.Count == orderMock.Bookings.Count),
                                                       Arg<List<Model.Booking.Payment>>.List.ContainsAll(paymentListMock),
                                                       Arg<List<PaymentEvent>>.Is.Anything)).Repeat.Once();
                settlementManagerMock.Expect(
                    sem =>
                    sem.SetGuestInfoOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                       Arg<Order>.Matches(
                                                           b =>
                                                           b.Id == orderMock.Id &&
                                                           b.OrderReference == orderMock.OrderReference))).Repeat.Once();
                settlementManagerMock.Expect(
                    sem => sem.SetBookingInfoOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                                Arg<Booking>.Matches(b =>
                                                                                     b.Id == bookingMock.Id &&
                                                                                     b.OrderId == bookingMock.OrderId &&
                                                                                     b.BusinessId ==
                                                                                     bookingMock.BusinessId &&
                                                                                     b.BookingReferenceNumber ==
                                                                                     bookingMock.BookingReferenceNumber),
                                                                Arg<Order>.Matches(
                                                                    o =>
                                                                    o.Id == orderMock.Id &&
                                                                    o.ChannelId == orderMock.ChannelId &&
                                                                    o.Bookings != null &&
                                                                    o.Bookings.Count == orderMock.Bookings.Count),
                                                                Arg<BookingEvent>.Matches(
                                                                    be =>
                                                                    be.Id == bookingEventMock.Id &&
                                                                    be.BookingId == bookingEventMock.BookingId),
                                                                Arg<List<BookingEventData>>.Is.Anything,
                                                                Arg<Model.Business.Business>.Matches(
                                                                    bu => bu.Id == businessMock.Id),
                                                                Arg<List<SettlementPaymentDto>>.Is.Anything, 
                                                                Arg<string>.Is.Anything)).Repeat.Once();

                settlementManagerMock.Expect(
                    sem => sem.SetFinancialInfoOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                                  Arg<Booking>.Matches(b =>
                                                                                       b.Id == bookingMock.Id &&
                                                                                       b.OrderId == bookingMock.OrderId &&
                                                                                       b.BusinessId ==
                                                                                       bookingMock.BusinessId &&
                                                                                       b.BookingReferenceNumber ==
                                                                                       bookingMock
                                                                                           .BookingReferenceNumber),
                                                                  Arg<Model.Business.Business>.Matches(
                                                                      bu => bu.Id == businessMock.Id),
                                                                  Arg<Order>.Matches(
                                                                      o =>
                                                                      o.Id == orderMock.Id &&
                                                                      o.ChannelId == orderMock.ChannelId &&
                                                                      o.Bookings != null &&
                                                                      o.Bookings.Count == orderMock.Bookings.Count),
                                                                  Arg<List<BookingItem>>.Is.Anything,
                                                                  Arg<decimal>.Is.Anything)).Repeat.Once();

                settlementManagerMock.Expect(
                    sem =>
                    sem.SetPaymentInfoOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                         Arg<Model.Booking.Payment>.Matches(p => p.Id == bookingPaymentMock.Id),
                                                         Arg<List<SettlementPaymentDto>>.Is.Anything,
                                                         Arg<Order>.Matches(
                                                                      o =>
                                                                      o.Id == orderMock.Id &&
                                                                      o.ChannelId == orderMock.ChannelId &&
                                                                      o.Bookings != null &&
                                                                      o.Bookings.Count == orderMock.Bookings.Count),
                                                         Arg<bool>.Is.Equal(forceProcess))).Repeat.Once();

                settlementManagerMock.Expect(
                    sem =>
                    sem.SetProviderDistributorInformationOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                                            Arg<Model.Business.Business>.Matches(
                                                                                bu => bu.Id == businessMock.Id),
                                                                            Arg<Model.Business.Business>.Matches(
                                                                                chbu => chbu.Id == channelBusinessMock.Id), 
                                                                            Arg<Channel>.Is.Anything)).Repeat.Once();

                settlementManagerMock.Expect(
                    sem =>
                    sem.SetReservedProductOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                             Arg<Booking>.Matches(b =>
                                                                                  b.Id == bookingMock.Id &&
                                                                                  b.OrderId == bookingMock.OrderId &&
                                                                                  b.BusinessId ==
                                                                                  bookingMock.BusinessId &&
                                                                                  b.BookingReferenceNumber ==
                                                                                  bookingMock
                                                                                      .BookingReferenceNumber),
                                                             Arg<Order>.Matches(
                                                                 o =>
                                                                 o.Id == orderMock.Id &&
                                                                 o.ChannelId == orderMock.ChannelId &&
                                                                 o.Bookings != null &&
                                                                 o.Bookings.Count == orderMock.Bookings.Count), 
                                                                 Arg<string>.Is.Anything)).Repeat.Once();

                settlementHelperMock.Expect(
                    helper =>
                    helper.SetMerchantInfoOnTransactionModel(Arg<TransactionModel>.Is.Anything,
                                                             Arg<Model.Booking.Booking>.Is.Anything,
                                                             Arg<Model.Business.Business>.Is.Anything,
                                                             Arg<Model.Business.Business>.Is.Anything,
                                                             Arg<List<SettlementPaymentDto>>.Is.Anything));

                settlementManagerMock.BookingDao = bookingDaoMock;
                settlementManagerMock.BookingEventDao = bookingEventDaoMock;
                settlementManagerMock.BookingEventDataDao = bookingEventDataDaoMock;
                settlementManagerMock.BookingItemDao = bookingItemDaoMock;
                settlementManagerMock.BusinessDao = businessDaoMock;
                settlementManagerMock.ChannelDao = channelDaoMock;
                settlementManagerMock.CountryDao = countryDaoMock;
                settlementManagerMock.OrderDao = orderDaoMock;
                settlementManagerMock.OrderReferenceDao = orderReferenceMock;
                settlementManagerMock.PaymentEventDao = paymentEventDaoMock;
                settlementManagerMock.PaymentDao = paymentDaoMock;
                settlementManagerMock.SettlementHelper = settlementHelperMock;

                #endregion

                // Act
                TransactionModel result = settlementManagerMock.CreateTransactionModelForInvoiceRequest(
                    GOOD_BOOKING_ID, GOOD_ORDER_ID, GOOD_EVENT_ID, forceProcess);

                // Assert
                settlementManagerMock.VerifyAllExpectations();
                bookingDaoMock.VerifyAllExpectations();
                bookingEventDaoMock.VerifyAllExpectations();
                bookingEventDataDaoMock.VerifyAllExpectations();
                bookingItemDaoMock.VerifyAllExpectations();
                businessDaoMock.VerifyAllExpectations();
                channelDaoMock.VerifyAllExpectations();
                countryDaoMock.VerifyAllExpectations();
                orderDaoMock.VerifyAllExpectations();
                orderReferenceMock.VerifyAllExpectations();
                paymentEventDaoMock.VerifyAllExpectations();
                paymentDaoMock.VerifyAllExpectations();
                settlementHelperMock.VerifyAllExpectations();
            }
Esempio n. 5
0
        /// <summary>
        /// Set transaction info based upon the events and booking
        /// </summary>
        /// <param name="transactionModel">what will be sent to settlement</param>
        /// <param name="booking">updated / inserted booking</param>
        /// <param name="bookingEvent">booking event for this booking</param>
        /// <param name="bookingEventData">list of booking event data from the related booking event</param>
        private void SetTransactionModelStartEndDateFromBookingEvent(TransactionModel transactionModel, Model.Booking.Booking booking, BookingEvent bookingEvent, List<BookingEventData> bookingEventData)
        {
            Helper.ArgumentNotNull(transactionModel, "transactionModel");
            DateTime oldStartDate = booking.StartDate;
            DateTime newStartDate = booking.StartDate;
            DateTime oldEndDate = booking.EndDate;
            DateTime newEndDate = booking.EndDate;
            
            // Only need to grab event data if it is modify event
            if (bookingEvent != null &&
                bookingEvent.EventType != null &&
                 bookingEvent.EventType.Code == BookingEventType.Modified.GetCode())
            {
                // fill in here the old / new start / end date

                BookingEventData startDateData = GetRecordFromColumnName(bookingEventData, BookingMapper.PublicParameters.StartDate.ToString());
                BookingEventData endDateData = GetRecordFromColumnName(bookingEventData, BookingMapper.PublicParameters.EndDate.ToString());

                DateTime tempDateTime;
                if (startDateData != null)
                {
                    // start date changed
                    if (DateTime.TryParse(startDateData.OldValue, out tempDateTime))
                    {
                        oldStartDate = tempDateTime;
                    }

                    if (DateTime.TryParse(startDateData.NewValue, out tempDateTime))
                    {
                        newStartDate = tempDateTime;
                    }
                }
                else
                {
                    oldStartDate = booking.StartDate;
                    newStartDate = booking.StartDate;
                }

                if (endDateData != null)
                {
                    // end date changed
                    if (DateTime.TryParse(endDateData.OldValue, out tempDateTime))
                    {
                        oldEndDate = tempDateTime;
                    }

                    if (DateTime.TryParse(endDateData.NewValue, out tempDateTime))
                    {
                        newEndDate = tempDateTime;
                    }
                }
                else
                {
                    oldEndDate = booking.EndDate;
                    newEndDate = booking.EndDate;
                }
            }

            transactionModel.StartDate      = oldStartDate;
            transactionModel.MovedStartDate = newStartDate;
            transactionModel.EndDate        = oldEndDate;
            transactionModel.MovedEndDate   = newEndDate;
        }
Esempio n. 6
0
        /// <summary>
        /// Set booking information on settlement TransactionModel
        /// </summary>
        /// <remarks>
        /// This will need looking into again when orders with multiple bookings gets done
        /// </remarks>
        /// <param name="transactionModel">TransactionModel</param>
        /// <param name="booking">Booking</param>
        /// <param name="order">Order</param>
        /// <param name="bookingEvent">booking event for this transaction</param>
        /// <param name="bookingEventData">booking event data from related event</param>
        /// <param name="business">Model.Business.Business</param>
        /// <param name="settlementPaymentDtos">Collection of SettlementPaymentDto</param>
        /// <param name="reservationId">Reservation Id</param>
        public virtual void SetBookingInfoOnTransactionModel(TransactionModel transactionModel, Model.Booking.Booking booking, Model.Order.Order order, BookingEvent bookingEvent, List<BookingEventData> bookingEventData, Model.Business.Business business, List<SettlementPaymentDto> settlementPaymentDtos, string reservationId)
        {
            Helper.ArgumentNotNull(transactionModel, "transactionModel");
            Helper.ArgumentNotNull(booking, "booking");
            Helper.ArgumentNotNull(order, "order");
            Helper.ArgumentNotNull(order.Channel, "channel");
            Helper.ArgumentNotNull(reservationId, "reservationId");

            SetTransactionModelStartEndDateFromBookingEvent(transactionModel, booking, bookingEvent, bookingEventData);

            transactionModel.PartnerOrderNumber = order.ChannelReference;
            transactionModel.BookingReferenceNumber = order.OrderReference.RemoveAllSpacesAndNonAlphaNumerics();
            transactionModel.ReservationId = reservationId;
            transactionModel.TransactonDate = order.OrderDatetime.GetValueOrDefault();
            transactionModel.Id = order.Id.HasValue ? Helper.IntToGuid(order.Id.Value) : default(Guid);
            transactionModel.CancellationDate = GetTransactionCancellationDate(bookingEvent);
            transactionModel.ScenarioType = GetTransactionScenarioType(booking, order, settlementPaymentDtos);
            transactionModel.CurrencyCode = order.CustomerCurrencyCode;
            transactionModel.CancelledAmount = order.TotalValue.HasValue && transactionModel.CancellationDate.HasValue ? order.TotalValue.Value : default(decimal);
            transactionModel.ReservationStatus = MapToSettlementTransactionReservationStatusTypes(booking.BookingStatus);
            
            logger.LogInfo("SetBookingInfoOnTransactionModel completed");
        }
Esempio n. 7
0
        /// <summary>
        /// Get TransactionCancellationDate, if present, from the BookingEvent
        /// </summary>
        /// <param name="bookingEvent">Booking event for this transaction</param>
        /// <returns>Cancellation Date</returns>
        private DateTime? GetTransactionCancellationDate(BookingEvent bookingEvent)
        {
            if (bookingEvent != null &&
                bookingEvent.EventType != null && 
                bookingEvent.EventType.Code == BookingEventType.Cancelled.GetCode())
            {
                return bookingEvent.Created;
            }

            // Not a cancelled event
            return null;
        }
Esempio n. 8
0
            public void CreateBookingEventIsSuccessful()
            {
                // Arrange
                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBookingAndPaymentsTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var bookingEvent = new BookingEvent
                    {
                        BookingId = 1,
                        EventType = new EnumEntity
                                        {
                                            Code = BookingEventType.Accepted.GetCode()
                                        }
                    };

                    // Act
                    bookingEventDao.Create(bookingEvent);

                    // Assert
                    BookingEvent createdBookingEvent = bookingEventDao.GetByKey(bookingEvent.Id);
                    Assert.IsTrue(bookingEvent.Id > 0, "Id was not filled in after create");
                    Assert.AreEqual(bookingEvent.BookingId, createdBookingEvent.BookingId, "booking Id is not the same");
                    Assert.AreEqual(bookingEvent.EventType.Code, createdBookingEvent.EventType.Code, "booking event type code is not the same");
                }
            }