Skip to content

IgnoreMember is not suffcient #2614

@ChristianSauer

Description

@ChristianSauer

I am converting some FluentAssertions Code and there it is possible to not only ignore Members but also DataTypes - super useful for those pesky CreatedAt / etc. fields

I am circumventing it like this:

public static async Task<bool> Matchs<T>(this T actual, T expected)
    {
#pragma warning disable TUnitAssertions0002
        var assertion = Assert.That(actual).IsEquivalentTo(expected);
#pragma warning restore TUnitAssertions0002
        foreach (var property in GetDateTimeProperties(actual))
        {
            assertion.IgnoringMember(property.Name);
        }
        await assertion;
        return true;
    }

private static IEnumerable<PropertyInfo> GetDateTimeProperties<T>(T obj)
    {
        if (obj == null)
            return [];

        return obj.GetType()
            .GetProperties()
            .Where(p =>
                p.PropertyType == typeof(DateTime)
                || p.PropertyType == typeof(DateTime?)
                || p.PropertyType == typeof(DateTimeOffset)
                || p.PropertyType == typeof(DateTimeOffset?)
            );
    }

But this is cumbersome :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions