Ejemplo n.º 1
0
        public void NotFailWithNoItemsNotificationNoCreditCard()
        {
            var paymentProcessor    = new FakePaymentProcessor();
            var reservationService  = new FakeReservationService();
            var notificationSerfice = new FakeNotificationService();
            var cart = new Cart {
                CustomerEmail = "*****@*****.**"
            };
            var paymentDetails = new PaymentDetails {
                PaymentMethod = PaymentMethod.CreditCard
            };
            var order = new OnlineOrder(cart, paymentDetails, paymentProcessor, reservationService, notificationSerfice);

            order.Checkout();
        }
        /// <summary>
        ///     Builds a controller of the required type using any data previously supplied (or defaults).
        /// </summary>
        /// <returns>An initialized controller of type <typeparamref name="TController" />.</returns>
        /// <exception cref="SpecificationException">Thrown if the controller cannot be built.</exception>
        public TController Build()
        {
            var dataLoader = new ObjectDataLoader(data);

            UnitOfWork = uowBuilder.WithData(dataLoader).Build();
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <ViewModelMappingProfile>(); });

            mapperConfiguration.AssertConfigurationIsValid();
            Mapper = mapperConfiguration.CreateMapper();
            var notifier = new FakeNotificationService();

            RulesService = new GameRulesService(UnitOfWork, Mapper, notifier);
            HttpContextBase httpContext;

            if (postedFile == null)
            {
                httpContext = new FakeHttpContext(requestPath, requestMethod.ToString("G"));
            }
            else
            {
                var filesCollection = new FakeHttpFileCollection(postedFile);
                httpContext = new FakeHttpContext(requestPath, filesCollection);
            }
            var fakeIdentity  = new FakeIdentity(requestUsername);
            var fakePrincipal = new FakePrincipal(fakeIdentity, requestUserRoles);

            httpContext.User = fakePrincipal;
            var context = new ControllerContext {
                HttpContext = httpContext
            };

            /*
             * Use Ninject to create the controller, as we don't know in advance what
             * type of controller or how many constructor parameters it has.
             */
            var kernel     = BuildNinjectKernel(fakeIdentity, requestUserId, RulesService);
            var controller = kernel.Get <TController>();

            if (controller == null)
            {
                throw new SpecificationException(
                          $"ControllerContextBuilder: Unable to create controller instance of type {nameof(TController)}");
            }

            controller.ControllerContext = context;
            controller.TempData          = tempdata;
            return(controller);
        }
        public void NotFailWithNoItemsNotificationNoCreditCard()
        {
            var paymentProcessor = new FakePaymentProcessor();
            var reservationService = new FakeReservationService();
            var notificationService = new FakeNotificationService();
            var cart = new Cart() { CustomerEmail = "*****@*****.**" };
            var paymentDetails = new PaymentDetails() { PaymentMethod = PaymentMethod.CreditCard };
            var order = new OnlineOrder(cart,
                                        paymentDetails,
                                        paymentProcessor,
                                        reservationService,
                                        notificationService);

            order.Checkout();

            // if I got here, I guess it worked...
        }
Ejemplo n.º 4
0
        public void SendTotalAmountToCreditCardProcessor()
        {
            var paymentProcessor    = new FakePaymentProcessor();
            var reservationService  = new FakeReservationService();
            var notificationService = new FakeNotificationService();
            var cart = new Cart {
                TotalAmount = 5.05m
            };
            var paymentDetails = new PaymentDetails
            {
                PaymentMethod = PaymentMethod.CreditCard
            };
            var order = new OnlineOrder(cart, paymentDetails, paymentProcessor, reservationService, notificationService);

            order.Checkout();

            Assert.True(paymentProcessor.WasCalled);
            Assert.Equal(cart.TotalAmount, paymentProcessor.AmountPassed);
        }
        public void SendTotalAmountToCreditCardProcessor()
        {
            var paymentProcessor = new FakePaymentProcessor();
            var reservationService = new FakeReservationService();
            var notificationService = new FakeNotificationService();
            var cart = new Cart {TotalAmount = 5.05m};
            var paymentDetails = new PaymentDetails()
            { PaymentMethod = PaymentMethod.CreditCard };
            var order = new OnlineOrder(cart,
                                        paymentDetails,
                                        paymentProcessor,
                                        reservationService,
                                        notificationService);

            order.Checkout();

            Assert.IsTrue(paymentProcessor.WasCalled);
            Assert.AreEqual(cart.TotalAmount, paymentProcessor.AmountPassed);
        }