Table of Contents

Class CollectionTracker

Namespace
Xunit.Sdk
Assembly
xunit.v3.assert.dll

Base class for generic CollectionTracker<T>, which also includes some public static functionality.

public abstract class CollectionTracker : IDisposable
Inheritance
CollectionTracker
Implements
Derived
Inherited Members
Extension Methods

Constructors

CollectionTracker(IEnumerable)

Initializes a new instance of the CollectionTracker class.

protected CollectionTracker(IEnumerable innerEnumerable)

Parameters

innerEnumerable IEnumerable

Exceptions

ArgumentNullException

Properties

InnerEnumerable

Gets the inner enumerable that this collection track is wrapping. This is mostly provided for simplifying other APIs which require both the tracker and the collection (for example, AreCollectionsEqual(CollectionTracker?, CollectionTracker?, IEqualityComparer, bool)).

protected IEnumerable InnerEnumerable { get; set; }

Property Value

IEnumerable

Methods

AreCollectionsEqual(CollectionTracker?, CollectionTracker?, IEqualityComparer, bool)

Determine if two enumerable collections are equal. It contains logic that varies depending on the collection type (supporting arrays, dictionaries, sets, and generic enumerables).

public static AssertEqualityResult AreCollectionsEqual(CollectionTracker? x, CollectionTracker? y, IEqualityComparer itemComparer, bool isDefaultItemComparer)

Parameters

x CollectionTracker

First value to compare

y CollectionTracker

Second value to comare

itemComparer IEqualityComparer

The comparer used for individual item comparisons

isDefaultItemComparer bool

Pass true if the itemComparer is the default item comparer from Xunit.Sdk.AssertEqualityComparer<T>; pass false, otherwise.

Returns

AssertEqualityResult

Returns true if the collections are equal; false, otherwise.

Dispose()

public void Dispose()

Dispose(bool)

Override to provide an implementation of Dispose().

protected abstract void Dispose(bool disposing)

Parameters

disposing bool

FormatIndexedMismatch(int, int, int?, out int?, int)

Formats the collection when you have a mismatched index. The formatted result will be the section of the collection from startIndex to endIndex. These indices are usually obtained by calling GetMismatchExtents(int?, out int, out int).

public abstract string FormatIndexedMismatch(int startIndex, int endIndex, int? mismatchedIndex, out int? pointerIndent, int depth = 1)

Parameters

startIndex int

The start index of the collection to print

endIndex int

The end index of the collection to print

mismatchedIndex int?

The mismatched item index

pointerIndent int?

How many spaces into the output value the pointed-to item begins at

depth int

The optional printing depth (1 indicates a top-level value)

Returns

string

The formatted collection

FormatIndexedMismatch(int?, out int?, int)

Formats the collection when you have a mismatched index. The formatted result will be the section of the collection surrounded by the mismatched item.

public abstract string FormatIndexedMismatch(int? mismatchedIndex, out int? pointerIndent, int depth = 1)

Parameters

mismatchedIndex int?

The index of the mismatched item

pointerIndent int?

How many spaces into the output value the pointed-to item begins at

depth int

The optional printing depth (1 indicates a top-level value)

Returns

string

The formatted collection

FormatStart(int)

Formats the beginning part of the collection.

public abstract string FormatStart(int depth = 1)

Parameters

depth int

The optional printing depth (1 indicates a top-level value)

Returns

string

The formatted collection

GetMismatchExtents(int?, out int, out int)

Gets the extents to print when you find a mismatched index, in the form of a startIndex and endIndex. If the mismatched index is null, the extents will start at index 0.

public abstract void GetMismatchExtents(int? mismatchedIndex, out int startIndex, out int endIndex)

Parameters

mismatchedIndex int?

The mismatched item index

startIndex int

The start index that should be used for printing

endIndex int

The end index that should be used for printing

GetSafeEnumerator()

Gets a safe version of IEnumerator that prevents double enumeration and does all the necessary tracking required for collection formatting. Should should be the same value returned by GetEnumerator(), except non-generic.

protected abstract IEnumerator GetSafeEnumerator()

Returns

IEnumerator

TypeAt(int?)

Gets the full name of the type of the element at the given index, if known. Since this uses the item cache produced by enumeration, it may return null when we haven't enumerated enough to see the given element, or if we enumerated so much that the item has left the cache, or if the item at the given index is null. It will also return null when the index is null.

public abstract string? TypeAt(int? index)

Parameters

index int?

The item index

Returns

string

Wrap(IEnumerable)

Wraps an untyped enumerable in an object-based CollectionTracker<T>.

public static CollectionTracker<object> Wrap(IEnumerable enumerable)

Parameters

enumerable IEnumerable

The untyped enumerable to wrap

Returns

CollectionTracker<object>