public OutputCacheMiddlewareRealCacheTests()
        {
            _loggerFactory = new Mock <IOcelotLoggerFactory>();
            _logger        = new Mock <IOcelotLogger>();
            _loggerFactory.Setup(x => x.CreateLogger <OutputCacheMiddleware>()).Returns(_logger.Object);

            _mockOptions       = new Mock <IOptions <OcelotEasyCachingOptions> >();
            _cacheKeyGenerator = new CacheKeyGenerator();
            _mockOptions.Setup(x => x.Value).Returns(new OcelotEasyCachingOptions()
            {
                EnableHybrid = false,
                ProviderName = "m1",
            });

            IServiceCollection services = new ServiceCollection();

            services.AddEasyCaching(x => x.UseInMemory(options => options.MaxRdSecond = 0, "m1"));
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            var factory = serviceProvider.GetService <IEasyCachingProviderFactory>();

            _ocelotCache       = new OcelotEasyCachingCache <CachedResponse>(_mockOptions.Object, factory, null);
            _downstreamContext = new DownstreamContext(new DefaultHttpContext());
            _downstreamContext.DownstreamRequest = new Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123"));
            _next       = context => Task.CompletedTask;
            _middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _ocelotCache, _cacheKeyGenerator);
        }
コード例 #2
0
        public OutputCacheMiddlewareRealCacheTests()
        {
            _loggerFactory = new Mock <IOcelotLoggerFactory>();
            _logger        = new Mock <IOcelotLogger>();
            _loggerFactory.Setup(x => x.CreateLogger <OutputCacheMiddleware>()).Returns(_logger.Object);
            var cacheManagerOutputCache = CacheFactory.Build <CachedResponse>("OcelotOutputCache", x =>
            {
                x.WithDictionaryHandle();
            });

            _cacheManager      = new OcelotCacheManagerCache <CachedResponse>(cacheManagerOutputCache);
            _downstreamContext = new DownstreamContext(new DefaultHttpContext());
            _downstreamContext.DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123"));
            _next       = context => Task.CompletedTask;
            _middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _cacheManager);
        }
コード例 #3
0
 private void WhenICallTheMiddleware()
 {
     _middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _cache.Object, _cacheKeyGenerator);
     _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
 }