-
-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
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 :)
Copilot
Metadata
Metadata
Assignees
Labels
No labels