New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should().Be() Throws exception using dynamic types #1493
Comments
I guess I've been spoiled by the Rubberduck repository which pops up related posts when you enter the title for an issue. My other thoughts would be that as dynamic appears to be problematical there should be some kind of discussion of the issues on the help pages. If I were authoring the code, I'd be trying to forwarn people of the issues with a specific message rather than relying on an exception message. |
I agree that a note in the documentation would be nice, we're open for PR's ;) We're not relying on any exceptions (as I see it), it's how C# handles extension methods on dynamic types. See this minimal example that not use Fluent Assertions, but behaves similar to your example. [TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
dynamic obj = 1;
obj.Should();
}
}
public static class Extensions
{
public static object Should(this object o)
{
throw new System.Exception("this is never hit");
}
} |
The best you can probably do is to cast your dynamic object to dynamic obj = 1;
((int)obj).Should(); |
Description
Should().Be()
throws an exception when the types being tested are dynamic.Gives the exception
If I replace the dynamic with int all is fine.
The text was updated successfully, but these errors were encountered: