Assertions and Test Cases for Enumerables and Collections
Learn when and how to assert lists and objects contained in lists.
We'll cover the following
- Introduction
- Catalog of collection assertions
- The AllItems constraint
- The AnyOf constraint
- The CollectionContains constraint
- The CollectionEquivalent constraint
- The CollectionOrdered constraint
- The CollectionSubset constraint
- The CollectionSuperset constraint
- The DictionaryContainsKey constraint
- The DictionaryContainsValue constraint
- The EmptyCollection constraint
- The ExactCount constraint
- The NoItem constraint
- The SomeItems constraint
- The UniqueItems constraint
- Conclusion
Introduction
Grouping objects into collections and performing actions on this collection are one of the most fundamental programming tasks. Given its importance, it’s helpful to recall the ICollection
class and some of its capabilities.
The ICollection
class is a base interface for all other classes in the System.Collections
namespace. The generic equivalent is the System.Collections.Generic.ICollection<T>
interface. The ICollection
interface itself extends the IEnumerable
interface. This basic schematic is shown in the figure below:
Get hands-on with 1400+ tech skills courses.