private static (RequestDelegate, HttpContext, MockContexts) GetMiddleware(BandwidthOptions options, Action <MockHttpContext> buildHttpContext = null) { var builder = new MockApplicationBuilder(); builder.UseBandwidth(options); Assert.NotNull(builder.Middleware); var context = new MockHttpContext(); var mockContexts = new MockContexts(); context.AddService <IMemoryCache>(new MockMemoryCache(mockContexts.MemoryCache)); context.AddService <IApplication>(new MockApplication(mockContexts.Application)); context.AddService <IPhoneNumber>(new MockPhoneNumber(mockContexts.PhoneNumber)); context.AddService <IAvailableNumber>(new MockAvailableNumber(mockContexts.AvailableNumber)); context.AddService <IDomain>(new MockDomain(mockContexts.Domain)); if (buildHttpContext != null) { buildHttpContext(context); } return(builder.Middleware(c => Task.FromResult(0)), context, mockContexts); }