Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if an object inherits from another class using FluentAssertions?

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?

like image 625
Rogerio Schmitt Avatar asked Mar 03 '23 01:03

Rogerio Schmitt


1 Answers

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

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

Some resources:

  • documentation
  • source code
  • tests
like image 58
Jonas Nyrup Avatar answered Apr 15 '23 20:04

Jonas Nyrup