Replies: 9 comments 14 replies
-
You could also create a builder and have properties like public static class FluentOccurrenceBuilder
{
public static OccurrenceConstraintBuilder Times(this int times)
{
return new OccurrenceConstraintBuilder(times);
}
}
public sealed class OccurrenceConstraintBuilder
{
private readonly int _times;
public OccurrenceConstraintBuilder(int times)
{
_times = times;
}
public OccurrenceConstraint Exactly => FluentAssertions.Exactly.Times(_times); // Namespace qualification needed to avoid conflict
public OccurrenceConstraint OrLess => AtMost.Times(_times);
public OccurrenceConstraint OrMore => AtLeast.Times(_times);
} This would allow you to write this instead: 4.Times().Exactly;
4.Times().OrLess;
4.Times().OrMore; |
Beta Was this translation helpful? Give feedback.
-
I think it's a nice idea and looks a bit better than |
Beta Was this translation helpful? Give feedback.
-
If somebody tells me that something should contain something else 4 times, I would have no doubts that this person meant "4 times exactly" |
Beta Was this translation helpful? Give feedback.
-
Is this change still relevant? I think I can give it a shot if @siewers does not mind 🙃 |
Beta Was this translation helpful? Give feedback.
-
Yes, I'm totally open to that. I guess it's a feature that isn't very discoverable. How do we make it clear to our users that we have a better way to express occurrences? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
How about "forcing" users to use the new approach by marking the "old" one with obsolete? |
Beta Was this translation helpful? Give feedback.
-
I don't think there's anything wrong in continue using All current usage of Do you think |
Beta Was this translation helpful? Give feedback.
-
Done in #2047 |
Beta Was this translation helpful? Give feedback.
-
I was wondering if it would make sense to include an extension method for
Exactly.Times
like this:I think it reads a bit better than the existing
Exactly.Times(4)
, but perhaps this has already been considered?I understand there might be some confusion around
AtLeast
,AtMost
etc., but that might be fixed like:There seems to be some redundancy in with
AtLeast
/MoreThan
andAtMost
/LessThan
, but they might be useful in scenarios I've never had.I know creating such extensions is pretty straightforward:
Beta Was this translation helpful? Give feedback.
All reactions