public async Task HalBuilderFactory_ResolvesCustomConfigurations() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseOk(TestResource.SerializedDefault1); var factory = container.Resolve <IHalBuilderFactory>(); var builder = factory.Create(); string actual = null; string actualTyped = null; var resource = await builder.WithLink(server.ListeningUri) .Advanced .WithCaching(false) .OnSending(HandlerPriority.Last, context => { actual = context.Items["CustomHalConfiguration"] as string; actualTyped = context.Items["CustomTypedConfiguration"] as string; }) .ResultAsync <TestResource>(); resource.ShouldBe(TestResource.Default1()); actual.ShouldBe("CustomHalConfiguration: It Works!"); actualTyped.ShouldBeNull(); } }
public void CustomCacheProviderActivated() { var activated = false; CustomCacheProvider.Activated += (sender, args) => { activated = true; }; var container = RegistrationHelpers.CreateContainer(false); activated.ShouldBeTrue(); }
public async Task HttpBuilderFactory_ResolvesCustomValidators() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponse(HttpStatusCode.Created); var factory = container.Resolve <IHttpBuilderFactory>(); var builder = factory.Create(); await Should.ThrowAsync <HttpRequestException>(builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync()); } }
public async Task HttpBuilder_CanResolveAndCall() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseOk("Response"); var builder = container.Resolve <IHttpBuilder>(); var response = await builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync(); response.StatusCode.ShouldBe(HttpStatusCode.OK); } }
public async Task HalBuilder_CanResolveAndCall() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseOk(TestResource.SerializedDefault1); var builder = container.Resolve <IHalBuilder>(); var resource = await builder.WithLink(server.ListeningUri).Advanced.WithCaching(false).ResultAsync <TestResource>(); resource.ShouldBe(TestResource.Default1()); } }
public async Task TypedBuilderFactory_CanResolveAndCall() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseOk(TestResult.SerializedDefault1); var factory = container.Resolve <ITypedBuilderFactory>(); var builder = factory.Create(); var result = await builder.WithUri(server.ListeningUri).Advanced.WithCaching(false).ResultAsync <TestResult>(); result.ShouldBe(TestResult.Default1()); } }
public async Task TypedBuilderFactory_TwoBuildersDonNotShareSameSettings() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server .WithNextResponseTextOk("Response1") .WithNextResponseTextOk("Response2"); var factory = container.Resolve <ITypedBuilderFactory>(); var actual1 = 0; var actual2 = 0; HttpMethod method1 = null; HttpMethod method2 = null; var builder1 = factory.Create().WithUri(server.ListeningUri) .AsGet() .Advanced.WithCaching(false) .WithContextItem("Shared", 1) .OnSending(HandlerPriority.Last, context => { actual1 = (int)context.Items["Shared"]; method1 = context.Request.Method; }); var builder2 = factory.Create().WithUri(server.ListeningUri) .AsPut() .Advanced.WithCaching(false) .WithContextItem("Shared", 2) .OnSending(HandlerPriority.Last, context => { actual2 = (int)context.Items["Shared"]; method2 = context.Request.Method; }); var response1 = await builder1.ResultAsync <string>(); var response2 = await builder2.ResultAsync <string>(); method1.ToString().ShouldNotBe(method2.ToString()); actual1.ShouldNotBe(actual2); } }
public async Task HalBuilderFactory_ResolvesCustomCacheHandlers() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponse(new MockHttpResponseMessage().WithContent(TestResource.SerializedDefault1).WithPrivateCacheHeader().WithDefaultExpiration()); var factory = container.Resolve <IHalBuilderFactory>(); var builder = factory.Create(); string actual = null; var resource = await builder.WithLink(server.ListeningUri) .Advanced.WithCaching(true) .OnCacheMiss(HandlerPriority.Last, context => { actual = context.Items["CustomTypedCacheHandler"] as string; }) .ResultAsync <TestResource>(); resource.ShouldBe(TestResource.Default1()); actual.ShouldBe("CustomTypedCacheHandler: It Works!"); } }
public async Task TypedBuilderFactory_ResolvesCustomCacheHandlers() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseTextOk("Typed Result", r => r.WithPrivateCacheHeader().WithDefaultExpiration()); var factory = container.Resolve <ITypedBuilderFactory>(); var builder = factory.Create(); string actual = null; var result = await builder.WithUri(server.ListeningUri) .Advanced.WithCaching(true) .OnCacheMiss(HandlerPriority.Last, context => { actual = context.Items["CustomTypedCacheHandler"] as string; }) .ResultAsync <string>(); result.ShouldBe("Typed Result"); actual.ShouldBe("CustomTypedCacheHandler: It Works!"); } }
public async Task HttpBuilderFactory_ResolvesCustomConfigurations() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server.WithNextResponseOk("Response"); var factory = container.Resolve <IHttpBuilderFactory>(); var builder = factory.Create(); string actual = null; var response = await builder.WithUri(server.ListeningUri) .Advanced .WithCaching(false) .OnSending(HandlerPriority.Last, context => { actual = context.Items["CustomHttpConfiguration"] as string; }) .ResultAsync(); response.StatusCode.ShouldBe(HttpStatusCode.OK); actual.ShouldBe("CustomHttpConfiguration: It Works!"); } }
public async Task HttpBuilderFactory_TwoBuildersDonNotShareSameSettings() { var container = RegistrationHelpers.CreateContainer(); using (var server = LocalWebServer.ListenInBackground(new XUnitMockLogger(_logger))) { server .WithNextResponseOk("Response1") .WithNextResponseOk("Response2"); var factory = container.Resolve <IHttpBuilderFactory>(); int actual1 = 0; int actual2 = 0; var builder1 = factory.Create().WithUri(server.ListeningUri) .Advanced.WithCaching(false) .WithContextItem("Shared", 1) .OnSending(HandlerPriority.Last, context => { actual1 = (int)context.Items["Shared"]; }); var builder2 = factory.Create().WithUri(server.ListeningUri) .Advanced.WithCaching(false) .WithContextItem("Shared", 2) .OnSending(HandlerPriority.Last, context => { actual2 = (int)context.Items["Shared"]; }); var response1 = await builder1.ResultAsync(); var response2 = await builder2.ResultAsync(); actual1.ShouldNotBe(actual2); } }
private IHttpBuilder CreateBuilder() { var container = RegistrationHelpers.CreateContainer(); return(container.Resolve <IHttpBuilder>()); }
public SpeedTest(ITestOutputHelper logger) { _logger = logger; _container = RegistrationHelpers.CreateContainer(false); }