コード例 #1
0
 public void CacheTimeoutWillReflectConstructorArgument()
 {
     // Fixture setup
     var fixture = new Fixture();
     var expectedCacheTimeout = fixture.CreateAnonymous<TimeSpan>();
     var sut = new CachingCurrencyProvider(new Mock<CurrencyProvider>().Object, expectedCacheTimeout);
     // Exercise system
     TimeSpan result = sut.CacheTimeout;
     // Verify outcome
     Assert.Equal<TimeSpan>(expectedCacheTimeout, result);
     // Teardown
 }
コード例 #2
0
        protected override IController GetControllerInstance(
            RequestContext requestContext, Type controllerType)
        {
            string connectionString =
                ConfigurationManager.ConnectionStrings
                ["CommerceObjectContext"].ConnectionString;

            var productRepository =
                new SqlProductRepository(connectionString);
            var basketRepository =
                new SqlBasketRepository(connectionString);
            var discountRepository =
                new SqlDiscountRepository(connectionString);

            var discountPolicy =
                new RepositoryBasketDiscountPolicy(
                    discountRepository);

            var basketService =
                new BasketService(basketRepository,
                    discountPolicy);

            var currencyProvider = new CachingCurrencyProvider(
                new SqlCurrencyProvider(connectionString),
                TimeSpan.FromHours(1));

            if (controllerType == typeof(BasketController))
            {
                return new BasketController(
                    basketService, currencyProvider);
            }
            if (controllerType == typeof(HomeController))
            {
                return new HomeController(
                    productRepository, currencyProvider);
            }

            return base.GetControllerInstance(
                requestContext, controllerType);
        }