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 [StringSyntax("CompositeFormat")] to all because parameters #2635

Merged
merged 7 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions Src/FluentAssertions/AsyncAssertionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using FluentAssertions.Specialized;

Expand Down Expand Up @@ -26,7 +27,7 @@ public static class AsyncAssertionsExtensions
/// </remarks>
public static async Task<AndWhichConstraint<GenericAsyncFunctionAssertions<T>, T>> WithResult<T>(
this Task<AndWhichConstraint<GenericAsyncFunctionAssertions<T>, T>> task,
T expected, string because = "", params object[] becauseArgs)
T expected, [StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
var andWhichConstraint = await task;
var subject = andWhichConstraint.Subject;
Expand All @@ -49,7 +50,7 @@ public static class AsyncAssertionsExtensions
/// </param>
public static async Task<AndWhichConstraint<TaskCompletionSourceAssertions<T>, T>> WithResult<T>(
this Task<AndWhichConstraint<TaskCompletionSourceAssertions<T>, T>> task,
T expected, string because = "", params object[] becauseArgs)
T expected, [StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
var andWhichConstraint = await task;
var subject = andWhichConstraint.Subject;
Expand Down
300 changes: 166 additions & 134 deletions Src/FluentAssertions/Collections/GenericCollectionAssertions.cs

Large diffs are not rendered by default.

41 changes: 20 additions & 21 deletions Src/FluentAssertions/Collections/GenericDictionaryAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="expected"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> Equal<T>(T expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
where T : IEnumerable<KeyValuePair<TKey, TValue>>
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected), "Cannot compare dictionary with <null>.");
Expand Down Expand Up @@ -117,7 +117,7 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="unexpected"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> NotEqual<T>(T unexpected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
where T : IEnumerable<KeyValuePair<TKey, TValue>>
{
Guard.ThrowIfArgumentIsNull(unexpected, nameof(unexpected), "Cannot compare dictionary with <null>.");
Expand Down Expand Up @@ -180,7 +180,7 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public AndConstraint<TAssertions> BeEquivalentTo<TExpectation>(TExpectation expectation,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return BeEquivalentTo(expectation, options => options, because, becauseArgs);
}
Expand Down Expand Up @@ -212,8 +212,8 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> BeEquivalentTo<TExpectation>(TExpectation expectation,
Func<EquivalencyOptions<TExpectation>, EquivalencyOptions<TExpectation>> config, string because = "",
params object[] becauseArgs)
Func<EquivalencyOptions<TExpectation>, EquivalencyOptions<TExpectation>> config,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(config);

Expand Down Expand Up @@ -253,7 +253,7 @@ public GenericDictionaryAssertions(TCollection keyValuePairs)
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public WhoseValueConstraint<TCollection, TKey, TValue, TAssertions> ContainKey(TKey expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
AndConstraint<TAssertions> andConstraint = ContainKeys([expected], because, becauseArgs);

Expand Down Expand Up @@ -287,7 +287,7 @@ public AndConstraint<TAssertions> ContainKeys(params TKey[] expected)
/// <exception cref="ArgumentNullException"><paramref name="expected"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="expected"/> is empty.</exception>
public AndConstraint<TAssertions> ContainKeys(IEnumerable<TKey> expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot verify key containment against a <null> collection of keys");
Expand Down Expand Up @@ -343,7 +343,7 @@ public AndConstraint<TAssertions> ContainKeys(params TKey[] expected)
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndConstraint<TAssertions> NotContainKey(TKey unexpected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
bool success = Execute.Assertion
.ForCondition(Subject is not null)
Expand Down Expand Up @@ -386,7 +386,7 @@ public AndConstraint<TAssertions> NotContainKeys(params TKey[] unexpected)
/// <exception cref="ArgumentNullException"><paramref name="unexpected"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="unexpected"/> is empty.</exception>
public AndConstraint<TAssertions> NotContainKeys(IEnumerable<TKey> unexpected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(unexpected, nameof(unexpected),
"Cannot verify key containment against a <null> collection of keys");
Expand Down Expand Up @@ -444,7 +444,7 @@ public AndConstraint<TAssertions> NotContainKeys(params TKey[] unexpected)
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndWhichConstraint<TAssertions, TValue> ContainValue(TValue expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
AndWhichConstraint<TAssertions, IEnumerable<TValue>> innerConstraint =
ContainValuesAndWhich([expected], because, becauseArgs);
Expand Down Expand Up @@ -479,7 +479,7 @@ public AndConstraint<TAssertions> ContainValues(params TValue[] expected)
/// <exception cref="ArgumentNullException"><paramref name="expected"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="expected"/> is empty.</exception>
public AndConstraint<TAssertions> ContainValues(IEnumerable<TValue> expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected),
"Cannot verify value containment against a <null> collection of values");
Expand All @@ -488,8 +488,7 @@ public AndConstraint<TAssertions> ContainValues(params TValue[] expected)
}

private AndWhichConstraint<TAssertions, IEnumerable<TValue>> ContainValuesAndWhich(IEnumerable<TValue> expected,
string because = "",
params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
ICollection<TValue> expectedValues = expected.ConvertOrCastToCollection();

Expand Down Expand Up @@ -560,7 +559,7 @@ public AndConstraint<TAssertions> ContainValues(params TValue[] expected)
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndConstraint<TAssertions> NotContainValue(TValue unexpected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
bool success = Execute.Assertion
.ForCondition(Subject is not null)
Expand Down Expand Up @@ -603,7 +602,7 @@ public AndConstraint<TAssertions> NotContainValues(params TValue[] unexpected)
/// <exception cref="ArgumentNullException"><paramref name="unexpected"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="unexpected"/> is empty.</exception>
public AndConstraint<TAssertions> NotContainValues(IEnumerable<TValue> unexpected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(unexpected, nameof(unexpected),
"Cannot verify value containment against a <null> collection of values");
Expand Down Expand Up @@ -676,7 +675,7 @@ public AndConstraint<TAssertions> Contain(params KeyValuePair<TKey, TValue>[] ex
/// <exception cref="ArgumentException"><paramref name="expected"/> is empty.</exception>
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs refactoring")]
public new AndConstraint<TAssertions> Contain(IEnumerable<KeyValuePair<TKey, TValue>> expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(expected, nameof(expected), "Cannot compare dictionary with <null>.");

Expand Down Expand Up @@ -760,7 +759,7 @@ public AndConstraint<TAssertions> Contain(params KeyValuePair<TKey, TValue>[] ex
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public new AndConstraint<TAssertions> Contain(KeyValuePair<TKey, TValue> expected,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return Contain(expected.Key, expected.Value, because, becauseArgs);
}
Expand All @@ -781,7 +780,7 @@ public AndConstraint<TAssertions> Contain(params KeyValuePair<TKey, TValue>[] ex
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndConstraint<TAssertions> Contain(TKey key, TValue value,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
bool success = Execute.Assertion
.ForCondition(Subject is not null)
Expand Down Expand Up @@ -845,7 +844,7 @@ public AndConstraint<TAssertions> NotContain(params KeyValuePair<TKey, TValue>[]
/// <exception cref="ArgumentNullException"><paramref name="items"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="items"/> is empty.</exception>
public new AndConstraint<TAssertions> NotContain(IEnumerable<KeyValuePair<TKey, TValue>> items,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(items, nameof(items), "Cannot compare dictionary with <null>.");

Expand Down Expand Up @@ -913,7 +912,7 @@ public AndConstraint<TAssertions> NotContain(params KeyValuePair<TKey, TValue>[]
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public new AndConstraint<TAssertions> NotContain(KeyValuePair<TKey, TValue> item,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return NotContain(item.Key, item.Value, because, becauseArgs);
}
Expand All @@ -934,7 +933,7 @@ public AndConstraint<TAssertions> NotContain(params KeyValuePair<TKey, TValue>[]
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndConstraint<TAssertions> NotContain(TKey key, TValue value,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
bool success = Execute.Assertion
.ForCondition(Subject is not null)
Expand Down
22 changes: 11 additions & 11 deletions Src/FluentAssertions/Collections/StringCollectionAssertions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using FluentAssertions.Common;
using FluentAssertions.Equivalency;
Expand Down Expand Up @@ -92,8 +93,8 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public AndConstraint<TAssertions> BeEquivalentTo(IEnumerable<string> expectation, string because = "",
params object[] becauseArgs)
public AndConstraint<TAssertions> BeEquivalentTo(IEnumerable<string> expectation,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return BeEquivalentTo(expectation, config => config, because, becauseArgs);
}
Expand Down Expand Up @@ -121,8 +122,8 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> BeEquivalentTo(IEnumerable<string> expectation,
Func<EquivalencyOptions<string>, EquivalencyOptions<string>> config, string because = "",
params object[] becauseArgs)
Func<EquivalencyOptions<string>, EquivalencyOptions<string>> config,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(config);

Expand Down Expand Up @@ -160,7 +161,7 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
/// Zero or more objects to format using the placeholders in <paramref name="because"/>.
/// </param>
public AndConstraint<TAssertions> AllBe(string expectation,
string because = "", params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return AllBe(expectation, options => options, because, becauseArgs);
}
Expand All @@ -185,8 +186,7 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
/// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception>
public AndConstraint<TAssertions> AllBe(string expectation,
Func<EquivalencyOptions<string>, EquivalencyOptions<string>> config,
string because = "",
params object[] becauseArgs)
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(config);

Expand Down Expand Up @@ -239,8 +239,8 @@ public AndConstraint<TAssertions> BeEquivalentTo(params string[] expectation)
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="wildcardPattern"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="wildcardPattern"/> is empty.</exception>
public AndWhichConstraint<TAssertions, string> ContainMatch(string wildcardPattern, string because = "",
params object[] becauseArgs)
public AndWhichConstraint<TAssertions, string> ContainMatch(string wildcardPattern,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(wildcardPattern, nameof(wildcardPattern),
"Cannot match strings in collection against <null>. Provide a wildcard pattern or use the Contain method.");
Expand Down Expand Up @@ -324,8 +324,8 @@ private IEnumerable<string> AllThatMatch(string wildcardPattern)
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="wildcardPattern"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="wildcardPattern"/> is empty.</exception>
public AndConstraint<TAssertions> NotContainMatch(string wildcardPattern, string because = "",
params object[] becauseArgs)
public AndConstraint<TAssertions> NotContainMatch(string wildcardPattern,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(wildcardPattern, nameof(wildcardPattern),
"Cannot match strings in collection against <null>. Provide a wildcard pattern or use the NotContain method.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using FluentAssertions.Common;
Expand Down Expand Up @@ -40,7 +41,8 @@ public SubsequentOrderingGenericCollectionAssertions(TCollection actualValue, IO
/// Empty and single element collections are considered to be ordered both in ascending and descending order at the same time.
/// </remarks>
public AndConstraint<SubsequentOrderingAssertions<T>> ThenBeInAscendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, string because = "", params object[] becauseArgs)
Expression<Func<T, TSelector>> propertyExpression,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return ThenBeInAscendingOrder(propertyExpression, GetComparer<TSelector>(), because, becauseArgs);
}
Expand All @@ -67,8 +69,8 @@ public SubsequentOrderingGenericCollectionAssertions(TCollection actualValue, IO
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <see langword="null"/>.</exception>
public AndConstraint<SubsequentOrderingAssertions<T>> ThenBeInAscendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "",
params object[] becauseArgs)
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer),
"Cannot assert collection ordering without specifying a comparer.");
Expand All @@ -94,7 +96,8 @@ public SubsequentOrderingGenericCollectionAssertions(TCollection actualValue, IO
/// Empty and single element collections are considered to be ordered both in ascending and descending order at the same time.
/// </remarks>
public AndConstraint<SubsequentOrderingAssertions<T>> ThenBeInDescendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, string because = "", params object[] becauseArgs)
Expression<Func<T, TSelector>> propertyExpression,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
return ThenBeInDescendingOrder(propertyExpression, GetComparer<TSelector>(), because, becauseArgs);
}
Expand All @@ -121,8 +124,8 @@ public SubsequentOrderingGenericCollectionAssertions(TCollection actualValue, IO
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <see langword="null"/>.</exception>
public AndConstraint<SubsequentOrderingAssertions<T>> ThenBeInDescendingOrder<TSelector>(
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer, string because = "",
params object[] becauseArgs)
Expression<Func<T, TSelector>> propertyExpression, IComparer<TSelector> comparer,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
Guard.ThrowIfArgumentIsNull(comparer, nameof(comparer),
"Cannot assert collection ordering without specifying a comparer.");
Expand Down