-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
Add version of StringAssertions.Contain that allows specifying the number of times a substring should occur. #818
Comments
How about the This asserts that actual.Should().Match("*Fred*Fred*", "Fred is important"); I emphasize distinct because I feel it could be difficult to get such an API right. Would Just for the record a very unreadable way to assert that actual.Should().MatchRegex("^(?:(?!Fred).)*Fred(?:(?!Fred).)*Fred(?:(?!Fred).)*$", "Fred is important"); |
Thanks for the explanation, in this case the
Given that my request can by implemented using the |
It could work, provided that |
Hi, I would like to do this.
API proposed by @basbossink is more readable, but I think it will be a breaking change. |
Of course I can implement other similar methods like e.g. |
I personally prefer the proposal of @basbossink |
Ok, I agree. Look at the following API If we have a string that does not contain "Fred" then assert should not throw. Then it will throw an exception. How it should looks like? |
We could do something similar to FakeItEasy's assertion syntax: actual.Should().Contain("Fred", 4, Times.Exactly);
actual.Should().Contain("Fred", 4, Times.OrLess);
actual.Should().Contain("Fred", 4, Times.OrMore); I'm still interested in the discussion about whether "aaa" contains "aa" once or twice. |
Good point. |
I have one more proposal
There will be a several predefined options (once, twice, etc.) and the Times method to specify a number. It also solves the problem with breaking changes. |
I still prefer the more fluent proposal of @basbossink |
@dennisdoomen I understand.
|
In case of
Personally, I think that FluentAssertions should be careful when introducing breaking changes. I have almost completed the feature, but I would like to adjust the API to final version before sending PR. |
Hi guys, I created the pull request #962 |
Currently StringAssertions has no easy way of asserting that a substring should occur a particular number of times within a string. Imagine the syntax could be something like
or
or
The text was updated successfully, but these errors were encountered: