Skip to content

Commit

Permalink
Squashed 'src/Microsoft.DotNet.XUnitAssert/src/' changes from 28ab73f…
Browse files Browse the repository at this point in the history
…b0..cb1e33ba6

cb1e33ba6 Updated doc comment for AllException.ForFailures
5986aa7bf Remove all ValueTask support
e48a30666 Performance optimization: unused code in comparison hot path
094b4d4cf Formatting
b3e3c931a Performance improvements in CollectionTrackerExtensions.AsTracker
6a94a86a0 Performance improvements in AssertEqualityComparer (conditional IEquatable<Y> and IComparable<Y> with type caching)
f1843557b Replace dictionary with ring buffer in CollectionTracker.Enumerator
3bb330972 Don't depend on the Assert class inside AssertEqualityComparer
10f8fe362 Ensure all throws of NotImplementedException contain messages
37e83a858 Ensure all GetHashCode functions are implemented (xunit/xunit#2804)
4828bf193 xunit/xunit#2803: Add support for KeyValuePair<,> in AssertEqualityComparer to enable collections in values
a92673b02 xunit/xunit#2800: Record exceptions from Assert.(Not)Equal comparer
ba2525400 Replace concatenation and interpolation with String.Format

git-subtree-dir: src/Microsoft.DotNet.XUnitAssert/src
git-subtree-split: cb1e33ba612d4829e0848a44bde1026f5f9e3576
  • Loading branch information
ViktorHofer committed Nov 14, 2023
1 parent 2b57770 commit d809d22
Show file tree
Hide file tree
Showing 52 changed files with 1,186 additions and 801 deletions.
25 changes: 10 additions & 15 deletions CollectionAsserts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Xunit.Sdk;

#if XUNIT_VALUETASK
using System.Threading.Tasks;
#endif
using Xunit.Sdk;

namespace Xunit
{
Expand Down Expand Up @@ -80,7 +77,6 @@ partial class Assert
throw AllException.ForFailures(idx, errors);
}

#if XUNIT_VALUETASK
/// <summary>
/// Verifies that all items in the collection pass when executed against
/// action.
Expand All @@ -89,9 +85,9 @@ partial class Assert
/// <param name="collection">The collection</param>
/// <param name="action">The action to test each item against</param>
/// <exception cref="AllException">Thrown when the collection contains at least one non-matching element</exception>
public static async ValueTask AllAsync<T>(
public static async Task AllAsync<T>(
IEnumerable<T> collection,
Func<T, ValueTask> action)
Func<T, Task> action)
{
GuardArgumentNotNull(nameof(collection), collection);
GuardArgumentNotNull(nameof(action), action);
Expand All @@ -107,9 +103,9 @@ partial class Assert
/// <param name="collection">The collection</param>
/// <param name="action">The action to test each item against</param>
/// <exception cref="AllException">Thrown when the collection contains at least one non-matching element</exception>
public static async ValueTask AllAsync<T>(
public static async Task AllAsync<T>(
IEnumerable<T> collection,
Func<T, int, ValueTask> action)
Func<T, int, Task> action)
{
GuardArgumentNotNull(nameof(collection), collection);
GuardArgumentNotNull(nameof(action), action);
Expand All @@ -134,7 +130,6 @@ partial class Assert
if (errors.Count > 0)
throw AllException.ForFailures(idx, errors.ToArray());
}
#endif

/// <summary>
/// Verifies that a collection contains exactly a given number of elements, which meet
Expand Down Expand Up @@ -177,7 +172,6 @@ partial class Assert
}
}

#if XUNIT_VALUETASK
/// <summary>
/// Verifies that a collection contains exactly a given number of elements, which meet
/// the criteria provided by the element inspectors.
Expand All @@ -186,9 +180,9 @@ partial class Assert
/// <param name="collection">The collection to be inspected</param>
/// <param name="elementInspectors">The element inspectors, which inspect each element in turn. The
/// total number of element inspectors must exactly match the number of elements in the collection.</param>
public static async ValueTask CollectionAsync<T>(
public static async Task CollectionAsync<T>(
IEnumerable<T> collection,
params Func<T, ValueTask>[] elementInspectors)
params Func<T, Task>[] elementInspectors)
{
GuardArgumentNotNull(nameof(collection), collection);
GuardArgumentNotNull(nameof(elementInspectors), elementInspectors);
Expand Down Expand Up @@ -218,7 +212,6 @@ partial class Assert
throw CollectionException.ForMismatchedItemCount(elementInspectors.Length, tracker.IterationCount, tracker.FormatStart());
}
}
#endif

/// <summary>
/// Verifies that a collection contains a given object.
Expand Down Expand Up @@ -430,9 +423,11 @@ public static void Empty(IEnumerable collection)
GuardArgumentNotNull(nameof(collection), collection);

using (var tracker = collection.AsTracker())
using (var enumerator = tracker.GetEnumerator())
{
var enumerator = tracker.GetEnumerator();
if (enumerator.MoveNext())
throw EmptyException.ForNonEmptyCollection(tracker.FormatStart());
}
}

/// <summary>
Expand Down

0 comments on commit d809d22

Please sign in to comment.