DD.WellWorkover.Cloud/AsbCloudWebApi.IntegrationTests/MatchHelper.cs
Степанов Дмитрий 88ce24b8bb Интеграционные тесты
1. Создание инфраструктуры для интегарционных тестов
2. Покрытие контроллера месторождений тестами
2023-12-29 11:46:17 +05:00

31 lines
876 B
C#

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))
throw new EqualException(expected, actual);
if (expected is null || actual is null)
throw new EqualException(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))
throw new EqualException(expected, actual);
}
}
}