-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
With #2147 we now try to convert the subject into an enum if the expectation is an enum.
This does not work when the subject is of another enum type.
Reproduction Steps
[Fact]
public void Test()
{
var subject = new { EnumA.Value };
var expected = new { EnumB.Value };
subject.Should().BeEquivalentTo(expected, o => o.WithAutoConversion());
}
enum EnumA { Value }
enum EnumB { Value }Expected behavior
Test should pass
Actual behavior
Message:
System.ArgumentException : Object must be the same type as the enum. The type passed in was 'TestProject19.UnitTest1+EnumA'; the enum type was 'TestProject19.UnitTest1+EnumB'.
Stack Trace:
RuntimeType.IsEnumDefined(Object value)
Enum.IsDefined(Type enumType, Object value)
AutoConversionStep.TryChangeType(Object subject, Type expectationType, Object& conversionResult)
AutoConversionStep.Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
EquivalencyValidator.TryToProveNodesAreEquivalent(Comparands comparands, IEquivalencyValidationContext context)
EquivalencyValidator.RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context)
StructuralEqualityEquivalencyStep.AssertMemberEquality(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator parent, IMember selectedMember, IEquivalencyAssertionOptions options)
StructuralEqualityEquivalencyStep.Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
EquivalencyValidator.TryToProveNodesAreEquivalent(Comparands comparands, IEquivalencyValidationContext context)
EquivalencyValidator.RecursivelyAssertEquality(Comparands comparands, IEquivalencyValidationContext context)
EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context)
ObjectAssertions`2.BeEquivalentTo[TExpectation](TExpectation expectation, Func`2 config, String because, Object[] becauseArgs)
UnitTest1.Fails() line 13
Regression?
Yes, introduced with 6.11
Known Workarounds
No response
Configuration
FluentAssertions 6.11.0
Other information
No response