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
                };

                var orderDto = new OrderDto
                    {
                        Id = 1,
                        Bookings = new List<BookingDto> { bookingDto }
                    };

                // 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.CreateOrder(MISMATCHED_BUSINESS_ID, orderDto);

                // 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 CreateOrderInvalidBusinessIdThrowsValidationException()
            {
                // Arrange
                // businessId that we know will never exist
                const long BUSINESS_ID = -100011110010000;

                var orderDto = new OrderDto
                    {
                        Id = 1,
                        Bookings = new List<BookingDto>()
                    };

                try
                {
                    // Act
                    PropertyManagementSystemService.CreateOrder(BUSINESS_ID, orderDto);

                    // 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 OrderDto CreateOrder(long businessId, OrderDto orderDto)
        {
            // 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.CreateOrder",
                                                additionalDescriptionParameters: (new object[] { businessId })));
            }

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

            // Convert to Model
            Order order = DataTransferObjectsConverter.ConvertOrderDtoToOrder(orderDto);
            order.OfflineSourceEnum = OfflineSourceEnum.Web;
            order.OrderSourceCode = SourceType.Pms.GetCode();

            order.Bookings.ForEach(b => b.CheckinStatus = new EnumEntity { Code = CheckinStatusOptions.NOTCHECKEDIN });

            orderManager.CreateOrder(businessId, order);

            return order.Id != null ? Mapper.Map<Order, OrderDto>(orderManager.GetOrderWithBookingsByKey(order.Id.Value)) : null;
        }
            public void CreateOrderCreatesOrder()
            {
                // 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 orderDto = new OrderDto
                    {
                        Id = 1,
                        Bookings = new List<BookingDto>()
                    };

                var order = new Order
                    {
                        Id = 1,
                        Bookings = new List<Booking>()
                    };
                
                var orderManager = MockRepository.GenerateMock<IOrderManager>();

                orderManager.Expect(x => x.CreateOrder(Arg<long>.Is.Anything, Arg<Order>.Is.Anything)).Return(true);
                orderManager.Expect(x => x.GetOrderWithBookingsByKey(Arg<int>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<GetOrderWithBookingsByEnum>.Is.Equal(GetOrderWithBookingsByEnum.Id))).Return(order);

                PropertyManagementSystemService.OrderManager = orderManager;

                // Act
                PropertyManagementSystemService.CreateOrder(BUSINESS_ID, orderDto);

                // Assert
                orderManager.VerifyAllExpectations();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
예제 #5
0
 /// <summary>
 /// Converts Order DTO object to Order
 /// </summary>
 /// <param name="orderDto">Order Dto to convert</param>
 /// <returns>Converted Order</returns>
 public static Order ConvertOrderDtoToOrder(OrderDto orderDto)
 {
     OfflineSourceEnum? offlineSourceEnum = EnumExtensions.ParseEnumFromCode<OfflineSourceEnum>(orderDto.OfflineSourceCode);
     
     if (offlineSourceEnum == OfflineSourceEnum.Unknown)
     {
         offlineSourceEnum = null;
     }
     
     var order = new Order
         {
             Id = orderDto.Id,
             OrderSourceCode = orderDto.OrderSourceCode,
             ChannelId = orderDto.ChannelId,
             ChannelReference = orderDto.ChannelReference,
             IntegrationType = EnumExtensions.ParseEnumFromCode<IntegrationTypeEnum>(orderDto.IntegrationTypeCode),
             AgentId = orderDto.AgentId,
             OfflineSourceEnum = offlineSourceEnum,
             CustomerCurrencyCode = orderDto.CustomerCurrencyCode,
             CustomerCultureCode = orderDto.CustomerCultureCode,
             GroupReference = orderDto.GroupReference,
             Bookings = orderDto.Bookings != null ? orderDto.Bookings.ConvertAll(ConvertBookingDtoToBooking) : null,
             OrderReference = orderDto.OrderReference,
             LeadGuest = orderDto.LeadGuest != null ? Mapper.Map<Guest>(orderDto.LeadGuest) : null,
             GuestMessage = orderDto.GuestMessage,
             Notes = orderDto.Notes
         };
     
     return order;
 }