DD.WellWorkover.Cloud/AsbCloudWebApi.IntegrationTests/MatchHelper.cs

31 lines
924 B
C#
Raw Normal View History

using System.Reflection;
using Xunit.Sdk;
namespace AsbCloudWebApi.IntegrationTests;
public static class MatchHelper
{
public static void Match<T>(T expected, T actual, IEnumerable<string>? excludeProps = null)
{
if (ReferenceEquals(expected, actual))
2024-01-18 11:05:22 +05:00
throw EqualException.ForMismatchedValues(expected, actual);
if (expected is null || actual is null)
2024-01-18 11:05:22 +05:00
throw EqualException.ForMismatchedValues(expected, actual);
var props = typeof(T).GetProperties(
BindingFlags.Public
| BindingFlags.Instance).Where(prop => prop.CanWrite);
if (excludeProps is not null && excludeProps.Any())
props = props.Where(prop => !excludeProps.Contains(prop.Name));
foreach (var prop in props)
{
var objValue = prop.GetValue(expected);
var anotherValue = prop.GetValue(actual);
if (objValue != null && !objValue.Equals(anotherValue))
2024-01-18 11:05:22 +05:00
throw EqualException.ForMismatchedValues(expected, actual);
}
}
}