Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 Src/FluentAssertions/Equivalency/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Field(FieldInfo fieldInfo, INode parent)
this.fieldInfo = fieldInfo;
DeclaringType = fieldInfo.DeclaringType;
ReflectedType = fieldInfo.ReflectedType;
Subject = new Pathway(parent.Subject.PathAndName, fieldInfo.Name, pathAndName => $"field {parent.GetSubjectId().Combine(pathAndName)}");
Subject = new Pathway(parent.Subject.PathAndName, fieldInfo.Name, pathAndName => $"field {parent.GetSubjectId().Combine(pathAndName)}");
Expectation = new Pathway(parent.Expectation.PathAndName, fieldInfo.Name, pathAndName => $"field {pathAndName}");
GetSubjectId = parent.GetSubjectId;
Type = fieldInfo.FieldType;
Expand All @@ -33,7 +33,7 @@ public object GetValue(object obj)
return fieldInfo.GetValue(obj);
}

public Type DeclaringType { get; set; }
public Type DeclaringType { get; }

public CSharpAccessModifier GetterAccessibility => fieldInfo.GetCSharpAccessModifier();

Expand Down
2 changes: 1 addition & 1 deletion 2 Src/FluentAssertions/Equivalency/INode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface INode
/// <summary>
/// Gets the path from the root of the subject upto and including the current node.
/// </summary>
Pathway Subject { get; internal set; }
Pathway Subject { get; }

/// <summary>
/// Gets the path from the root of the expectation upto and including the current node.
Expand Down
8 changes: 4 additions & 4 deletions 8 Src/FluentAssertions/Equivalency/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public GetSubjectId GetSubjectId
protected init => field = value;
}

public Type Type { get; protected set; }
public Type Type { get; init; }

public Type ParentType { get; protected set; }
public Type ParentType { get; init; }

public Pathway Subject
{
get;
set
protected set
{
field = value;
Expectation ??= value;
Expand All @@ -46,7 +46,7 @@ public bool IsRoot

private bool IsFirstIndex => MatchFirstIndex.IsMatch(Subject.PathAndName);

public bool RootIsCollection { get; protected set; }
public bool RootIsCollection { get; init; }

public void AdjustForRemappedSubject(IMember subjectMember)
{
Expand Down
14 changes: 3 additions & 11 deletions 14 Src/FluentAssertions/Equivalency/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Property(Type reflectedType, PropertyInfo propertyInfo, INode parent)
ReflectedType = reflectedType;
this.propertyInfo = propertyInfo;
DeclaringType = propertyInfo.DeclaringType;
Subject = new Pathway(parent.Subject.PathAndName, propertyInfo.Name, pathAndName => $"property {parent.GetSubjectId().Combine(pathAndName)}");
Subject = new Pathway(parent.Subject.PathAndName, propertyInfo.Name, pathAndName => $"property {parent.GetSubjectId().Combine(pathAndName)}");
Expectation = new Pathway(parent.Expectation.PathAndName, propertyInfo.Name, pathAndName => $"property {pathAndName}");
Type = propertyInfo.PropertyType;
ParentType = propertyInfo.DeclaringType;
Expand All @@ -45,14 +45,6 @@ public object GetValue(object obj)

public CSharpAccessModifier SetterAccessibility => propertyInfo.GetSetMethod(nonPublic: true).GetCSharpAccessModifier();

public bool IsBrowsable
{
get
{
isBrowsable ??=
propertyInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };

return isBrowsable.Value;
}
}
public bool IsBrowsable =>
isBrowsable ??= propertyInfo.GetCustomAttribute<EditorBrowsableAttribute>() is not { State: EditorBrowsableState.Never };
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ public EnumerableEquivalencyValidator(AssertionChain assertionChain, IValidateCh
this.assertionChain = assertionChain;
this.parent = parent;
this.context = context;
Recursive = false;
}

public bool Recursive { get; init; }
public required bool Recursive { get; init; }

public OrderingRuleCollection OrderingRules { get; init; }
public required OrderingRuleCollection OrderingRules { get; init; }

public void Execute<T>(object[] subject, T[] expectation)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using FluentAssertions.Common;
using FluentAssertions.Execution;

namespace FluentAssertions.Equivalency.Steps;
Expand All @@ -10,7 +10,8 @@ public class EqualityComparerEquivalencyStep<T> : IEquivalencyStep

public EqualityComparerEquivalencyStep(IEqualityComparer<T> comparer)
{
this.comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
Guard.ThrowIfArgumentIsNull(comparer);
this.comparer = comparer;
}

public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
namespace FluentAssertions.Equivalency.Tracing;

internal sealed class InternalTraceWriter : StringBuilderTraceWriter
{
}
internal sealed class InternalTraceWriter : StringBuilderTraceWriter;
4 changes: 2 additions & 2 deletions 4 Src/FluentAssertions/Execution/AssertionScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public AssertionScope(Func<string> name)
/// <exception cref="ArgumentNullException"><paramref name="assertionStrategy"/> is <see langword="null"/>.</exception>
private AssertionScope(Func<string> name, IAssertionStrategy assertionStrategy)
{
Guard.ThrowIfArgumentIsNull(assertionStrategy);
parent = CurrentScope.Value;
CurrentScope.Value = this;

this.assertionStrategy = assertionStrategy
?? throw new ArgumentNullException(nameof(assertionStrategy));
this.assertionStrategy = assertionStrategy;

if (parent is not null)
{
Expand Down
3 changes: 1 addition & 2 deletions 3 Src/FluentAssertions/Primitives/DateTimeOffsetAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ public AndConstraint<TAssertions> NotBeExactly(DateTimeOffset? unexpected,
[StringSyntax("CompositeFormat")] string because = "", params object[] becauseArgs)
{
assertionChain
.ForCondition(!((Subject == null && unexpected == null) ||
(Subject != null && unexpected != null && Subject.Value.EqualsExact(unexpected.Value))))
.ForCondition(!(Subject.HasValue == unexpected.HasValue && Subject.GetValueOrDefault().EqualsExact(unexpected.GetValueOrDefault())))
.BecauseOf(because, becauseArgs)
.FailWith("Did not expect {context:the date and time} to be exactly {0}{reason}, but it was.", unexpected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public AndConstraint<TAssertions> BeCloseTo(TimeSpan nearbyTime, TimeSpan precis
TimeSpan maximumValue = nearbyTime + precision;

assertionChain
.ForCondition(Subject >= minimumValue && Subject.Value <= maximumValue)
.ForCondition(Subject >= minimumValue && Subject <= maximumValue)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:time} to be within {0} from {1}{reason}, but found {2}.",
precision,
Expand Down
2 changes: 1 addition & 1 deletion 2 Src/FluentAssertions/Primitives/StringEqualityStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public StringEqualityStrategy(IEqualityComparer<string> comparer, string predica
/// Gets a value indicating whether the differences between string properties should
/// include the full values of the subject and expectation instead of just the fragment that differs.
/// </summary>
public bool IncludeFullDetails { get; set; } = true;
public bool IncludeFullDetails { get; init; } = true;

public void AssertForEquality(AssertionChain assertionChain, string subject, string expected)
{
Expand Down
6 changes: 4 additions & 2 deletions 6 Src/FluentAssertions/Specialized/DelegateAssertionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ private protected DelegateAssertionsBase(TDelegate @delegate, IExtractExceptions
IClock clock)
: base(@delegate, assertionChain)
{
Guard.ThrowIfArgumentIsNull(extractor);
Guard.ThrowIfArgumentIsNull(clock);
this.assertionChain = assertionChain;
Extractor = extractor ?? throw new ArgumentNullException(nameof(extractor));
Clock = clock ?? throw new ArgumentNullException(nameof(clock));
Extractor = extractor;
Clock = clock;
}

private protected IClock Clock { get; }
Expand Down
3 changes: 2 additions & 1 deletion 3 Src/FluentAssertions/Specialized/ExecutionTimeAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class ExecutionTimeAssertions
/// <param name="executionTime">The execution on which time must be asserted.</param>
public ExecutionTimeAssertions(ExecutionTime executionTime, AssertionChain assertionChain)
{
execution = executionTime ?? throw new ArgumentNullException(nameof(executionTime));
Guard.ThrowIfArgumentIsNull(executionTime);
execution = executionTime;
this.assertionChain = assertionChain;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class TaskCompletionSourceAssertionsBase
{
protected TaskCompletionSourceAssertionsBase(IClock clock)
{
Clock = clock ?? throw new ArgumentNullException(nameof(clock));
Guard.ThrowIfArgumentIsNull(clock);
Clock = clock;
}

private protected IClock Clock { get; }
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.