-
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 #176 from hassanhabib/users/hassanhabib/controller…
…s-custome-http CONTROLLERS: Support Custom Http Methods (Client & Server)
- Loading branch information
Showing
17 changed files
with
814 additions
and
2 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
RESTFulSense.Tests.Acceptance/Tests/RestfulApiClientTests.SendHttpRequest.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,89 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
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 void ShouldSendContentWithNoResponseAndDeserializeContent() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity inputTEntity = randomTEntity; | ||
TEntity expectedTEntity = inputTEntity; | ||
string mediaType = "application/json"; | ||
bool ignoreDefaultValues = false; | ||
string randomHttpMethodName = GetRandomHttpMethodName(); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingMethod(randomHttpMethodName)) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200)); | ||
|
||
// when | ||
Action actualResponseResult = async () => | ||
await this.restfulApiClient.SendHttpRequestAsync<TEntity>( | ||
method: randomHttpMethodName, | ||
relativeUrl: relativeUrl, | ||
content: inputTEntity, | ||
mediaType: mediaType, | ||
ignoreDefaultValues: ignoreDefaultValues, | ||
serializationFunction: SerializationContentFunction); | ||
|
||
// then | ||
actualResponseResult.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldSendContentWithTContentReturnsTResultAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity inputTEntity = randomTEntity; | ||
TEntity expectedTEntity = inputTEntity; | ||
string mediaType = "text/json"; | ||
bool ignoreDefaultValues = false; | ||
string randomHttpMethodName = GetRandomHttpMethodName(); | ||
|
||
string expectedBody = | ||
JsonConvert.SerializeObject(randomTEntity); | ||
|
||
this.wiremockServer.Given( | ||
Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingMethod(randomHttpMethodName)) | ||
.RespondWith( | ||
Response.Create() | ||
.WithStatusCode(200) | ||
.WithHeader("Content-Type", mediaType) | ||
.WithBody(expectedBody)); | ||
|
||
// when | ||
TEntity actualTEntity = | ||
await this.restfulApiClient.SendHttpRequestAsync<TEntity, TEntity>( | ||
method: randomHttpMethodName, | ||
relativeUrl: relativeUrl, | ||
content: inputTEntity, | ||
mediaType: mediaType, | ||
ignoreDefaultValues: ignoreDefaultValues, | ||
serializationFunction: SerializationContentFunction, | ||
deserializationFunction: DeserializationContentFunction); | ||
|
||
// then | ||
actualTEntity.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
88 changes: 88 additions & 0 deletions
88
RESTFulSense.Tests.Acceptance/Tests/RestfulSenseApiFactoryTests.SendHttpRequest.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,88 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
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 void ShouldSendContentWithNoResponseAndDeserializeContent() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity inputTEntity = randomTEntity; | ||
TEntity expectedTEntity = inputTEntity; | ||
string mediaType = "application/json"; | ||
bool ignoreDefaultValues = false; | ||
string randomHttpMethodName = GetRandomHttpMethodName(); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingMethod(randomHttpMethodName)) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200)); | ||
|
||
// when | ||
Action actualResponseResult = async () => | ||
await this.factoryClient.SendHttpRequestAsync<TEntity>( | ||
method: randomHttpMethodName, | ||
relativeUrl: relativeUrl, | ||
content: inputTEntity, | ||
mediaType: mediaType, | ||
ignoreDefaultValues: ignoreDefaultValues, | ||
serializationFunction: SerializationContentFunction); | ||
|
||
// then | ||
actualResponseResult.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldSendContentWithTContentReturnsTResultAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity inputTEntity = randomTEntity; | ||
TEntity expectedTEntity = inputTEntity; | ||
string mediaType = "text/json"; | ||
bool ignoreDefaultValues = false; | ||
string randomHttpMethodName = GetRandomHttpMethodName(); | ||
|
||
string expectedBody = | ||
JsonConvert.SerializeObject(randomTEntity); | ||
|
||
this.wiremockServer.Given( | ||
Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingMethod(randomHttpMethodName)) | ||
.RespondWith( | ||
Response.Create() | ||
.WithStatusCode(200) | ||
.WithHeader("Content-Type", mediaType) | ||
.WithBody(expectedBody)); | ||
|
||
// when | ||
TEntity actualTEntity = | ||
await this.factoryClient.SendHttpRequestAsync<TEntity, TEntity>( | ||
method: randomHttpMethodName, | ||
relativeUrl: relativeUrl, | ||
content: inputTEntity, | ||
mediaType: mediaType, | ||
ignoreDefaultValues: ignoreDefaultValues, | ||
serializationFunction: SerializationContentFunction, | ||
deserializationFunction: ContentDeserializationFunction); | ||
|
||
// then | ||
actualTEntity.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
Oops, something went wrong.