What's the idiomatic way to verify collection size in xUnit?

隐身守侯 提交于 2019-12-03 04:08:11

Xunit offers quick fixes for most of its warnings, so you should be able to see what it thinks is "right".

In your case, it wants you to use Assert.Single since you are expecting exactly one item. If you were asserting an arbitrary number, like 412, then it would not give you a warning about using Count. It will only suggest using Single if you are expecting one item, or Empty if you are expecting no items.

I found this give me the same error:

Assert.Equal(2, vm.Errors.Count());

And casting it stopped the error from appearing.

Assert.Equal(2, (int)vm.Errors.Count());

I had same issue when I used Count property as below in xUnit.

After, I use Count() function on collection, it fixed my issue.

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