-
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 #160 from glhays/users/glhays/acceptance-init-project
ACCEPTANCE: RESTFulSense WireMock Tests
- Loading branch information
Showing
20 changed files
with
1,961 additions
and
127 deletions.
There are no files selected for viewing
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,15 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace RESTFulSense.Tests.Acceptance.Models | ||
{ | ||
public class TEntity | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
public DateTimeOffset CreateDate { get; set; } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
RESTFulSense.Tests.Acceptance/RESTFulSense.Tests.Acceptance.csproj
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>disable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CleanMoq" Version="1.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="Tynamix.ObjectFiller" Version="1.5.8" /> | ||
<PackageReference Include="WireMock.Net" Version="1.5.47" /> | ||
<PackageReference Include="xunit" Version="2.6.6" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RESTFulSense\RESTFulSense.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
104 changes: 104 additions & 0 deletions
104
RESTFulSense.Tests.Acceptance/Tests/RestfulApiClientTests.DeleteContent.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,104 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
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 ShouldDeleteContentAsync() | ||
{ | ||
// given | ||
this.wiremockServer | ||
.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200)); | ||
|
||
// when . then | ||
await this.restfulApiClient.DeleteContentAsync( | ||
relativeUrl: relativeUrl); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldDeleteContentCancellationTokenAsync() | ||
{ | ||
// given | ||
var cancellationToken = new CancellationToken(canceled: false); | ||
|
||
this.wiremockServer | ||
.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200)); | ||
|
||
// when . then | ||
await this.restfulApiClient.DeleteContentAsync( | ||
relativeUrl: relativeUrl, | ||
cancellationToken: cancellationToken); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldDeleteContentReturnsExpectedContentDeserializeAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity expectedDeletedTEntity = randomTEntity; | ||
|
||
this.wiremockServer | ||
.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200) | ||
.WithBodyAsJson(randomTEntity)); | ||
|
||
// when | ||
TEntity actualDeletedTEntity = | ||
await this.restfulApiClient.DeleteContentAsync<TEntity>( | ||
relativeUrl: relativeUrl, | ||
deserializationFunction: DeserializationContentFunction); | ||
|
||
// then | ||
actualDeletedTEntity.Should().BeEquivalentTo(expectedDeletedTEntity); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldDeleteContentReturnsExpectedContentCancellationTokenAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity expectedDeletedTEntity = randomTEntity; | ||
var cancellationToken = new CancellationToken(canceled: false); | ||
|
||
this.wiremockServer | ||
.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200) | ||
.WithBodyAsJson(randomTEntity)); | ||
|
||
// when | ||
TEntity actualDeletedTEntity = | ||
await this.restfulApiClient.DeleteContentAsync<TEntity>( | ||
relativeUrl: relativeUrl, | ||
cancellationToken: cancellationToken); | ||
|
||
// then | ||
actualDeletedTEntity.Should().BeEquivalentTo(expectedDeletedTEntity); | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
RESTFulSense.Tests.Acceptance/Tests/RestfulApiClientTests.GetContent.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,113 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
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 ShouldGetContentWithDeserializationFunctionAsync() | ||
{ | ||
// given | ||
TEntity randomTEntity = GetRandomTEntity(); | ||
TEntity expectedTEntity = randomTEntity; | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(200) | ||
.WithBodyAsJson(expectedTEntity)); | ||
|
||
// when | ||
TEntity actualTEntityEntity = | ||
await this.restfulApiClient.GetContentAsync<TEntity>( | ||
relativeUrl: relativeUrl, | ||
deserializationFunction: DeserializationContentFunction); | ||
|
||
// then | ||
actualTEntityEntity.Should().BeEquivalentTo(expectedTEntity); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldCancelGetContentDeserializationIfCancellationInvokedAsync() | ||
{ | ||
// given | ||
TEntity someContent = GetRandomTEntity(); | ||
var expectedCanceledTaskException = new TaskCanceledException(); | ||
var taskCancelInvoked = new CancellationToken(canceled: true); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithBodyAsJson(someContent)); | ||
|
||
// when | ||
TaskCanceledException actualCanceledTask = | ||
await Assert.ThrowsAsync<TaskCanceledException>(async () => | ||
await this.restfulApiClient.GetContentAsync<TEntity>( | ||
relativeUrl: relativeUrl, | ||
cancellationToken: taskCancelInvoked, | ||
deserializationFunction: DeserializationContentFunction)); | ||
|
||
// then | ||
actualCanceledTask.Should().BeEquivalentTo(expectedCanceledTaskException); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldReturnStringOnGetContentStringAsync() | ||
{ | ||
// given | ||
string someContent = CreateRandomContent(); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithBody(someContent)); | ||
|
||
// when | ||
string actualContent = | ||
await this.restfulApiClient.GetContentStringAsync(relativeUrl); | ||
|
||
// then | ||
actualContent.Should().BeEquivalentTo(someContent); | ||
} | ||
|
||
[Fact] | ||
private async Task ShouldReturnStreamOnGetContentStreamAsync() | ||
{ | ||
// given | ||
string expectedContent = CreateRandomContent(); | ||
|
||
this.wiremockServer.Given(Request.Create() | ||
.WithPath(relativeUrl) | ||
.UsingGet()) | ||
.RespondWith(Response.Create() | ||
.WithBody(expectedContent)); | ||
|
||
// when | ||
Stream expectedContentStream = | ||
await this.restfulApiClient.GetContentStreamAsync( | ||
relativeUrl: relativeUrl); | ||
|
||
string actualReadStream = | ||
await ReadStreamToEndAsync(expectedContentStream); | ||
|
||
// then | ||
actualReadStream.Should().BeEquivalentTo(expectedContent); | ||
} | ||
} | ||
} |
Oops, something went wrong.