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

Cleanups #1998

Merged
merged 8 commits into from Sep 14, 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: 0 additions & 1 deletion Src/FluentAssertions/AssertionExtensions.cs
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Reflection;
Expand Down
52 changes: 25 additions & 27 deletions Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Expand Up @@ -843,38 +843,36 @@ public AndConstraint<TAssertions> Contain(IEnumerable<T> expected, string becaus
{
EquivalencyAssertionOptions<TExpectation> options = config(AssertionOptions.CloneDefaults<TExpectation>());

using (var scope = new AssertionScope())
using var scope = new AssertionScope();
scope.AddReportable("configuration", () => options.ToString());

foreach (T actualItem in Subject)
{
scope.AddReportable("configuration", () => options.ToString());
var context = new EquivalencyValidationContext(Node.From<TExpectation>(() => AssertionScope.Current.CallerIdentity), options)
{
Reason = new Reason(because, becauseArgs),
TraceWriter = options.TraceWriter
};

foreach (T actualItem in Subject)
var comparands = new Comparands
{
var context = new EquivalencyValidationContext(Node.From<TExpectation>(() => AssertionScope.Current.CallerIdentity), options)
{
Reason = new Reason(because, becauseArgs),
TraceWriter = options.TraceWriter
};
Subject = actualItem,
Expectation = expectation,
CompileTimeType = typeof(TExpectation),
};

var comparands = new Comparands
{
Subject = actualItem,
Expectation = expectation,
CompileTimeType = typeof(TExpectation),
};
new EquivalencyValidator().AssertEquality(comparands, context);

new EquivalencyValidator().AssertEquality(comparands, context);

string[] failures = scope.Discard();
if (!failures.Any())
{
return new AndWhichConstraint<TAssertions, T>((TAssertions)this, actualItem);
}
string[] failures = scope.Discard();
if (!failures.Any())
{
return new AndWhichConstraint<TAssertions, T>((TAssertions)this, actualItem);
}

Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:collection} {0} to contain equivalent of {1}{reason}.", Subject, expectation);
}

Execute.Assertion
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:collection} {0} to contain equivalent of {1}{reason}.", Subject, expectation);
}

return new AndWhichConstraint<TAssertions, T>((TAssertions)this, default(T));
Expand Down Expand Up @@ -921,7 +919,7 @@ public AndConstraint<TAssertions> ContainInOrder(params T[] expected)
IList<T> actualItems = Subject.ConvertOrCastToList();

int subjectIndex = 0;

for (int index = 0; index < expectedItems.Count; index++)
{
T expectedItem = expectedItems[index];
Expand Down Expand Up @@ -2341,7 +2339,7 @@ public AndConstraint<TAssertions> NotContainInOrder(params T[] unexpected)
{
IList<T> actualItems = Subject.ConvertOrCastToList();
int subjectIndex = 0;

foreach (var unexpectedItem in unexpectedItems)
{
subjectIndex = IndexOf(actualItems, unexpectedItem, startIndex: subjectIndex);
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Common/ExpressionExtensions.cs
Expand Up @@ -97,7 +97,7 @@ internal static class ExpressionExtensions
// If any members were accessed in the expression, the first one found is the last member.
Type declaringType = declaringTypes.FirstOrDefault() ?? typeof(TDeclaringType);

string[] reversedSegments = segments.AsEnumerable().Reverse().ToArray();
IEnumerable<string> reversedSegments = segments.AsEnumerable().Reverse();
string segmentPath = string.Join(".", reversedSegments);

return new MemberPath(typeof(TDeclaringType), declaringType, segmentPath.Replace(".[", "[", StringComparison.Ordinal));
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Common/TypeExtensions.cs
Expand Up @@ -442,8 +442,8 @@ public static ConstructorInfo GetConstructor(this Type type, IEnumerable<Type> p
&& m.IsSpecialName
&& m.ReturnType == targetType
&& predicate(m.Name)
&& m.GetParameters().Length == 1
&& m.GetParameters()[0].ParameterType == sourceType);
&& m.GetParameters() is { Length: 1 } parameters
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

&& parameters[0].ParameterType == sourceType);
}

public static bool IsAssignableToOpenGeneric(this Type type, Type definition)
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Data/DataEquivalencyAssertionOptions.cs
Expand Up @@ -91,9 +91,9 @@ public IDataEquivalencyAssertionOptions<T> IgnoringUnmatchedColumns()
return this;
}

public IDataEquivalencyAssertionOptions<T> UsingRowMatchMode(RowMatchMode newRowMatchMode)
public IDataEquivalencyAssertionOptions<T> UsingRowMatchMode(RowMatchMode rowMatchMode)
{
rowMatchMode = newRowMatchMode;
this.rowMatchMode = rowMatchMode;
return this;
}

Expand Down
Expand Up @@ -96,7 +96,7 @@ private static Type[] GatherPrimaryKeyColumnTypes(DataTable table, string compar
{
Type[] primaryKeyTypes = null;

if ((table.PrimaryKey is null) || (table.PrimaryKey.Length == 0))
if (table.PrimaryKey is null or { Length: 0 })
{
AssertionScope.Current
.FailWith("Table {0} containing {1} {context:DataRowCollection} does not have a primary key. RowMatchMode.PrimaryKey cannot be applied.", table.TableName, comparisonTerm);
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/EventRaisingExtensions.cs
Expand Up @@ -71,7 +71,7 @@ public static IEventRecording WithArgs<T>(this IEventRecording eventRecording, E

foreach (OccurredEvent @event in eventRecording)
{
var typedParameters = @event.Parameters.OfType<T>().ToArray();
IEnumerable<T> typedParameters = @event.Parameters.OfType<T>();

if (typedParameters.Any(parameter => compiledPredicate(parameter)))
{
Expand Down
7 changes: 2 additions & 5 deletions Src/FluentAssertions/Formatting/Formatter.cs
Expand Up @@ -163,10 +163,7 @@ private static void Format(object value, FormattedObjectGraph output, Formatting
/// </summary>
public static void RemoveFormatter(IValueFormatter formatter)
{
if (CustomFormatters.Contains(formatter))
{
CustomFormatters.Remove(formatter);
}
CustomFormatters.Remove(formatter);
}

/// <summary>
Expand Down Expand Up @@ -219,7 +216,7 @@ public void Pop()

public override string ToString()
{
return string.Join(".", pathStack.Reverse().ToArray());
return string.Join(".", pathStack.Reverse());
}
}
}
4 changes: 2 additions & 2 deletions Src/FluentAssertions/Primitives/StringAssertions.cs
Expand Up @@ -1036,7 +1036,7 @@ public AndConstraint<TAssertions> ContainAll(IEnumerable<string> values, string
{
ThrowIfValuesNullOrEmpty(values);

var missing = values.Where(v => !Contains(Subject, v, StringComparison.Ordinal)).ToArray();
IEnumerable<string> missing = values.Where(v => !Contains(Subject, v, StringComparison.Ordinal));
Execute.Assertion
.ForCondition(values.All(v => Contains(Subject, v, StringComparison.Ordinal)))
.BecauseOf(because, becauseArgs)
Expand Down Expand Up @@ -1076,7 +1076,7 @@ public AndConstraint<TAssertions> ContainAny(IEnumerable<string> values, string
Execute.Assertion
.ForCondition(values.Any(v => Contains(Subject, v, StringComparison.Ordinal)))
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:string} {0} to contain at least one of the strings: {1}{reason}.", Subject, values.ToArray());
.FailWith("Expected {context:string} {0} to contain at least one of the strings: {1}{reason}.", Subject, values);

return new AndConstraint<TAssertions>((TAssertions)this);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Specialized/ExceptionAssertions.cs
Expand Up @@ -87,7 +87,7 @@ public ExceptionAssertions(IEnumerable<TException> exceptions)
.ForCondition(Subject.Any())
.FailWith("Expected exception with message {0}{reason}, but no exception was thrown.", expectedWildcardPattern);

OuterMessageAssertion.Execute(Subject.Select(exc => exc.Message).ToArray(), expectedWildcardPattern, because,
OuterMessageAssertion.Execute(Subject.Select(exc => exc.Message), expectedWildcardPattern, because,
becauseArgs);

return this;
Expand Down