CollectionAssert.That Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the singleton instance of the CollectionAssert functionality.
public:
static property Microsoft::VisualStudio::TestTools::UnitTesting::CollectionAssert ^ That { Microsoft::VisualStudio::TestTools::UnitTesting::CollectionAssert ^ get(); };
public static Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert That { get; }
[System.Runtime.CompilerServices.Nullable(1)]
public static Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert That { get; }
static member That : Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert
[<System.Runtime.CompilerServices.Nullable(1)>]
static member That : Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert
Public Shared ReadOnly Property That As CollectionAssert
Property Value
- Attributes
Examples
The following example defines a custom AreEqualUnordered assertion as an extension method
on CollectionAssert and invokes it through CollectionAssert.That:
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public static class CustomCollectionAssertExtensions
{
public static void AreEqualUnordered<T>(this CollectionAssert collectionAssert, IEnumerable<T> expected, IEnumerable<T> actual)
{
if (!expected.OrderBy(x => x).SequenceEqual(actual.OrderBy(x => x)))
{
throw new AssertFailedException("CollectionAssert.That.AreEqualUnordered failed. Collections do not contain the same elements.");
}
}
}
[TestClass]
public class SetTests
{
[TestMethod]
public void Items_MatchRegardlessOfOrder()
{
CollectionAssert.That.AreEqualUnordered(new[] { 1, 2, 3 }, new[] { 3, 1, 2 });
}
}
Remarks
Users can use this to plug-in custom assertions through C# extension methods. For instance, the signature of a custom assertion provider could be public static void AreEqualUnordered(this CollectionAssert customAssert, ICollection expected, ICollection actual) and the call-site would be CollectionAssert.That.AreEqualUnordered(list1, list2);.
For new custom assertions, prefer extending That instead, because CollectionAssert is likely to be deprecated in a future release. For more information, see Extension hooks on StringAssert and CollectionAssert.