Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FluentAssertions Should().BeOfType() or derived type?

I have the following situation:

class A
{
}

class B : A
{
}

I want to assert that variables of typeof(B) are assignable to typeof(A) variables. How to do that with fluent assertions?

like image 369
D.R. Avatar asked Feb 21 '26 19:02

D.R.


1 Answers

I think you can use BeAssignableTo<T> for this:

var b = new B();
        
b.Should().BeAssignableTo<A>();

This is almost your own sentence you have written. :)

like image 195
Michaël Hompus Avatar answered Feb 25 '26 03:02

Michaël Hompus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!