DynamicShould.HaveProperty assumes cast to IDictionary<string, object>
marco-luzzara opened this issue · comments
In DynamicShould.HaveProperty, if the object we pass is of type IDynamicMetaObjectProvider
, but does not implement IDictionary<string, object>
, an InvalidCastException
is thrown.
This does not happen with expando objects, but Shouldly cannot assert the property of a class that directly implements System.Dynamic.DynamicObject
, for example.
shouldly/src/Shouldly/ShouldStaticClasses/DynamicShould.cs
Lines 17 to 19 in 070f721
Thanks for the report! My guess is we should be using the IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression)
method instead. Possibly for correctness even in the case that the type does implement IDictionary<string, object>
.
Pull requests welcome.
I would like to work on it but I cannot compile the solution. I am using docker (mcr.microsoft.com/dotnet/sdk:6.0
) because I don't have the last version installed but when I run:
dotnet build src/Shouldly.Tests/Shouldly.Tests.csproj
I get
/app/src/Shouldly.Tests/Shouldly.Tests.csproj : error NU1505: Duplicate 'PackageDownload' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageDownload' items are: Microsoft.NETCore.App.Ref [3.1.0], Microsoft.NETCore.App.Ref [3.1.0].
The same goes for dotnet build
on the solution. It only works when I build the Shouldly.csproj
.