Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NotNullOrEmptyMatcher to also implement IStringMatcher #654

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.4.24 (15 October 2021)
- [#643](https:/WireMock-Net/WireMock.Net/pull/643) - Support edge case: first object, next an array. [feature] contributed by [leolplex](https:/leolplex)
- [#644](https:/WireMock-Net/WireMock.Net/pull/644) - Mapping headers in OpenAPI [feature] contributed by [leolplex](https:/leolplex)
- [#649](https:/WireMock-Net/WireMock.Net/pull/649) - Refactor method name MapHeaders and httpStatusCode contributed by [leolplex](https:/leolplex)
- [#651](https:/WireMock-Net/WireMock.Net/pull/651) - Implement PatternAsFile for StringMatcher [feature] contributed by [StefH](https:/StefH)

# 1.4.23 (27 September 2021)
- [#635](https:/WireMock-Net/WireMock.Net/pull/635) - WireMock.Net.FluentAssertions : upgrade to latest FluentAssertions [feature] contributed by [StefH](https:/StefH)
- [#634](https:/WireMock-Net/WireMock.Net/issues/634) - Upgrade to latest FluentAssertions [bug]
Expand Down Expand Up @@ -111,14 +117,16 @@
- [#549](https:/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]

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

# 1.3.6 (10 November 2020)
- [#529](https:/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https:/akamud)
- [#535](https:/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https:/StefH)
Expand Down
2 changes: 1 addition & 1 deletion Generate-ReleaseNotes.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rem https:/StefH/GitHubReleaseNotes

SET version=1.4.23
SET version=1.4.24

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

Expand Down
8 changes: 5 additions & 3 deletions PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 1.4.23 (27 September 2021)
- #635 WireMock.Net.FluentAssertions : upgrade to latest FluentAssertions [feature]
- #634 Upgrade to latest FluentAssertions [bug]
# 1.4.24 (15 October 2021)
- #643 Support edge case: first object, next an array. [feature]
- #644 Mapping headers in OpenAPI [feature]
- #649 Refactor method name MapHeaders and httpStatusCode
- #651 Implement PatternAsFile for StringMatcher [feature]

The full release notes can be found here: https:/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
18 changes: 17 additions & 1 deletion src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Linq;
using AnyOfTypes;
using WireMock.Models;

namespace WireMock.Matchers
{
/// <summary>
/// NotNullOrEmptyMatcher
/// </summary>
/// <seealso cref="IObjectMatcher" />
public class NotNullOrEmptyMatcher : IObjectMatcher
public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
{
/// <inheritdoc cref="IMatcher.Name"/>
public string Name => "NotNullOrEmptyMatcher";
Expand Down Expand Up @@ -48,5 +50,19 @@ public double IsMatch(object input)

return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
}

/// <inheritdoc cref="IStringMatcher.IsMatch"/>
public double IsMatch(string input)
{
var match = !string.IsNullOrEmpty(input);

return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
}

/// <inheritdoc cref="IStringMatcher.GetPatterns"/>
public AnyOf<string, StringPattern>[] GetPatterns()
{
return new AnyOf<string, StringPattern>[0];
}
}
}
28 changes: 26 additions & 2 deletions test/WireMock.Net.Tests/Matchers/NotNullOrEmptyMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,25 @@ public void NotNullOrEmptyMatcher_IsMatch_ByteArray(byte[] data, double expected
[InlineData(null, 0.0)]
[InlineData("", 0.0)]
[InlineData("x", 1.0)]
public void NotNullOrEmptyMatcher_IsMatch_String(string data, double expected)
public void NotNullOrEmptyMatcher_IsMatch_String(string @string, double expected)
{
// Act
var matcher = new NotNullOrEmptyMatcher();
double result = matcher.IsMatch(data);
double result = matcher.IsMatch(@string);

// Assert
result.Should().Be(expected);
}

[Theory]
[InlineData(null, 0.0)]
[InlineData("", 0.0)]
[InlineData("x", 1.0)]
public void NotNullOrEmptyMatcher_IsMatch_StringAsObject(string @string, double expected)
{
// Act
var matcher = new NotNullOrEmptyMatcher();
double result = matcher.IsMatch((object)@string);

// Assert
result.Should().Be(expected);
Expand All @@ -56,5 +70,15 @@ public void NotNullOrEmptyMatcher_IsMatch_Json()
// Assert
result.Should().Be(1.0);
}

[Fact]
public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray()
{
// Act
var patterns = new NotNullOrEmptyMatcher().GetPatterns();

// Assert
patterns.Should().BeEmpty();
}
}
}