How to combine collection and property assertions using fluent-assertions?

不羁岁月 提交于 2019-12-04 02:52:28
Dennis Doomen

I have added support for your scenario in the main branch of Fluent Assertions. It will be part of the next version, but it might take us a month or two to accumalate enough changes to warrant another release. If you want, you can grab the source build and run the release.bat to build an intermediate version.

If I'm interpreting your question correctly, I think you should try version 1.7.0 of Fluent Assertions. In that version we changed the behavior that when IncludingNestedObjects is used, it will also do that on collections of objects. An excerpt of the documentation.

"Additionally, you can take structural comparison a level further by including the IncludingNestedObjects property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested properties of the subject match the nested properties of the expected object. However, if you do specify SharedProperties, then it will only compare the equally named properties between the nested objects. For instance:

dto.ShouldHave().SharedProperties().IncludingNestedObjects.EqualTo(customer);"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!