Expand builder and tests for query strings and post body
This commit is contained in:
parent
524b418969
commit
022de696e3
2 changed files with 66 additions and 7 deletions
|
@ -21,7 +21,11 @@ namespace Website.Tests.Data {
|
|||
|
||||
[Fact]
|
||||
public async Task Get_WithUrl_ReturnsResult() {
|
||||
var httpClient = new HttpClientBuilder().WithMethod(HttpMethod.Get).WithUrl("/test").WithResponse(@"{""TestProperty"":1}").Build();
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Get)
|
||||
.WithUrl("/test")
|
||||
.WithResponse(@"{""TestProperty"":1}")
|
||||
.Build();
|
||||
|
||||
var expected = new TestObject {TestProperty = 1};
|
||||
|
||||
|
@ -31,7 +35,13 @@ namespace Website.Tests.Data {
|
|||
|
||||
[Fact]
|
||||
public async Task Get_WithUrlAndQuery_ReturnsResult() {
|
||||
var httpClient = new HttpClientBuilder().WithMethod(HttpMethod.Get).WithUrl("/test?query1=1&query2=2").WithResponse(@"{""TestProperty"":1}").Build();
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Get)
|
||||
.WithUrl("/test")
|
||||
.WithQueryString("query1", "1")
|
||||
.WithQueryString("query2", "2")
|
||||
.WithResponse(@"{""TestProperty"":1}")
|
||||
.Build();
|
||||
|
||||
var expected = new TestObject {TestProperty = 1};
|
||||
|
||||
|
@ -41,7 +51,11 @@ namespace Website.Tests.Data {
|
|||
|
||||
[Fact]
|
||||
public void Get_WithUrlThatReturns404_ThrowsException() {
|
||||
var httpClient = new HttpClientBuilder().WithMethod(HttpMethod.Get).WithUrl("/test").WithResponse("").Build();
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Get)
|
||||
.WithUrl("/test")
|
||||
.WithResponse("")
|
||||
.Build();
|
||||
|
||||
var client = new TestApiClient(httpClient);
|
||||
|
||||
|
@ -51,7 +65,11 @@ namespace Website.Tests.Data {
|
|||
|
||||
[Fact]
|
||||
public async Task Post_WithUrlAndValue_ReturnsResult() {
|
||||
var httpClient = new HttpClientBuilder().WithMethod(HttpMethod.Post).WithUrl("/test").WithResponse(@"{""TestProperty"":1}").Build();
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/test")
|
||||
.WithResponse(@"{""TestProperty"":1}")
|
||||
.Build();
|
||||
|
||||
var expected = new TestObject {TestProperty = 1};
|
||||
|
||||
|
@ -61,12 +79,34 @@ namespace Website.Tests.Data {
|
|||
|
||||
[Fact]
|
||||
public async Task Post_WithUrlAndValueAndQuery_ReturnsResult() {
|
||||
var httpClient = new HttpClientBuilder().WithMethod(HttpMethod.Post).WithUrl("/test?query1=1&query2=2").WithResponse(@"{""TestProperty"":1}").Build();
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/test")
|
||||
.WithQueryString("query1", "1")
|
||||
.WithQueryString("query2", "2")
|
||||
.WithPostBody("\"value\"")
|
||||
.WithResponse(@"{""TestProperty"":1}")
|
||||
.Build();
|
||||
|
||||
var expected = new TestObject {TestProperty = 1};
|
||||
|
||||
var client = new TestApiClient(httpClient);
|
||||
(await client.Post<TestObject>("/test", "value", new {query1 = 1, query2 = 2})).Should().BeEquivalentTo(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Post_WithUrlAndValueAndQuery_ReturnsNoResult() {
|
||||
var httpClient = new HttpClientBuilder()
|
||||
.WithMethod(HttpMethod.Post)
|
||||
.WithUrl("/test")
|
||||
.WithQueryString("query1", "1")
|
||||
.WithQueryString("query2", "2")
|
||||
.WithPostBody("\"value\"")
|
||||
.Build();
|
||||
|
||||
|
||||
var client = new TestApiClient(httpClient);
|
||||
(await client.Post<TestObject>("/test", "value", new {query1 = 1, query2 = 2})).Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue