From 6194f4e46036e07b1f8aac4ab6f911e809e7f093 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 15 Oct 2021 12:59:03 +0200 Subject: [PATCH] Update NotNullOrEmptyMatcher to also implement IStringMatcher (#654) * Update NotNullOrEmptyMatcher to also implement IStringMatcher * NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray * 24 --- CHANGELOG.md | 10 ++++++- Generate-ReleaseNotes.cmd | 2 +- PackageReleaseNotes.txt | 8 ++++-- .../Matchers/NotNullOrEmptyMatcher.cs | 18 +++++++++++- .../Matchers/NotNullOrEmptyMatcherTests.cs | 28 +++++++++++++++++-- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df5d5ae0..51457ae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.24 (15 October 2021) +- [#643](https://github.com/WireMock-Net/WireMock.Net/pull/643) - Support edge case: first object, next an array. [feature] contributed by [leolplex](https://github.com/leolplex) +- [#644](https://github.com/WireMock-Net/WireMock.Net/pull/644) - Mapping headers in OpenAPI [feature] contributed by [leolplex](https://github.com/leolplex) +- [#649](https://github.com/WireMock-Net/WireMock.Net/pull/649) - Refactor method name MapHeaders and httpStatusCode contributed by [leolplex](https://github.com/leolplex) +- [#651](https://github.com/WireMock-Net/WireMock.Net/pull/651) - Implement PatternAsFile for StringMatcher [feature] contributed by [StefH](https://github.com/StefH) + # 1.4.23 (27 September 2021) - [#635](https://github.com/WireMock-Net/WireMock.Net/pull/635) - WireMock.Net.FluentAssertions : upgrade to latest FluentAssertions [feature] contributed by [StefH](https://github.com/StefH) - [#634](https://github.com/WireMock-Net/WireMock.Net/issues/634) - Upgrade to latest FluentAssertions [bug] @@ -111,7 +117,6 @@ - [#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) @@ -119,6 +124,9 @@ - [#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) diff --git a/Generate-ReleaseNotes.cmd b/Generate-ReleaseNotes.cmd index 274e6525..0b74750a 100644 --- a/Generate-ReleaseNotes.cmd +++ b/Generate-ReleaseNotes.cmd @@ -1,6 +1,6 @@ rem https://github.com/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% diff --git a/PackageReleaseNotes.txt b/PackageReleaseNotes.txt index c8bcf40b..391528a5 100644 --- a/PackageReleaseNotes.txt +++ b/PackageReleaseNotes.txt @@ -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://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs b/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs index 00354933..4b16b48e 100644 --- a/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs +++ b/src/WireMock.Net/Matchers/NotNullOrEmptyMatcher.cs @@ -1,4 +1,6 @@ using System.Linq; +using AnyOfTypes; +using WireMock.Models; namespace WireMock.Matchers { @@ -6,7 +8,7 @@ namespace WireMock.Matchers /// NotNullOrEmptyMatcher /// /// - public class NotNullOrEmptyMatcher : IObjectMatcher + public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher { /// public string Name => "NotNullOrEmptyMatcher"; @@ -48,5 +50,19 @@ namespace WireMock.Matchers return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match)); } + + /// + public double IsMatch(string input) + { + var match = !string.IsNullOrEmpty(input); + + return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match)); + } + + /// + public AnyOf[] GetPatterns() + { + return new AnyOf[0]; + } } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Matchers/NotNullOrEmptyMatcherTests.cs b/test/WireMock.Net.Tests/Matchers/NotNullOrEmptyMatcherTests.cs index ca5c7242..151fec55 100644 --- a/test/WireMock.Net.Tests/Matchers/NotNullOrEmptyMatcherTests.cs +++ b/test/WireMock.Net.Tests/Matchers/NotNullOrEmptyMatcherTests.cs @@ -36,11 +36,25 @@ namespace WireMock.Net.Tests.Matchers [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); @@ -56,5 +70,15 @@ namespace WireMock.Net.Tests.Matchers // Assert result.Should().Be(1.0); } + + [Fact] + public void NotNullOrEmptyMatcher_GetPatterns_Should_Return_EmptyArray() + { + // Act + var patterns = new NotNullOrEmptyMatcher().GetPatterns(); + + // Assert + patterns.Should().BeEmpty(); + } } } \ No newline at end of file