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

Stef negate matcher #134

Merged
merged 6 commits into from
May 12, 2018
Merged

Stef negate matcher #134

merged 6 commits into from
May 12, 2018

Conversation

alastairtree
Copy link
Collaborator

No description provided.

@alastairtree alastairtree self-assigned this May 11, 2018
@codecov
Copy link

codecov bot commented May 11, 2018

Codecov Report

Merging #134 into master will increase coverage by 0.9%.
The diff coverage is 85.43%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #134     +/-   ##
=======================================
+ Coverage   67.09%    68%   +0.9%     
=======================================
  Files          79     80      +1     
  Lines        2875   2963     +88     
  Branches      390    394      +4     
=======================================
+ Hits         1929   2015     +86     
- Misses        728    731      +3     
+ Partials      218    217      -1
Impacted Files Coverage Δ
src/WireMock.Net/Server/FluentMockServer.cs 50.41% <0%> (ø) ⬆️
src/WireMock.Net/Matchers/SimMetricsMatcher.cs 60.86% <100%> (+5.86%) ⬆️
src/WireMock.Net/Matchers/WildcardMatcher.cs 100% <100%> (ø) ⬆️
src/WireMock.Net/Matchers/MatchBehaviourHelper.cs 100% <100%> (ø)
....Net/Matchers/Request/RequestMessageBodyMatcher.cs 96.87% <100%> (ø) ⬆️
src/WireMock.Net/Matchers/ExactObjectMatcher.cs 100% <100%> (ø) ⬆️
src/WireMock.Net/Server/FluentMockServer.Admin.cs 39.96% <100%> (ø) ⬆️
...et/Matchers/Request/RequestMessageCookieMatcher.cs 93.02% <100%> (+14.45%) ⬆️
src/WireMock.Net/Admin/Mappings/MatcherModel.cs 100% <100%> (ø) ⬆️
...et/Matchers/Request/RequestMessageHeaderMatcher.cs 94.11% <100%> (+6.36%) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cf283e...d3640d0. Read the comment docs.

Copy link
Collaborator Author

@alastairtree alastairtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done some testing and it behaves as I would expect. Couple of minor things in comments but i think this is in good shape.

.WithHeader("x", "1", MatchBehaviour.RejectOnMatch)
.UsingAnyMethod())
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""reject""}"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we make this example more realistic - like the absense of an API key header returns 401 unauthorised?

var jtoken = JToken.Parse(input);
match = IsMatch(jtoken);
}
catch (Exception)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to catch the exact exception? Wouldn't want to inadvertently catch a SystemOutOfMemoryException for example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll fix this.

/// </returns>
IRequestBuilder UsingAnyVerb();
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder UsingAnyMethod();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this must be a breaking public API change? Worth obsoleting and reinstating the old one? Of following SemVer with the versioning?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these again with [Obsolete].

@@ -20,23 +20,24 @@ public static IMatcher Map([CanBeNull] MatcherModel matcher)
string matcherType = parts.Length > 1 ? parts[1] : null;

string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor but unnecessary comparison with true here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed because RejectOnMatch is a nullable bool.

.UsingAnyMethod())
.RespondWith(Response.Create()
.WithStatusCode(HttpStatusCode.Unauthorized)
.WithBody(@"{ ""result"": ""api-key missing""}"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tweaked this example a bit - think it makes more sense now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Collaborator

@StefH StefH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@StefH
Copy link
Collaborator

StefH commented May 12, 2018

Thanks for code review. and your updates. I'll merge this to main now.

@StefH StefH merged commit a8ddd31 into master May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants