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
ContainItemsAssignableTo vs AllBeAssignableTo #1618
Comments
You're on to something. I was expecting |
Very interesting and a freaky occurrence :) We are now discussing whether to implement a new assertion |
I think we should fix the behavior for the next 6.0 beta. |
I think it might need some additional assertion options. If you want to assert the collection only contains a single instance of type T, how would that be done? |
If subject.Should().ContainItemsAssignableTo<T>()
.Which.Should().ContainSingle(); |
Ah, yes, that is an option, although I find it a little less fluent :)
and not:
;) |
Scratch my comment about collection.Should().ContainSingle().Which.Should().BeOfType<T>(); |
These are different assertions. subject.Should().ContainItemsAssignableTo<T>()
.Which.Should().ContainSingle();
collection.Should().ContainSingle()
.Which.Should().BeOfType<T>();
|
@eNeRGy164 Yes, you are right of course :)
versus
, I know which one I would prefer. However, I am not sure how to express this fluently, without breaking existing convention. subject.Should().Contain().AtMost(1).OfType<T>();
subject.Should().Contain().AtLeast(1).OfType<T>(); |
Description
Is there any difference between
ContainItemsAssignableTo
andAllBeAssignableTo
?Spending five minutes looking at them, they seem to test the same scenario.
(With the exception, that
AllBeAssignableTo
has special handling forIEnumerable<Type>
)In contrast to other
Contain
methods,ContainItemsAssignableTo
expects all elements to satisfy and not just a subset.Complete minimal example reproducing the issue
The text was updated successfully, but these errors were encountered: