예제 #1
0
        public void UseDependencies_can_be_used_to_set_dependencies_using_an_application_owned_container()
        {
            var applicationsContainer = new PocketContainer()
                                        .Register <IPaymentService>(_ => new CreditCardPaymentGateway(chargeLimit: 1));

            Configuration.Current
            .UseDependencies(type =>
            {
                if (applicationsContainer.Any(reg => reg.Key == type))
                {
                    return(() => applicationsContainer.Resolve(type));
                }

                return(null);
            });

            var order = new Order(new CreateOrder(Any.FullName()))
                        .Apply(new AddItem
            {
                Price       = 5m,
                ProductName = Any.Word()
            })
                        .Apply(new Ship())
                        .Apply(new ChargeAccount
            {
                AccountNumber = Any.PositiveInt().ToString()
            });

            order.Events()
            .Last()
            .Should()
            .BeOfType <Order.PaymentConfirmed>();
        }