Skip to content

Open up OccurenceConstraint for usage in custom assertion extensions #1281

@brooknovak

Description

@brooknovak

The OccurrenceConstraint.Assert() method is internal - so people who write their own extensions cannot use this very handy constraint (and therefore create their own - creating inconsistency of how to deal with assertion occurences).

Understand why this is internal - so the actual usage hides this when defining an assertion for the test.
However why not add a new overload in the Execute assertion fluent API to accept a OccurrenceConstraint. i.e. as an alternative to ForCondition(...):

Execute.Assertion
    .BecauseOf(because, becauseArgs)
    .ForConstraint(constraint)
    .FailWith("Expected {0}{reason} but found {1}",
              constraint, Subject.Count());

Note there would be a formatter for the occurrence constraint to render the expected amount / "mode" (since these are also internal - and should continue to be)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions