4

I would like to know how can I check if an object inherits from another class using Fluent Assertions?

I know I can do that with xUnit using IsAssignableFrom, like so:

[Fact]
public void CreateBossEnemy()
{
    //arrange
    EnemyFactory sut = new EnemyFactory();

    //action
    var enemy = sut.Create("Zombie King", true);

    //assert
    Assert.IsAssignableFrom<Enemy>(enemy);
}

What would be the equivalent of IsAssignableFrom for Fluent Assertions?

Praxiteles
  • 5,802
  • 9
  • 47
  • 78
Rogerio Schmitt
  • 1,055
  • 1
  • 15
  • 35

1 Answers1

7

To check whether enemy is assignable to the the type Enemy you can use:

enemy.Should().BeAssignableTo<Enemy>();

Some resources:

Jonas Nyrup
  • 2,376
  • 18
  • 25