ContainItemsAssignableTo vs AllBeAssignableTo
See original GitHub issueDescription
Is there any difference between ContainItemsAssignableTo
and AllBeAssignableTo
?
Spending five minutes looking at them, they seem to test the same scenario.
(With the exception, that AllBeAssignableTo
has special handling for IEnumerable<Type>
)
In contrast to other Contain
methods, ContainItemsAssignableTo
expects all elements to satisfy and not just a subset.
Complete minimal example reproducing the issue
class Base { }
class Derived : Base { }
public void MyTestMethod()
{
new[] { new Derived(), new Base() }.Should().AllBeAssignableTo<Derived>(); // fails as expected
new[] { new Derived(), new Base() }.Should().ContainItemsAssignableTo<Derived>(); // <-- I would have expected this to pass
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Collections
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit...
Read more >Releases - Fluent Assertions
Fixed hanging of CompleteWithinAsync when used with WithResult and ... ContainItemsAssignableTo now expects at least one item assignable to T - #1765 ...
Read more >(T81-17)用FluentAssertions的ContainItemsAssignableTo
... 的 ContainItemsAssignableTo 、 AllBeAssignableTo 、AllBeOfType測試 ... LeetCode 34 Find First and Last Position of Element in Sorted Array.
Read more >FluentAssertions Collection集合类型断言
And.ContainItemsAssignableTo<int>(); // 元素可以被赋值成int类型 collection. ... AllBeAssignableTo<Student>(); // 是不是子元素都是Student类型 students1.
Read more >fluentassertions中文文档_weixin_30451709的博客
And.ContainItemsAssignableTo<int>();. collection. ... ContainItemsAssignableTo<int>();. collection. ... AllBeAssignableTo<DerivedType>();.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
These are different assertions.
@eNeRGy164 Yes, you are right of course 😃 I still think that scenario reads a bit messy. I would never talk like that, and reading it as
versus
, I know which one I would prefer.
However, I am not sure how to express this fluently, without breaking existing convention.