Reuse existing assertions inside custom assertion? #1857
-
I followed the docs to write custom assertions. But I found an edge case that is not covered in the docs or past issues/discussions. Let's say I have a container type Container.Foo.Value.Should().BeSameAs(otherValue); I want to write a custom assertion like so: Container.Should().HaveValueSameAs(otherValue); I wrote a custom assertion that does that. But I had to duplicate all the Is it possible to "reuse" built-in assertions when writing my custom assertion? public AndConstraint<ContainerAssertions> HaveValueSameAs(object other, string because = "", params object[] becauseArgs)
{
Execute.Assertion
.BecauseOf(because, becauseArgs)
//...reuse Be() / BeSameAs() / BeEquivalentTo() / etc...
.FailWith("some message");
return new AndConstraint<ContainerAssertions>(this);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Why not use the FA assertions directly in your |
Beta Was this translation helpful? Give feedback.
Why not use the FA assertions directly in your
HaveValueSameAs
method?