public async Task CachesManyRequestSeparatelyAsyncTest( string responseHeaderNameToAdd, string queryParams, [Frozen] IList <Element> responseElements, [CustomizeWith(typeof(MemoryCacheMethodAutoFixture))][Frozen] MiddlewareContext context, [CustomizeWith(typeof(ExpiresHeaderAutoFixture))][Frozen] IWebApiResponse response, IFixture fixture) { var options = CreateRequestOptions(queryParams); context.Request.Options.Returns(options); SetResponseHeader(response, responseHeaderNameToAdd, fixture.Create <string>()); SetResponseContent(response, responseElements); // Do the first request var middleware = new CacheMiddleware(); await middleware.OnRequestAsync(context, (r, t) => Task.FromResult(response)); // Do individual requests to see if they are taken from the cache options.EndpointQuery.Clear(); foreach (var element in responseElements) { options.PathSuffix = element.Id; var elementResponse = await middleware.OnRequestAsync(context, (r, t) => throw new InvalidOperationException("should not be hit")); var elementObject = JsonSerializer.Deserialize <Element>(elementResponse.Content); elementObject.Should().BeEquivalentTo(element); } }
public async Task SingleRequestAsyncTest( string responseHeaderNameToAdd, [CustomizeWith(typeof(MemoryCacheMethodAutoFixture))][Frozen] MiddlewareContext context, [Frozen] IWebApiResponse response, IFixture fixture) { context.Request.Options.Returns(CreateRequestOptions()); SetResponseHeader(response, responseHeaderNameToAdd, fixture.Create <string>()); // Do the request var middleware = new CacheMiddleware(); var liveResponse = await middleware.OnRequestAsync(context, (r, t) => Task.FromResult(response)); liveResponse.Should().BeSameAs(response); }
public async Task ManyRequestAsyncTest( string responseHeaderNameToAdd, string queryParams, [Frozen] IList <Element> responseElements, [CustomizeWith(typeof(MemoryCacheMethodAutoFixture))][Frozen] MiddlewareContext context, [Frozen] IWebApiResponse response, IFixture fixture) { context.Request.Options.Returns(CreateRequestOptions(queryParams)); SetResponseHeader(response, responseHeaderNameToAdd, fixture.Create <string>()); SetResponseContent(response, responseElements); // Do the request var middleware = new CacheMiddleware(); var liveResponse = await middleware.OnRequestAsync(context, (r, t) => Task.FromResult(response)); liveResponse.Should().BeEquivalentTo(response); }
public async Task CachesSingleRequestAsyncTest( string responseHeaderNameToAdd, [CustomizeWith(typeof(MemoryCacheMethodAutoFixture))][Frozen] MiddlewareContext context, [CustomizeWith(typeof(ExpiresHeaderAutoFixture))][Frozen] IWebApiResponse response, IFixture fixture) { context.Request.Options.Returns(CreateRequestOptions()); SetResponseHeader(response, responseHeaderNameToAdd, fixture.Create <string>()); // Do the first request var middleware = new CacheMiddleware(); await middleware.OnRequestAsync(context, (r, t) => Task.FromResult(response)); // Repeat the request to see if it's taken from the cache var cachedResponse = await middleware.OnRequestAsync(context, (r, t) => throw new InvalidOperationException("should not be hit")); cachedResponse.Should().BeEquivalentTo(response); }