public void Given_Default_When_Instantiated_Then_It_Should_Return_Value() { var instance = new HttpSchemaSink(); instance.BaseLocation.Should().BeEmpty(); instance.Encoding.Should().Be(Encoding.UTF8); }
public async Task Given_Location_And_Path_When_SetSchemaAsync_Invoked_Then_It_Should_Return_Result(string schema, string location, string path, HttpStatusCode statusCode) { var content = new StringContent(schema); var response = new HttpResponseMessage(statusCode) { Content = content }; var options = new HttpMessageOptions() { HttpResponseMessage = response }; var handler = new FakeHttpMessageHandler(options); var httpClient = new HttpClient(handler); var instance = new HttpSchemaSink() .WithBaseLocation(location) .WithHttpClient(httpClient); var result = await instance.SetSchemaAsync(schema, path).ConfigureAwait(false); result.Should().BeTrue(); content.Dispose(); handler.Dispose(); httpClient.Dispose(); }
public void Given_Null_Path_When_GetSchemaAsync_Invoked_Then_It_Should_Throw_Exception() { var instance = new HttpSchemaSink(); Func <Task> func = async() => await instance.GetSchemaAsync(null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); }
public void Given_Null_BaseLocation_When_SetSchemaAsync_Invoked_Then_It_Should_Throw_Exception() { var instance = new HttpSchemaSink(); Func <Task> func = async() => await instance.SetSchemaAsync("hello-world", "default.json").ConfigureAwait(false); func.Should().Throw <InvalidOperationException>(); }
public void Given_Null_HttpClient_When_WithHttpClient_Invoked_Then_It_Should_Throw_Exception() { var instance = new HttpSchemaSink(); Action action = () => instance.WithHttpClient(null); action.Should().Throw <ArgumentNullException>(); }
public void Given_Uri_When_WithBaseLocation_Invoked_Then_It_Should_Return_Result(string uri) { var instance = new HttpSchemaSink(); var result = instance.WithBaseLocation(new Uri(uri)); result.BaseLocation.Trim('/').Should().BeEquivalentTo(uri.Trim('/')); }
public void Given_Null_Uri_When_WithBaseLocation_Invoked_Then_It_Should_Throw_Exception() { var instance = new HttpSchemaSink(); Action action = () => instance.WithBaseLocation((Uri)null); action.Should().Throw <ArgumentNullException>(); }
public void Given_Encoding_When_Instantiated_Then_It_Should_Return_Value() { var encoding = Encoding.ASCII; var instance = new HttpSchemaSink() { Encoding = encoding }; instance.BaseLocation.Should().BeEmpty(); instance.Encoding.Should().Be(encoding); }
public void Given_HttpClient_When_WithHttpClient_Invoked_Then_It_Should_Return_Result() { var httpClient = new HttpClient(); var instance = new HttpSchemaSink(); var result = instance.WithHttpClient(httpClient); var field = typeof(HttpSchemaSink).GetField("_httpClient", BindingFlags.NonPublic | BindingFlags.Instance); field.GetValue(instance).Should().Be(httpClient); httpClient.Dispose(); }
public void Given_HttpClient_When_WithHttpClient_Invoked_Then_It_Should_Return_Result() { var sink = new HttpSchemaSink(); var httpClient = new HttpClient(); var result = SchemaSinkExtensions.WithHttpClient(sink, httpClient); result .Should().NotBeNull() .And.BeAssignableTo <ISchemaSink>(); httpClient.Dispose(); }
public void Given_Schema_And_Path_And_ErrorResponse_When_SetSchemaAsync_Invoked_Then_It_Should_Throw_Exception(string schema, string path, HttpStatusCode statusCode) { var response = new HttpResponseMessage(statusCode); var options = new HttpMessageOptions() { HttpResponseMessage = response }; var handler = new FakeHttpMessageHandler(options); var httpClient = new HttpClient(handler); var instance = new HttpSchemaSink() .WithHttpClient(httpClient); Func <Task> func = async() => await instance.SetSchemaAsync(schema, path).ConfigureAwait(false); func.Should().Throw <HttpRequestException>(); handler.Dispose(); httpClient.Dispose(); }