private IDeliveryClient GetCachedDeliveryClient() { mockHttp.When($"{baseUrl}/items") .WithQueryString(new[] { new KeyValuePair <string, string>("system.type", Article.Codename), new KeyValuePair <string, string>("limit", "3"), new KeyValuePair <string, string>("depth", "0"), new KeyValuePair <string, string>("order", "elements.post_date[asc]") }) .Respond("application/json", File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "Fixtures\\CachedDeliveryClient\\articles.json"))); var httpClient = mockHttp.ToHttpClient(); var projectOptions = Options.Create(new ProjectOptions { CacheTimeoutSeconds = 60, DeliveryOptions = new DeliveryOptions { ProjectId = guid } }); var memoryCacheOptions = Options.Create(new MemoryCacheOptions { Clock = new TestClock(), ExpirationScanFrequency = new TimeSpan(0, 0, 5) }); var cacheManager = new ReactiveCacheManager(projectOptions, new MemoryCache(memoryCacheOptions), new DependentFormatResolver(), new WebhookListener()); return(new CachedDeliveryClient(projectOptions, cacheManager) { CodeFirstModelProvider = { TypeProvider = new Models.CustomTypeProvider() }, HttpClient = httpClient }); }
private CachedDeliveryClient GetCachedDeliveryClient(Action mockAction = null, Func <RequestCount, RequestCount> mockFunc = null, RequestCount actualHttpRequests = null) { HttpClient httpClient = null; DeliveryOptions deliveryOptions = null; if (mockAction != null) { InitClientPrerequisites(out httpClient, out deliveryOptions, mockAction: mockAction); } else if (mockFunc != null && actualHttpRequests != null) { InitClientPrerequisites(out httpClient, out deliveryOptions, mockFunc: mockFunc, actualHttpRequests: actualHttpRequests); } var projectOptions = Options.Create(new ProjectOptions { CacheTimeoutSeconds = 60, DeliveryOptions = deliveryOptions }); var memoryCacheOptions = Options.Create(new MemoryCacheOptions { Clock = new TestClock(), ExpirationScanFrequency = new TimeSpan(0, 0, 5) }); var cacheManager = new ReactiveCacheManager(projectOptions, new MemoryCache(memoryCacheOptions), new DependentFormatResolver(), new WebhookListener()); return(new CachedDeliveryClient(projectOptions, cacheManager , DeliveryClientBuilder.WithOptions(o => deliveryOptions).WithCodeFirstTypeProvider(new Models.CustomTypeProvider()).WithHttpClient(httpClient).Build())); }
private void PrepareFixture(out ReactiveCacheManager cacheManager, out List <string> identifier, out string value) { cacheManager = BuildCacheManager(); identifier = new List <string> { "TestIdentifier" }; value = "TestValue"; }