I'm working on a .NET Core 5 application. In some parts of the system, I'm using a cast to dynamic to handle generic type resolution. Something like this:
public void Foo(ISomething something){
Bar((dynamic)something);
}
private void Bar<T>(T somethingElse) where T : ISomething
{ .... }
Works pretty well if I run the whole application. Now, for some mysterious reason, the same code refuses to work during Unit Tests. I get an exception as soon as it tries to call Bar<T>(), complaining that it's receiving an object instead of an ISomething.
I'm using XUnit.
Any idea?
UPDATE 10/01/2021
I've pushed the code to GitHub, the branch is coverage.
This is the failing test. The issue happens on this line in the InMemoryPublisher class, when casting the message to dynamic.