Exemplo n.º 1
0
        public void CreateBooking(CreateBookingRequest request)
        {
            // calculate price

            // if booking is successful, capture payment
            paymentGateway.CapturePayment(10);
        }
Exemplo n.º 2
0
        public void Pass_in_a_fake_interface([Frozen] IPaymentGateway paymentGateway, BookingService sut)
        {
            // arrange
            // not much here!!

            // act
            sut.CreateBooking();

            // assert
            A.CallTo(() => paymentGateway.CapturePayment()).MustHaveHappened();
        }
Exemplo n.º 3
0
        // create a new booking and persist it to our fake database.
        public void CreateBooking(CreateBookingRequest request)
        {
            // not part of the test, but is an example of why
            // we use a separate CreateBookingRequest object
            // than the domain object Booking itself as parameter
            // the request has properties that aren't relevant
            // to persist in the data store.
            if (!HasPermission(request.RequestedBy))
            {
                throw new InvalidOperationException("You don't have permission.");
            }

            // get the price from the price calculator
            var totalAmount = priceCalculator.GetPriceForBookingWith(1, 2);

            // assume everything is ok with the booking
            // usually do more things here
            var capturePaymentResult = paymentGateway.CapturePayment(totalAmount);

            if (capturePaymentResult == true)
            {
                repository.AddBooking(new Booking(request.Id));
            }
        }