Skip to content

Exception when using WithStrictOrderingFor on enums #2927

@lg2de

Description

@lg2de

Description

While testing upgrade from 6.X to 8.0.rc2 I faced an exception when using BeEquivalentTo with WithStrictOrderingFor on an enum.

Reproduction Steps

public class UnitTest1
{
    public enum TestEnum
    {
        Undefined,
        Active,
        Manual
    }
    
    [Fact]
    public void Test1()
    {
        var existing = new List<TestEnum> { TestEnum.Active, TestEnum.Manual };

        existing.Should().BeEquivalentTo([TestEnum.Active, TestEnum.Manual],
            options => options.WithStrictOrderingFor(v => v));
    }
}

Expected behavior

Test succeed.

Actual behavior

System.InvalidOperationException
Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at FluentAssertions.Common.ExpressionExtensions.GetMemberPath[TDeclaringType,TPropertyType](Expression`1 expression)
   at FluentAssertions.Equivalency.EquivalencyOptions`1.WithStrictOrderingFor(Expression`1 expression)
   at TestProject1.UnitTest1.<>c.<Test1>b__1_0(EquivalencyOptions`1 options) in C:\Lukas\Projekte\github-lg2de\TestProject1\TestProject1\UnitTest1.cs:line 20
   at FluentAssertions.Collections.GenericCollectionAssertions`3.BeEquivalentTo[TExpectation](IEnumerable`1 expectation, Func`2 config, String because, Object[] becauseArgs)
   at TestProject1.UnitTest1.Test1() in C:\Lukas\Projekte\github-lg2de\TestProject1\TestProject1\UnitTest1.cs:line 19
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Regression?

The problem starts when updating from 7.0.0 to 8.0.0-rc2 and disappears on downgrading to 7.0.0-apha.5.

Known Workarounds

N/A

Configuration

net8

Other information

No response

Are you willing to help with a pull-request?

Yes, please assign this issue to me.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions