Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ CollectionAssert.AreNotEquivalent(IEnumerable expected, IEnumerable actual);
CollectionAssert.AreNotEquivalent(
IEnumerable expected, IEnumerable actual, string message, params object[] args);

CollectionAssert.Contains(IEnumerable expected, object actual);
CollectionAssert.Contains(IEnumerable collection, object actual);
CollectionAssert.Contains(
IEnumerable expected, object actual, string message, params object[] args);
IEnumerable collection, object actual, string message, params object[] args);

CollectionAssert.DoesNotContain(IEnumerable expected, object actual);
CollectionAssert.DoesNotContain(IEnumerable collection, object actual);
CollectionAssert.DoesNotContain(
IEnumerable expected, object actual, string message, params object[] args);
IEnumerable collection, object actual, string message, params object[] args);

CollectionAssert.IsSubsetOf(IEnumerable subset, IEnumerable superset);
CollectionAssert.IsSubsetOf(
Expand All @@ -79,6 +79,29 @@ CollectionAssert.IsOrdered(IEnumerable collection,
IComparer comparer, string message, params object[] args);
```

## Contains and DoesNotContain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting a PR up for this one @SeanKilleen

I'll have to reacquaint myself with the issue before reviewing. Hopefully soon. I had thought we supported subset-style contains through this API too, but perhaps that's just at constraint level


The parameters of `Contains` and `DoesNotContain` do not follow the usual *expected, actual* pattern of the other
classic assertions. The first argument is the collection to search, and the second, named `actual`, is the single item
being looked for. Despite its name, that item is what the assertion *expects* to find, so the failure message reports it
on the **Expected** line and the collection on the **But was** line:

```csharp
CollectionAssert.Contains(new[] { 1, 2 }, 3);

// Expected: some item equal to 3
// But was: < 1, 2 >
```

Passing a collection as the second argument does not check that one collection contains another. It checks whether the
collection contains that collection as a single element. The parameter names are kept for compatibility, since renaming
them would break callers that use named arguments. The constraint-based equivalents read more naturally:

```csharp
Assert.That(new[] { 1, 2 }, Does.Contain(3));
Assert.That(new[] { 1, 2 }, Has.Member(3));
```

## Examples

### Comparing collections
Expand Down
Loading