Skip to content

Restrict custom assertion to a specific (reference) type while keeping existing object assertions #1999

Answered by andreivanea
andreivanea asked this question in Q&A
Discussion options

You must be logged in to vote

This might have been the wrong approach here. I only "explored" alternative solutions because following the official documentation on creating custom assertions did not yield the expected result. What I had written initially was:

public class MyClassAssertions : ReferenceTypeAssertions<MyClass, MyClassAssertions>
{
    public MyClassAssertions(MyClass instance)  : base(instance) { }

    public AndConstraint<MyClassAssertions> BeTheBestClassEver(string because = "", params object[] becauseArgs)
    {
        // ...
    }
}

This meant that all assertions defined in ObjectAssertions were basically removed from my class. To get keep existing assertions and get my new, custom assertion for my…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dennisdoomen
Comment options

Answer selected by jnyrup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants