Put in test fallback for manual error code. Output http mock for later verification.
This commit is contained in:
parent
022de696e3
commit
e389b2404a
2 changed files with 26 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Website.Data;
|
||||
|
@ -50,17 +51,18 @@ namespace Website.Tests.Data {
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Get_WithUrlThatReturns404_ThrowsException() {
|
||||
public void Get_WithUrlThatReturnsError_ThrowsException() {
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Get)
|
||||
.WithUrl("/test")
|
||||
.WithResponse("")
|
||||
.WithErrorStatus(HttpStatusCode.NotFound)
|
||||
.Build();
|
||||
|
||||
var client = new TestApiClient(httpClient);
|
||||
|
||||
client.Invoking(apiClient => apiClient.Get<TestObject>("/404")).Should().Throw<ApiCallException>()
|
||||
.WithMessage("Error calling API http://example.com/404: 404, No matching mock handler for \"GET http://example.com/404\"");
|
||||
.WithMessage("Error calling API http://example.com/404: 404, Not Found");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -69,6 +71,7 @@ namespace Website.Tests.Data {
|
|||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/test")
|
||||
.WithResponse(@"{""TestProperty"":1}")
|
||||
.WithPostBody("\"value\"")
|
||||
.Build();
|
||||
|
||||
var expected = new TestObject {TestProperty = 1};
|
||||
|
@ -102,11 +105,12 @@ namespace Website.Tests.Data {
|
|||
.WithQueryString("query1", "1")
|
||||
.WithQueryString("query2", "2")
|
||||
.WithPostBody("\"value\"")
|
||||
.Build();
|
||||
.Build(out var mockHttpMessageHandler);
|
||||
|
||||
|
||||
var client = new TestApiClient(httpClient);
|
||||
(await client.Post<TestObject>("/test", "value", new {query1 = 1, query2 = 2})).Should().BeNull();
|
||||
await client.Post<object>("/test", "value", new {query1 = 1, query2 = 2});
|
||||
mockHttpMessageHandler.VerifyNoOutstandingExpectation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue