Skip to content

Commit

Permalink
SAVEPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Dec 1, 2024
1 parent ef0cfbc commit 412e378
Show file tree
Hide file tree
Showing 32 changed files with 41 additions and 126 deletions.
8 changes: 3 additions & 5 deletions Src/FluentAssertions/Equivalency/Comparands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ public Type RuntimeType
}

/// <summary>
/// Returns either the run-time or compile-time type of the expectation based on the options provided by the caller.
/// Returns the run-time of the expectation.
/// </summary>
/// <remarks>
/// If the expectation is a nullable type, it should return the type of the wrapped object.
/// </remarks>
public Type GetExpectedType(IEquivalencyOptions options)
public Type GetExpectedType()
{
Type type = options.UseRuntimeTyping ? RuntimeType : CompileTimeType;

return type.NullableOrActualType();
return RuntimeType.NullableOrActualType();
}

public override string ToString()
Expand Down
2 changes: 0 additions & 2 deletions Src/FluentAssertions/Equivalency/EquivalencyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,5 @@ public EquivalencyOptions()

IncludingFields();
IncludingProperties();

RespectingDeclaredTypes();
}
}
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Equivalency/EquivalencyStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class EquivalencyStep<T> : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
if (!typeof(T).IsAssignableFrom(comparands.GetExpectedType(context.Options)))
if (!typeof(T).IsAssignableFrom(comparands.GetExpectedType()))
{
return EquivalencyResult.ContinueWithNext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public IEnumerable<IEquivalencyStep> UserEquivalencySteps

public EnumEquivalencyHandling EnumEquivalencyHandling => inner.EnumEquivalencyHandling;

public bool UseRuntimeTyping => inner.UseRuntimeTyping;

public MemberVisibility IncludedProperties => inner.IncludedProperties;

public MemberVisibility IncludedFields => inner.IncludedFields;
Expand Down
3 changes: 0 additions & 3 deletions Src/FluentAssertions/Equivalency/Execution/ObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public ObjectInfo(Comparands comparands, INode currentNode)
Type = currentNode.Type;
ParentType = currentNode.ParentType;
Path = currentNode.PathAndName;
CompileTimeType = comparands.CompileTimeType;
RuntimeType = comparands.RuntimeType;
}

Expand All @@ -19,7 +18,5 @@ public ObjectInfo(Comparands comparands, INode currentNode)

public string Path { get; set; }

public Type CompileTimeType { get; }

public Type RuntimeType { get; }
}
5 changes: 0 additions & 5 deletions Src/FluentAssertions/Equivalency/IEquivalencyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public interface IEquivalencyOptions
/// </summary>
IEnumerable<IEquivalencyStep> UserEquivalencySteps { get; }

/// <summary>
/// Gets a value indicating whether the runtime type of the expectation should be used rather than the declared type.
/// </summary>
bool UseRuntimeTyping { get; }

/// <summary>
/// Gets a value indicating whether and which properties should be considered.
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions Src/FluentAssertions/Equivalency/IObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public interface IObjectInfo
/// </summary>
string Path { get; set; }

/// <summary>
/// Gets the compile-time type of the current object. If the current object is not the root object and the type is not <see cref="object"/>,
/// then it returns the same <see cref="System.Type"/> as the <see cref="IObjectInfo.RuntimeType"/> property does.
/// </summary>
Type CompileTimeType { get; }

/// <summary>
/// Gets the run-time type of the current object.
/// </summary>
Expand Down
8 changes: 2 additions & 6 deletions Src/FluentAssertions/Equivalency/MemberSelectionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace FluentAssertions.Equivalency;
/// </summary>
public class MemberSelectionContext
{
private readonly Type compileTimeType;
private readonly Type runtimeType;
private readonly IEquivalencyOptions options;

public MemberSelectionContext(Type compileTimeType, Type runtimeType, IEquivalencyOptions options)
public MemberSelectionContext(Type runtimeType, IEquivalencyOptions options)
{
this.runtimeType = runtimeType;
this.compileTimeType = compileTimeType;
this.options = options;
}

Expand All @@ -36,9 +34,7 @@ public Type Type
{
get
{
Type type = options.UseRuntimeTyping ? runtimeType : compileTimeType;

return type.NullableOrActualType();
return runtimeType.NullableOrActualType();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class ByteArrayOrderingRule : IOrderingRule
{
public OrderStrictness Evaluate(IObjectInfo objectInfo)
{
return objectInfo.CompileTimeType.IsSameOrInherits(typeof(IEnumerable<byte>))
return objectInfo.RuntimeType.IsSameOrInherits(typeof(IEnumerable<byte>))
? OrderStrictness.Strict
: OrderStrictness.Irrelevant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public CollectionMemberObjectInfo(IObjectInfo context)

ParentType = context.ParentType;
RuntimeType = context.RuntimeType;
CompileTimeType = context.CompileTimeType;
}

private static string GetAdjustedPropertyPath(string propertyPath)
Expand All @@ -28,7 +27,5 @@ private static string GetAdjustedPropertyPath(string propertyPath)

public string Path { get; set; }

public Type CompileTimeType { get; }

public Type RuntimeType { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public abstract class SelfReferenceEquivalencyOptions<TSelf> : IEquivalencyOptio

private EnumEquivalencyHandling enumEquivalencyHandling;

private bool useRuntimeTyping;

private MemberVisibility includedProperties;
private MemberVisibility includedFields;
private bool ignoreNonBrowsableOnSubject;
Expand Down Expand Up @@ -83,7 +81,6 @@ protected SelfReferenceEquivalencyOptions(IEquivalencyOptions defaults)
cyclicReferenceHandling = defaults.CyclicReferenceHandling;
allowInfiniteRecursion = defaults.AllowInfiniteRecursion;
enumEquivalencyHandling = defaults.EnumEquivalencyHandling;
useRuntimeTyping = defaults.UseRuntimeTyping;
includedProperties = defaults.IncludedProperties;
includedFields = defaults.IncludedFields;
ignoreNonBrowsableOnSubject = defaults.IgnoreNonBrowsableOnSubject;
Expand Down Expand Up @@ -171,8 +168,6 @@ IEnumerable<IMemberSelectionRule> IEquivalencyOptions.SelectionRules

EnumEquivalencyHandling IEquivalencyOptions.EnumEquivalencyHandling => enumEquivalencyHandling;

bool IEquivalencyOptions.UseRuntimeTyping => useRuntimeTyping;

MemberVisibility IEquivalencyOptions.IncludedProperties => includedProperties;

MemberVisibility IEquivalencyOptions.IncludedFields => includedFields;
Expand Down Expand Up @@ -204,8 +199,6 @@ EqualityStrategy IEquivalencyOptions.GetEqualityStrategy(Type type)
/// </remarks>
public TSelf IncludingAllDeclaredProperties()
{
RespectingDeclaredTypes();

ExcludingFields();
IncludingProperties();

Expand All @@ -222,8 +215,6 @@ public TSelf IncludingAllDeclaredProperties()
/// </remarks>
public TSelf IncludingAllRuntimeProperties()
{
RespectingRuntimeTypes();

ExcludingFields();
IncludingProperties();

Expand Down Expand Up @@ -330,24 +321,6 @@ public TSelf IgnoringNonBrowsableMembersOnSubject()
return (TSelf)this;
}

/// <summary>
/// Instructs the comparison to respect the expectation's runtime type.
/// </summary>
public TSelf RespectingRuntimeTypes()
{
useRuntimeTyping = true;
return (TSelf)this;
}

/// <summary>
/// Instructs the comparison to respect the expectation's declared type.
/// </summary>
public TSelf RespectingDeclaredTypes()
{
useRuntimeTyping = false;
return (TSelf)this;
}

/// <summary>
/// Excludes a (nested) property based on a predicate from the structural equality check.
/// </summary>
Expand Down Expand Up @@ -778,10 +751,6 @@ public override string ToString()
{
var builder = new StringBuilder();

builder.Append("- Use ")
.Append(useRuntimeTyping ? "runtime" : "declared")
.AppendLine(" types and members");

if (ignoreNonBrowsableOnSubject)
{
builder.AppendLine("- Do not consider members marked non-browsable on the subject");
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Equivalency/Steps/EnumEqualityStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EnumEqualityStep : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
if (!comparands.GetExpectedType(context.Options).IsEnum)
if (!comparands.GetExpectedType().IsEnum)
{
return EquivalencyResult.ContinueWithNext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EnumerableEquivalencyStep : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
if (!IsCollection(comparands.GetExpectedType(context.Options)))
if (!IsCollection(comparands.GetExpectedType()))
{
return EquivalencyResult.ContinueWithNext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public EqualityComparerEquivalencyStep(IEqualityComparer<T> comparer)
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
var expectedType = context.Options.UseRuntimeTyping ? comparands.RuntimeType : comparands.CompileTimeType;

var expectedType = comparands.RuntimeType;
if (expectedType != typeof(T))
{
return EquivalencyResult.ContinueWithNext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon
return EquivalencyResult.ContinueWithNext;
}

Type expectationType = comparands.GetExpectedType(context.Options);
Type expectationType = comparands.GetExpectedType();

if (DictionaryInterfaceInfo.FindFrom(expectationType, "expectation") is not { } expectedDictionary)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GenericEnumerableEquivalencyStep : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
Type expectedType = comparands.GetExpectedType(context.Options);
Type expectedType = comparands.GetExpectedType();

if (comparands.Expectation is null || !IsGenericCollection(expectedType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class StringEqualityEquivalencyStep : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
Type expectationType = comparands.GetExpectedType(context.Options);
Type expectationType = comparands.GetExpectedType();

if (expectationType is null || expectationType != typeof(string))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static IEnumerable<IMember> GetMembersFromExpectation(INode currentNode,
foreach (IMemberSelectionRule rule in options.SelectionRules)
{
members = rule.SelectMembers(currentNode, members,
new MemberSelectionContext(comparands.CompileTimeType, comparands.RuntimeType, options));
new MemberSelectionContext(comparands.RuntimeType, options));
}

return members;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ValueTypeEquivalencyStep : IEquivalencyStep
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IValidateChildNodeEquivalency valueChildNodes)
{
Type expectationType = comparands.GetExpectedType(context.Options);
Type expectationType = comparands.GetExpectedType();
EqualityStrategy strategy = context.Options.GetEqualityStrategy(expectationType);

bool canHandle = strategy is EqualityStrategy.Equals or EqualityStrategy.ForceEquals;
Expand Down
4 changes: 2 additions & 2 deletions Src/FluentAssertions/ObjectAssertionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static AndConstraint<ObjectAssertions> BeDataContractSerializable<T>(this
var deserializedObject = CreateCloneUsingDataContractSerializer(assertions.Subject);

EquivalencyOptions<T> defaultOptions = AssertionOptions.CloneDefaults<T>()
.RespectingRuntimeTypes().IncludingFields().IncludingProperties();
.IncludingFields().IncludingProperties();

((T)deserializedObject).Should().BeEquivalentTo((T)assertions.Subject, _ => options(defaultOptions));
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static AndConstraint<ObjectAssertions> BeXmlSerializable(this ObjectAsser
object deserializedObject = CreateCloneUsingXmlSerializer(assertions.Subject);

deserializedObject.Should().BeEquivalentTo(assertions.Subject,
options => options.RespectingRuntimeTypes().IncludingFields().IncludingProperties());
options => options.IncludingFields().IncludingProperties());
}
catch (Exception exc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ namespace FluentAssertions.Equivalency
public object Expectation { get; set; }
public System.Type RuntimeType { get; }
public object Subject { get; set; }
public System.Type GetExpectedType(FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public System.Type GetExpectedType() { }
public override string ToString() { }
}
public class ConversionSelector
Expand Down Expand Up @@ -748,7 +748,6 @@ namespace FluentAssertions.Equivalency
FluentAssertions.Equivalency.OrderingRuleCollection OrderingRules { get; }
System.Collections.Generic.IEnumerable<FluentAssertions.Equivalency.IMemberSelectionRule> SelectionRules { get; }
FluentAssertions.Equivalency.Tracing.ITraceWriter TraceWriter { get; }
bool UseRuntimeTyping { get; }
System.Collections.Generic.IEnumerable<FluentAssertions.Equivalency.IEquivalencyStep> UserEquivalencySteps { get; }
FluentAssertions.Equivalency.EqualityStrategy GetEqualityStrategy(System.Type type);
}
Expand Down Expand Up @@ -810,7 +809,6 @@ namespace FluentAssertions.Equivalency
}
public interface IObjectInfo
{
System.Type CompileTimeType { get; }
System.Type ParentType { get; }
string Path { get; set; }
System.Type RuntimeType { get; }
Expand All @@ -831,7 +829,7 @@ namespace FluentAssertions.Equivalency
}
public class MemberSelectionContext
{
public MemberSelectionContext(System.Type compileTimeType, System.Type runtimeType, FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public MemberSelectionContext(System.Type runtimeType, FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public FluentAssertions.Equivalency.MemberVisibility IncludedFields { get; }
public FluentAssertions.Equivalency.MemberVisibility IncludedProperties { get; }
public System.Type Type { get; }
Expand Down Expand Up @@ -909,8 +907,6 @@ namespace FluentAssertions.Equivalency
public TSelf IncludingInternalProperties() { }
public TSelf IncludingNestedObjects() { }
public TSelf IncludingProperties() { }
public TSelf RespectingDeclaredTypes() { }
public TSelf RespectingRuntimeTypes() { }
public TSelf ThrowingOnMissingMembers() { }
public override string ToString() { }
public TSelf Using(FluentAssertions.Equivalency.IEquivalencyStep equivalencyStep) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ namespace FluentAssertions.Equivalency
public object Expectation { get; set; }
public System.Type RuntimeType { get; }
public object Subject { get; set; }
public System.Type GetExpectedType(FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public System.Type GetExpectedType() { }
public override string ToString() { }
}
public class ConversionSelector
Expand Down Expand Up @@ -761,7 +761,6 @@ namespace FluentAssertions.Equivalency
FluentAssertions.Equivalency.OrderingRuleCollection OrderingRules { get; }
System.Collections.Generic.IEnumerable<FluentAssertions.Equivalency.IMemberSelectionRule> SelectionRules { get; }
FluentAssertions.Equivalency.Tracing.ITraceWriter TraceWriter { get; }
bool UseRuntimeTyping { get; }
System.Collections.Generic.IEnumerable<FluentAssertions.Equivalency.IEquivalencyStep> UserEquivalencySteps { get; }
FluentAssertions.Equivalency.EqualityStrategy GetEqualityStrategy(System.Type type);
}
Expand Down Expand Up @@ -823,7 +822,6 @@ namespace FluentAssertions.Equivalency
}
public interface IObjectInfo
{
System.Type CompileTimeType { get; }
System.Type ParentType { get; }
string Path { get; set; }
System.Type RuntimeType { get; }
Expand All @@ -844,7 +842,7 @@ namespace FluentAssertions.Equivalency
}
public class MemberSelectionContext
{
public MemberSelectionContext(System.Type compileTimeType, System.Type runtimeType, FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public MemberSelectionContext(System.Type runtimeType, FluentAssertions.Equivalency.IEquivalencyOptions options) { }
public FluentAssertions.Equivalency.MemberVisibility IncludedFields { get; }
public FluentAssertions.Equivalency.MemberVisibility IncludedProperties { get; }
public System.Type Type { get; }
Expand Down Expand Up @@ -922,8 +920,6 @@ namespace FluentAssertions.Equivalency
public TSelf IncludingInternalProperties() { }
public TSelf IncludingNestedObjects() { }
public TSelf IncludingProperties() { }
public TSelf RespectingDeclaredTypes() { }
public TSelf RespectingRuntimeTypes() { }
public TSelf ThrowingOnMissingMembers() { }
public override string ToString() { }
public TSelf Using(FluentAssertions.Equivalency.IEquivalencyStep equivalencyStep) { }
Expand Down
Loading

0 comments on commit 412e378

Please sign in to comment.