Skip to content

Commit

Permalink
WireMock.Net.FluentAssertions : upgrade to latest FluentAssertions (#635
Browse files Browse the repository at this point in the history
)

* .

* #634

* fix UT
  • Loading branch information
StefH committed Sep 27, 2021
1 parent 772398b commit 2ab075e
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 142 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@
- [#549](https://github.com/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]

# 1.3.8 (03 December 2020)
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
- [#542](https://github.com/WireMock-Net/WireMock.Net/pull/542) - Create dotnet-wiremock tool [feature] contributed by [StefH](https://github.com/StefH)
- [#543](https://github.com/WireMock-Net/WireMock.Net/pull/543) - Add support for .NET 5 [feature] contributed by [StefH](https://github.com/StefH)
- [#544](https://github.com/WireMock-Net/WireMock.Net/pull/544) - Use Java 11 in Azure Pipelines (needed for SonarCloud) [feature] contributed by [StefH](https://github.com/StefH)
- [#545](https://github.com/WireMock-Net/WireMock.Net/pull/545) - Fix SonarCloud OpenCover (coverlet-coverage) [bug] contributed by [StefH](https://github.com/StefH)
- [#547](https://github.com/WireMock-Net/WireMock.Net/pull/547) - Fix Proxying with SSL and NetCoreApp3.1 [bug] contributed by [StefH](https://github.com/StefH)
- [#524](https://github.com/WireMock-Net/WireMock.Net/issues/524) - Proxying with SSL Not Working in .NET Core 3.1 [bug]

# 1.3.7 (17 November 2020)
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)

# 1.3.6 (10 November 2020)
- [#529](https://github.com/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https://github.com/akamud)
- [#535](https://github.com/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https://github.com/StefH)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.4.22</VersionPrefix>
<VersionPrefix>1.4.23</VersionPrefix>
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
Expand Down
6 changes: 3 additions & 3 deletions Generate-ReleaseNotes.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rem https://github.com/StefH/GitHubReleaseNotes

SET version=1.4.22
SET version=1.4.23

GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version%
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%

GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate --template PackageReleaseNotes.template --version %version%
GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate --template PackageReleaseNotes.template --version %version% --token %GH_TOKEN%
4 changes: 2 additions & 2 deletions PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.4.21 (16 September 2021)
- #631 Add WireMock.org RestClient [feature]
# 1.4.22 (22 September 2021)
- #633 Implement Random Delay [feature]

The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AndConstraint<WireMockAssertions> AtAbsoluteUrl(string absoluteUrl, strin

[CustomAssertion]
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value, string because = "", params object[] becauseArgs)
=> WithHeader(expectedKey, new[] {value}, because, becauseArgs);
=> WithHeader(expectedKey, new[] { value }, because, becauseArgs);

[CustomAssertion]
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
Expand Down Expand Up @@ -69,7 +69,7 @@ public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[]

return new AndConstraint<WireMockAssertions>(this);
}

[CustomAssertion]
public AndConstraint<WireMockAssertions> AtUrl(string url, string because = "", params object[] becauseArgs)
{
Expand All @@ -85,10 +85,10 @@ public AndConstraint<WireMockAssertions> AtUrl(string url, string because = "",
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but didn't find it among the calls to {1}.",
_ => url, requests => requests.Select(request => request.Url));

return new AndConstraint<WireMockAssertions>(this);
}

[CustomAssertion]
public AndConstraint<WireMockAssertions> WithProxyUrl(string proxyUrl, string because = "", params object[] becauseArgs)
{
Expand All @@ -104,10 +104,10 @@ public AndConstraint<WireMockAssertions> WithProxyUrl(string proxyUrl, string be
.FailWith(
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but didn't find it among the calls with {1}.",
_ => proxyUrl, requests => requests.Select(request => request.ProxyUrl));

return new AndConstraint<WireMockAssertions>(this);
}

[CustomAssertion]
public AndConstraint<WireMockAssertions> FromClientIP(string clientIP, string because = "", params object[] becauseArgs)
{
Expand All @@ -123,7 +123,7 @@ public AndConstraint<WireMockAssertions> FromClientIP(string clientIP, string be
.FailWith(
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but didn't find it among the calls from IP(s) {1}.",
_ => clientIP, requests => requests.Select(request => request.ClientIP));

return new AndConstraint<WireMockAssertions>(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@
// ReSharper disable once CheckNamespace
namespace WireMock.FluentAssertions
{
/// <summary>
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
/// </summary>
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
{
public WireMockReceivedAssertions(IWireMockServer server)
/// <summary>
/// Create a WireMockReceivedAssertions.
/// </summary>
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
{
Subject = server;
}


/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received a call.
/// </summary>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockAssertions HaveReceivedACall()
{
return new WireMockAssertions(Subject, null);
}


/// <summary>
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
/// </summary>
/// <param name="callsCount"></param>
/// <returns><see cref="WireMockAssertions"/></returns>
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
{
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
}

/// <inheritdoc/>
protected override string Identifier => "wiremockserver";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>FluentAssertions extensions for WireMock.Net</Description>
Expand Down Expand Up @@ -29,13 +29,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="FluentAssertions" Version="5.10.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net451' and '$(TargetFramework)' != 'netstandard1.3'">
<PackageReference Include="FluentAssertions" Version="6.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
</ItemGroup>

</Project>
</Project>
31 changes: 12 additions & 19 deletions test/WireMock.Net.Tests/FluentAssertions/WireMockAssertionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using FluentAssertions;
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
using WireMock.FluentAssertions;
using System.Threading.Tasks;
using WireMock.Settings;
using Xunit;
using static System.Environment;

namespace WireMock.Net.Tests.FluentAssertions
Expand Down Expand Up @@ -100,16 +100,9 @@ public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMad
.HaveReceivedACall()
.WithHeader("Authorization", "value");

var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
.ToDictionary(x => x.Key, x => x.Value)
.ToList();

var sentHeaderString = "{" + string.Join(", ", sentHeaders) + "}";

act.Should().Throw<Exception>()
.And.Message.Should()
.Be(
$"Expected headers from requests sent {sentHeaderString} to contain key \"Authorization\".{NewLine}");
.Contain("to contain key \"Authorization\".");
}

[Fact]
Expand Down Expand Up @@ -156,7 +149,7 @@ public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderWithMultipl
.And.Message.Should()
.Be($"{string.Join(NewLine, missingValue1Message, missingValue2Message)}{NewLine}");
}

[Fact]
public async Task AtUrl_WhenACallWasMadeToUrl_Should_BeOK()
{
Expand Down Expand Up @@ -200,7 +193,7 @@ public async Task WithProxyUrl_WhenACallWasMadeWithProxyUrl_Should_BeOK()
{
_server.ResetMappings();
_server.Given(Request.Create().UsingAnyMethod())
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings {Url = "http://localhost:9999"}));
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));

await _httpClient.GetAsync("");

Expand All @@ -214,8 +207,8 @@ public void WithProxyUrl_Should_ThrowWhenNoCallsWereMade()
{
_server.ResetMappings();
_server.Given(Request.Create().UsingAnyMethod())
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings {Url = "http://localhost:9999"}));
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));

Action act = () => _server.Should()
.HaveReceivedACall()
.WithProxyUrl("anyurl");
Expand All @@ -231,8 +224,8 @@ public async Task WithProxyUrl_Should_ThrowWhenNoCallsWithTheProxyUrlWereMade()
{
_server.ResetMappings();
_server.Given(Request.Create().UsingAnyMethod())
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings {Url = "http://localhost:9999"}));
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));

await _httpClient.GetAsync("");

Action act = () => _server.Should()
Expand All @@ -244,7 +237,7 @@ public async Task WithProxyUrl_Should_ThrowWhenNoCallsWithTheProxyUrlWereMade()
.Be(
$"Expected _server to have been called with proxy url \"anyurl\", but didn't find it among the calls with {{\"http://localhost:9999\"}}.");
}

[Fact]
public async Task FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task Response_WithCallback_And_Additional_WithStatusCode_And_WithHe

// Assert
response.Message.BodyData.BodyAsString.Should().Be("/fooBar");
response.Message.StatusCode.Should().Be(HttpStatusCode.Accepted);
response.Message.StatusCode.Should().Be((int) HttpStatusCode.Accepted);
response.Message.Headers[header].Should().ContainSingle("Stef");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using FluentAssertions;
using HandlebarsDotNet;
Expand Down Expand Up @@ -216,7 +216,7 @@ public void Response_ProvideResponse_Handlebars_Linq1_ParseError_Throws_Exceptio
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(request, _settings);

// Assert
a.Should().Throw<HandlebarsException>();
a.Should().ThrowAsync<HandlebarsException>();
}

[Fact]
Expand All @@ -243,7 +243,7 @@ public void Response_ProvideResponse_Handlebars_Linq2_ParseError_Throws_Exceptio
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(request, _settings);

// Assert
a.Should().Throw<HandlebarsException>();
a.Should().ThrowAsync<HandlebarsException>();
}
}
}
Loading

0 comments on commit 2ab075e

Please sign in to comment.