public void CancelValidBookingExpectSuccess()
            {
                // Arrange
                const int  BOOKING_ID = 1;
                const long BUSINESS_ID = 11111111111;

                var requestcancelBooking = new RequestCancelBooking() { BookingId = BOOKING_ID, BusinessId = BUSINESS_ID };
                var requestcancelBookingDto = new RequestCancelBookingDto() { BookingId = BOOKING_ID, BusinessId = BUSINESS_ID }; 
                var existingBooking = new Booking{Id = BOOKING_ID,BusinessId = BUSINESS_ID,};
                var bookingManager = MockRepository.GenerateMock<IBookingManager>();
                
                bookingManager.Stub(b => b.GetByKey(BOOKING_ID)).Return(existingBooking);
                bookingManager.Expect(r => r.RequestCancelBooking(Arg<RequestCancelBooking>.Matches(
                    rcbook => 
                        rcbook.CancellationRequestReason == requestcancelBooking.CancellationRequestReason &&
                        rcbook.CancellationRequestAction == requestcancelBooking.CancellationRequestAction &&
                        rcbook.BookingId == requestcancelBooking.BookingId &&
                        rcbook.BusinessId == requestcancelBooking.BusinessId &&
                        rcbook.BusinessContactedGuest == requestcancelBooking.BusinessContactedGuest &&
                        rcbook.Notes == requestcancelBooking.Notes), Arg<Booking>.Is.Equal(existingBooking))).Return(true);
                PropertyManagementSystemService.BookingManager = bookingManager;

                // 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
                bool requestResult = PropertyManagementSystemService.RequestCancelBooking(requestcancelBookingDto);

                // Assert
                Assert.IsTrue(requestResult, "Booking is not cancelled successfully.");
                bookingManager.VerifyAllExpectations();

                // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
        public bool RequestCancelBooking(RequestCancelBookingDto requestCancelBookingDto)
        {
            // Make sure the current user has access to this business
            CheckAccessRights(requestCancelBookingDto.BusinessId);

            // Validate if business exists
            if (BusinessCache.TryGetValue(requestCancelBookingDto.BusinessId) == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30001,
                                                                                "PropertyManagementSystemService.RequestCancelBooking",
                                                                                additionalDescriptionParameters:
                                                                                    (new object[] { requestCancelBookingDto.BusinessId })));
            }

            // Retrieve latest booking information
            Booking internalBooking = bookingManager.GetByKey(requestCancelBookingDto.BookingId);

            // Throw validation exception if booking could not be found in the system
            if (internalBooking == null)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30010,
                                                                             "PropertyManagementSystemService.RequestCancelBooking",
                                                                             descriptionParameters:
                                                                                 (new object[] { requestCancelBookingDto.BookingId, requestCancelBookingDto.BookingId }),
                                                                             additionalDescriptionParameters:
                                                                                 (new object[] { requestCancelBookingDto.BookingId, requestCancelBookingDto.BusinessId }),
                                                                             arguments:
                                                                                 new object[] { requestCancelBookingDto.BookingId, requestCancelBookingDto.BusinessId }));

            }
            // Convert to requestCancelBooking Model
            RequestCancelBooking requestCancelBooking = DataTransferObjectsConverter.ConvertRequestCancelBookingDtoToRequestCancelBooking(requestCancelBookingDto);
            
            // Request cancellation
            return bookingManager.RequestCancelBooking(requestCancelBooking, internalBooking);
        }
            public void RequestCancelNonExistingBookingExpectExceptionThrown()
            {
                // Arrange
                var requestcancelBookingDto = new RequestCancelBookingDto() { BookingId = -1, BusinessId = 11111111111 };

                var bookingManager = MockRepository.GenerateStub<IBookingManager>();
                bookingManager.Stub(b => b.GetByKey(BOOKING_ID)).Return(null);
                PropertyManagementSystemService.BookingManager = bookingManager;

                // 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();

                try
                {
                    // Act
                    PropertyManagementSystemService.RequestCancelBooking(requestcancelBookingDto);

                    // 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");
                }
                
              // Reassign the Dao on the cache to discard the stub assigned on the StubBusinessCacheSingleBusiness method
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
Exemplo n.º 4
0
 /// <summary>
 /// Convert RequestCancelBookingDto to RequestCancelBooking model
 /// </summary>
 /// <param name="requestCancelBookingDto">RequestCancelBookingDto</param>
 /// <returns>RequestCancelBooking</returns>
 public static RequestCancelBooking ConvertRequestCancelBookingDtoToRequestCancelBooking(RequestCancelBookingDto requestCancelBookingDto)
 {
     return new RequestCancelBooking
                {
                    BookingId = requestCancelBookingDto.BookingId,
                    BusinessId = requestCancelBookingDto.BusinessId,
                    BusinessContactedGuest = requestCancelBookingDto.BusinessContactedGuest,
                    CancellationRequestAction = (CancellationRequestAction)requestCancelBookingDto.CancellationRequestAction,
                    CancellationRequestReason = (CancellationReasonEnum)requestCancelBookingDto.CancellationReason,
                    Notes = requestCancelBookingDto.Notes  
                };
 }