-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from hassanhabib/users/hassanhabib/clients-ex…
…ecute-async CLIENTS: Execute Any API Call w/ Validations
- Loading branch information
Showing
84 changed files
with
449 additions
and
197 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
RESTFulSense.Tests.Acceptance/Tests/RestfulApiClientTests.ExecuteHttpCall.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using RESTFulSense.Tests.Acceptance.Models; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace RESTFulSense.Tests.Acceptance.Tests | ||
{ | ||
public partial class RestfulApiClientTests | ||
{ | ||
|
||
[Fact] | ||
private async Task ShouldExecuteHttpCallAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity expectedTEntity = randomTEntity; | ||
var httpClient = new HttpClient(); | ||
httpClient.BaseAddress = new Uri(this.wiremockServer.Urls[0]); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200) | ||
.WithBodyAsJson(expectedTEntity)); | ||
|
||
// when | ||
HttpResponseMessage httpResponseMessage = | ||
await this.restfulApiClient.ExecuteHttpCallAsync( | ||
httpClient.GetAsync("/tests")); | ||
|
||
TEntity actualTEntityEntity = | ||
JsonConvert.DeserializeObject<TEntity>( | ||
await httpResponseMessage.Content.ReadAsStringAsync()); | ||
|
||
// then | ||
actualTEntityEntity.Should().BeEquivalentTo(expectedTEntity); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
RESTFulSense.Tests.Acceptance/Tests/RestfulSenseApiFactoryTests.ExecuteHttpCall.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using RESTFulSense.Tests.Acceptance.Models; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace RESTFulSense.Tests.Acceptance.Tests | ||
{ | ||
public partial class RestfulSenseApiFactoryTests | ||
{ | ||
[Fact] | ||
private async Task ShouldExecuteHttpCallAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity expectedTEntity = randomTEntity; | ||
var httpClient = new HttpClient(); | ||
httpClient.BaseAddress = new Uri(this.wiremockServer.Urls[0]); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200) | ||
.WithBodyAsJson(expectedTEntity)); | ||
|
||
// when | ||
HttpResponseMessage httpResponseMessage = | ||
await this.factoryClient.ExecuteHttpCallAsync( | ||
httpClient.GetAsync("/tests")); | ||
|
||
TEntity actualTEntityEntity = | ||
JsonConvert.DeserializeObject<TEntity>( | ||
await httpResponseMessage.Content.ReadAsStringAsync()); | ||
|
||
// then | ||
actualTEntityEntity.Should().BeEquivalentTo(expectedTEntity); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.