Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing exceptions to xml summaries #2023

Merged
merged 6 commits into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Src/FluentAssertions/AssertionOptions.cs
Expand Up @@ -36,6 +36,7 @@ public static EquivalencyAssertionOptions<T> CloneDefaults<T>()
/// <param name="defaultsConfigurer">
/// An action that is used to configure the defaults.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="defaultsConfigurer"/> is <see langword="null"/>.</exception>
public static void AssertEquivalencyUsing(
Func<EquivalencyAssertionOptions, EquivalencyAssertionOptions> defaultsConfigurer)
{
Expand Down
40 changes: 16 additions & 24 deletions Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Expand Up @@ -176,6 +176,7 @@ public AndConstraint<TAssertions> AllBeAssignableTo(Type expectedType, string be
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> AllBeEquivalentTo<TExpectation>(TExpectation expectation,
Func<EquivalencyAssertionOptions<TExpectation>, EquivalencyAssertionOptions<TExpectation>> config,
string because = "",
Expand Down Expand Up @@ -347,6 +348,7 @@ public AndConstraint<TAssertions> BeEmpty(string because = "", params object[] b
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> BeEquivalentTo<TExpectation>(IEnumerable<TExpectation> expectation,
Func<EquivalencyAssertionOptions<TExpectation>, EquivalencyAssertionOptions<TExpectation>> config, string because = "",
params object[] becauseArgs)
Expand Down Expand Up @@ -417,6 +419,7 @@ public AndConstraint<TAssertions> BeEmpty(string because = "", params object[] b
public AndConstraint<SubsequentOrderingAssertions<T>> BeInAscendingOrder(
IComparer<T> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");

Choose a reason for hiding this comment

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

The custom message doesn't seem to be adding much value here from my perspective (as a consumer). I'd suggest removing in cases like this to reduce noise in the codebase.

return BeInOrder(comparer, SortOrder.Ascending, because, becauseArgs);
}

Expand Down Expand Up @@ -444,6 +447,7 @@ public AndConstraint<TAssertions> BeEmpty(string because = "", params object[] b
public AndConstraint<SubsequentOrderingAssertions<T>> BeInAscendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return BeOrderedBy(propertyExpression, comparer, SortOrder.Ascending, because, becauseArgs);
}

Expand Down Expand Up @@ -532,6 +536,7 @@ public AndConstraint<SubsequentOrderingAssertions<T>> BeInAscendingOrder(Func<T,
public AndConstraint<SubsequentOrderingAssertions<T>> BeInDescendingOrder(
IComparer<T> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return BeInOrder(comparer, SortOrder.Descending, because, becauseArgs);
}

Expand Down Expand Up @@ -559,6 +564,7 @@ public AndConstraint<SubsequentOrderingAssertions<T>> BeInAscendingOrder(Func<T,
public AndConstraint<SubsequentOrderingAssertions<T>> BeInDescendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return BeOrderedBy(propertyExpression, comparer, SortOrder.Descending, because, becauseArgs);
}

Expand Down Expand Up @@ -750,10 +756,7 @@ public AndConstraint<TAssertions> Contain(IEnumerable<T> expected, string becaus
Guard.ThrowIfArgumentIsNull(expected, nameof(expected), "Cannot verify containment against a <null> collection");

ICollection<T> expectedObjects = expected.ConvertOrCastToCollection();
if (!expectedObjects.Any())
{
throw new ArgumentException("Cannot verify containment against an empty collection", nameof(expected));
}
Guard.ThrowIfArgumentIsEmpty(expectedObjects, nameof(expected), "Cannot verify containment against an empty collection");
jnyrup marked this conversation as resolved.
Show resolved Hide resolved

bool success = Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -1185,6 +1188,7 @@ public AndConstraint<TAssertions> EndWith(IEnumerable<T> expectation, string bec
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="expectation"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> EndWith<TExpectation>(
IEnumerable<TExpectation> expectation, Func<T, TExpectation, bool> equalityComparison, string because = "", params object[] becauseArgs)
{
Expand Down Expand Up @@ -1690,6 +1694,7 @@ public AndConstraint<TAssertions> NotBeEmpty(string because = "", params object[
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="unexpected"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> NotBeEquivalentTo<TExpectation>(IEnumerable<TExpectation> unexpected, string because = "",
params object[] becauseArgs)
{
Expand Down Expand Up @@ -1807,6 +1812,7 @@ public AndConstraint<TAssertions> NotBeEmpty(string because = "", params object[
public AndConstraint<TAssertions> NotBeInAscendingOrder(
IComparer<T> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return NotBeInOrder(comparer, SortOrder.Ascending, because, becauseArgs);
}

Expand Down Expand Up @@ -1834,6 +1840,7 @@ public AndConstraint<TAssertions> NotBeEmpty(string because = "", params object[
public AndConstraint<TAssertions> NotBeInAscendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return NotBeOrderedBy(propertyExpression, comparer, SortOrder.Ascending, because, becauseArgs);
}

Expand Down Expand Up @@ -1921,6 +1928,7 @@ public AndConstraint<TAssertions> NotBeInAscendingOrder(Func<T, T, int> comparis
public AndConstraint<TAssertions> NotBeInDescendingOrder(
IComparer<T> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return NotBeInOrder(comparer, SortOrder.Descending, because, becauseArgs);
}

Expand Down Expand Up @@ -1948,6 +1956,7 @@ public AndConstraint<TAssertions> NotBeInAscendingOrder(Func<T, T, int> comparis
public AndConstraint<TAssertions> NotBeInDescendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");
return NotBeOrderedBy(propertyExpression, comparer, SortOrder.Descending, because, becauseArgs);
}

Expand Down Expand Up @@ -2141,10 +2150,7 @@ public AndConstraint<TAssertions> NotContain(IEnumerable<T> unexpected, string b
Guard.ThrowIfArgumentIsNull(unexpected, nameof(unexpected), "Cannot verify non-containment against a <null> collection");

ICollection<T> unexpectedObjects = unexpected.ConvertOrCastToCollection();
if (!unexpectedObjects.Any())
{
throw new ArgumentException("Cannot verify non-containment against an empty collection", nameof(unexpected));
}
Guard.ThrowIfArgumentIsEmpty(unexpectedObjects, nameof(unexpected), "Cannot verify non-containment against an empty collection");

bool success = Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -2908,10 +2914,7 @@ public AndConstraint<TAssertions> SatisfyRespectively(IEnumerable<Action<T>> exp
Guard.ThrowIfArgumentIsNull(expected, nameof(expected), "Cannot verify against a <null> collection of inspectors");

ICollection<Action<T>> elementInspectors = expected.ConvertOrCastToCollection();
if (!elementInspectors.Any())
{
throw new ArgumentException("Cannot verify against an empty collection of inspectors", nameof(expected));
}
Guard.ThrowIfArgumentIsEmpty(elementInspectors, nameof(expected), "Cannot verify against an empty collection of inspectors");

bool success = Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -2997,10 +3000,7 @@ public AndConstraint<TAssertions> Satisfy(IEnumerable<Expression<Func<T, bool>>>
Guard.ThrowIfArgumentIsNull(predicates, nameof(predicates), "Cannot verify against a <null> collection of predicates");

IList<Expression<Func<T, bool>>> predicatesList = predicates.ConvertOrCastToList();
if (predicatesList.Count == 0)
{
throw new ArgumentException("Cannot verify against an empty collection of predicates", nameof(predicates));
}
Guard.ThrowIfArgumentIsEmpty(predicatesList, nameof(predicates), "Cannot verify against an empty collection of predicates");

bool success = Execute.Assertion
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -3122,8 +3122,6 @@ public AndConstraint<TAssertions> StartWith(T element, string because = "", para
string because,
object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");

if (IsValidProperty(propertyExpression, because, becauseArgs))
{
ICollection<T> unordered = Subject.ConvertOrCastToCollection();
Expand Down Expand Up @@ -3343,8 +3341,6 @@ private bool IsValidProperty<TSelector>(Expression<Func<T, TSelector>> propertyE
string because,
object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");

if (IsValidProperty(propertyExpression, because, becauseArgs))
{
ICollection<T> unordered = Subject.ConvertOrCastToCollection();
Expand Down Expand Up @@ -3372,8 +3368,6 @@ private bool IsValidProperty<TSelector>(Expression<Func<T, TSelector>> propertyE
private AndConstraint<SubsequentOrderingAssertions<T>> BeInOrder(
IComparer<T> comparer, SortOrder expectedOrder, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");

string sortOrder = (expectedOrder == SortOrder.Ascending) ? "ascending" : "descending";

bool success = Execute.Assertion
Expand Down Expand Up @@ -3419,8 +3413,6 @@ private bool IsValidProperty<TSelector>(Expression<Func<T, TSelector>> propertyE
/// </summary>
private AndConstraint<TAssertions> NotBeInOrder(IComparer<T> comparer, SortOrder order, string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer), "Cannot assert collection ordering without specifying a comparer.");

string sortOrder = (order == SortOrder.Ascending) ? "ascending" : "descending";

bool success = Execute.Assertion
Expand Down