-
-
Notifications
You must be signed in to change notification settings - Fork 207
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
FluentAssertions extensions are not open for extension #1075
Comments
@chrischu using System;
using System.Linq;
using FluentAssertions;
using FluentAssertions.Execution;
using WireMock.FluentAssertions;
namespace WireMock.Net.Tests.FluentAssertions;
public static class WireMockAssertionsExtensions
{
[CustomAssertion]
public static AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl2(this WireMockAssertions assertions,
string absoluteUrl, string because = "", params object[] becauseArgs)
{
var (filter, condition) = assertions.BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
Execute.Assertion
.BecauseOf(because, becauseArgs)
.Given(() => assertions.RequestMessages)
.ForCondition(requests => assertions.CallsCount == 0 || requests.Any())
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
absoluteUrl
)
.Then
.ForCondition(condition)
.FailWith(
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but didn't find it among the calls to {1}.",
_ => absoluteUrl,
requests => requests.Select(request => request.AbsoluteUrl)
);
assertions.FilterRequestMessages(filter);
return new AndWhichConstraint<WireMockAssertions, string>(assertions, absoluteUrl);
}
} Note that the RequestMessages, BuildFilterAndCondition and FilterRequestMessages are made public so these can be used in the extension methods. Would this fix your issue? And if you have any useful default fliuent extensions, you can also add these to this project using a PR. |
Oh sorry I just saw the comment, yes this looks perfect, thank you! |
Is your feature request related to a problem? Please describe.
Currently the FluentAssertion extensions offer a pretty small feature set, which would not be a problem by itself, but the fact that they are not very open for extension makes this really problematic.
Describe the solution you'd like
I would like to for example access all the filtered requests on the
WireMockAssertions
object. That way I could write my own extension methods for it to for example assert that a request was using a specific path (currently only Url & AbsoluteUrl exist).Describe alternatives you've considered
As far as I can tell the only alternative is using reflection to access the private members of
WireMockAssertions
.The text was updated successfully, but these errors were encountered: