2023-12-29 11:46:17 +05:00
|
|
|
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);
|
2023-12-29 11:46:17 +05:00
|
|
|
|
|
|
|
if (expected is null || actual is null)
|
2024-01-18 11:05:22 +05:00
|
|
|
throw EqualException.ForMismatchedValues(expected, actual);
|
2023-12-29 11:46:17 +05:00
|
|
|
|
|
|
|
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);
|
2023-12-29 11:46:17 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|