Skip to content

Commit

Permalink
Merge pull request #1936 from jnyrup/fileScopedNamespaces
Browse files Browse the repository at this point in the history
Use file scoped namespaces
  • Loading branch information
jnyrup committed May 21, 2022
2 parents 4f2fc22 + 0c39ac9 commit 17c52d0
Show file tree
Hide file tree
Showing 589 changed files with 103,388 additions and 103,983 deletions.
6 changes: 3 additions & 3 deletions FluentAssertions.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28922.388
# Visual Studio Version 17
VisualStudioVersion = 17.3.32505.426
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E5A0B454-22D4-4694-99FF-D6A8B7DE7DA3}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -44,7 +44,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.Specs", "T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UWP.Specs", "Tests\UWP.Specs\UWP.Specs.csproj", "{08087654-2C32-4818-95E4-45362373441D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentAssertions.Equivalency.Specs", "Tests\FluentAssertions.Equivalency.Specs\FluentAssertions.Equivalency.Specs.csproj", "{A946043D-D3F8-46A4-B485-A88412C417FE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.Equivalency.Specs", "Tests\FluentAssertions.Equivalency.Specs\FluentAssertions.Equivalency.Specs.csproj", "{A946043D-D3F8-46A4-B485-A88412C417FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
47 changes: 23 additions & 24 deletions Src/FluentAssertions/AggregateExceptionExtractor.cs
Expand Up @@ -4,38 +4,37 @@
using FluentAssertions.Common;
using FluentAssertions.Specialized;

namespace FluentAssertions
namespace FluentAssertions;

public class AggregateExceptionExtractor : IExtractExceptions
{
public class AggregateExceptionExtractor : IExtractExceptions
public IEnumerable<T> OfType<T>(Exception actualException)
where T : Exception
{
public IEnumerable<T> OfType<T>(Exception actualException)
where T : Exception
if (typeof(T).IsSameOrInherits(typeof(AggregateException)))
{
if (typeof(T).IsSameOrInherits(typeof(AggregateException)))
{
return (actualException is T exception) ? new[] { exception } : Enumerable.Empty<T>();
}

return GetExtractedExceptions<T>(actualException);
return (actualException is T exception) ? new[] { exception } : Enumerable.Empty<T>();
}

private static List<T> GetExtractedExceptions<T>(Exception actualException)
where T : Exception
{
var exceptions = new List<T>();
return GetExtractedExceptions<T>(actualException);
}

if (actualException is AggregateException aggregateException)
{
AggregateException flattenedExceptions = aggregateException.Flatten();
private static List<T> GetExtractedExceptions<T>(Exception actualException)
where T : Exception
{
var exceptions = new List<T>();

exceptions.AddRange(flattenedExceptions.InnerExceptions.OfType<T>());
}
else if (actualException is T genericException)
{
exceptions.Add(genericException);
}
if (actualException is AggregateException aggregateException)
{
AggregateException flattenedExceptions = aggregateException.Flatten();

return exceptions;
exceptions.AddRange(flattenedExceptions.InnerExceptions.OfType<T>());
}
else if (actualException is T genericException)
{
exceptions.Add(genericException);
}

return exceptions;
}
}
23 changes: 11 additions & 12 deletions Src/FluentAssertions/AndConstraint.cs
@@ -1,18 +1,17 @@
using System.Diagnostics;

namespace FluentAssertions
namespace FluentAssertions;

[DebuggerNonUserCode]
public class AndConstraint<T>
{
[DebuggerNonUserCode]
public class AndConstraint<T>
{
public T And { get; }
public T And { get; }

/// <summary>
/// Initializes a new instance of the <see cref="AndConstraint{T}"/> class.
/// </summary>
public AndConstraint(T parentConstraint)
{
And = parentConstraint;
}
/// <summary>
/// Initializes a new instance of the <see cref="AndConstraint{T}"/> class.
/// </summary>
public AndConstraint(T parentConstraint)
{
And = parentConstraint;
}
}
97 changes: 48 additions & 49 deletions Src/FluentAssertions/AndWhichConstraint.cs
Expand Up @@ -5,64 +5,63 @@
using FluentAssertions.Common;
using FluentAssertions.Formatting;

namespace FluentAssertions
namespace FluentAssertions;

/// <summary>
/// Constraint which can be returned from an assertion which matches a condition and which will allow
/// further matches to be performed on the matched condition as well as the parent constraint.
/// </summary>
/// <typeparam name="TParentConstraint">The type of the original constraint that was matched</typeparam>
/// <typeparam name="TMatchedElement">The type of the matched object which the parent constraint matched</typeparam>
public class AndWhichConstraint<TParentConstraint, TMatchedElement> : AndConstraint<TParentConstraint>
{
/// <summary>
/// Constraint which can be returned from an assertion which matches a condition and which will allow
/// further matches to be performed on the matched condition as well as the parent constraint.
/// </summary>
/// <typeparam name="TParentConstraint">The type of the original constraint that was matched</typeparam>
/// <typeparam name="TMatchedElement">The type of the matched object which the parent constraint matched</typeparam>
public class AndWhichConstraint<TParentConstraint, TMatchedElement> : AndConstraint<TParentConstraint>
private readonly Lazy<TMatchedElement> matchedConstraint;

public AndWhichConstraint(TParentConstraint parentConstraint, TMatchedElement matchedConstraint)
: base(parentConstraint)
{
private readonly Lazy<TMatchedElement> matchedConstraint;
this.matchedConstraint =
new Lazy<TMatchedElement>(() => matchedConstraint);
}

public AndWhichConstraint(TParentConstraint parentConstraint, TMatchedElement matchedConstraint)
: base(parentConstraint)
{
this.matchedConstraint =
new Lazy<TMatchedElement>(() => matchedConstraint);
}
public AndWhichConstraint(TParentConstraint parentConstraint, IEnumerable<TMatchedElement> matchedConstraint)
: base(parentConstraint)
{
this.matchedConstraint =
new Lazy<TMatchedElement>(
() => SingleOrDefault(matchedConstraint));
}

public AndWhichConstraint(TParentConstraint parentConstraint, IEnumerable<TMatchedElement> matchedConstraint)
: base(parentConstraint)
{
this.matchedConstraint =
new Lazy<TMatchedElement>(
() => SingleOrDefault(matchedConstraint));
}
private static TMatchedElement SingleOrDefault(
IEnumerable<TMatchedElement> matchedConstraint)
{
TMatchedElement[] matchedElements = matchedConstraint.ToArray();

private static TMatchedElement SingleOrDefault(
IEnumerable<TMatchedElement> matchedConstraint)
if (matchedElements.Length > 1)
{
TMatchedElement[] matchedElements = matchedConstraint.ToArray();

if (matchedElements.Length > 1)
{
string foundObjects = string.Join(Environment.NewLine,
matchedElements.Select(
ele => "\t" + Formatter.ToString(ele)));

string message = "More than one object found. FluentAssertions cannot determine which object is meant."
+ $" Found objects:{Environment.NewLine}{foundObjects}";
string foundObjects = string.Join(Environment.NewLine,
matchedElements.Select(
ele => "\t" + Formatter.ToString(ele)));

Services.ThrowException(message);
}
string message = "More than one object found. FluentAssertions cannot determine which object is meant."
+ $" Found objects:{Environment.NewLine}{foundObjects}";

return matchedElements.Single();
Services.ThrowException(message);
}

/// <summary>
/// Returns the single result of a prior assertion that is used to select a nested or collection item.
/// </summary>
public TMatchedElement Which => matchedConstraint.Value;

/// <summary>
/// Returns the single result of a prior assertion that is used to select a nested or collection item.
/// </summary>
/// <remarks>
/// Just a convenience property that returns the same value as <see cref="Which"/>.
/// </remarks>
public TMatchedElement Subject => Which;
return matchedElements.Single();
}

/// <summary>
/// Returns the single result of a prior assertion that is used to select a nested or collection item.
/// </summary>
public TMatchedElement Which => matchedConstraint.Value;

/// <summary>
/// Returns the single result of a prior assertion that is used to select a nested or collection item.
/// </summary>
/// <remarks>
/// Just a convenience property that returns the same value as <see cref="Which"/>.
/// </remarks>
public TMatchedElement Subject => Which;
}

0 comments on commit 17c52d0

Please sign in to comment.