Exemplo n.º 1
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));
            }
        }