Есть две таблицы DataTable с почти одинаковой структурой, желательно проверить, эквивалентны ли они:
// Arrange
var expected = new DataTable();
expected.Columns.Add("DISTANCE", typeof(double));
expected.Columns.Add("ANOMALY_TYPE_SCL", typeof(string));
expected.Columns.Add("O_CLOCK", typeof(string));
expected.Columns.Add("INTERNAL", typeof(string));
expected.Rows.Add(20.975, "MELO-MIFE", "07:06", "INT");
expected.Rows.Add(21.077, "MELO-MIFE", "06:57", "INT");
expected.Rows.Add(22.319, "MELO", "07:07", "INT");
expected.Rows.Add(34.657, "MELO", "03:45", "INT");
var actual = new DataTable();
actual.Columns.Add("DISTANCE", typeof(object));
actual.Columns.Add("ANOMALY_TYPE_SCL", typeof(object));
actual.Columns.Add("O_CLOCK", typeof(object));
actual.Columns.Add("INTERNAL", typeof(object));
actual.Rows.Add(20.975, "MELO-MIFE", "07:06", "INT");
actual.Rows.Add(21.077, "MELO-MIFE", "06:57", "INT");
actual.Rows.Add(22.319, "MELO", "07:07", "INT");
actual.Rows.Add(34.657, "MELO", "03:45", "INT");
// Act & Assert
actual.Should().BeEquivalentTo(expected, options => options.AllowingMismatchedTypes());
следуя документации options.AllowingMismatchedTypes(), но выполнение теста продолжает возвращать следующий результат:
Expected property actual.Columns[0].DataType to be System.Double, but found System.Object.
Expected property actual.Columns[1].DataType to be System.String, but found System.Object.
Expected property actual.Columns[2].DataType to be System.String, but found System.Object.
Expected property actual.Columns[3].DataType to be System.String, but found System.Object.
With configuration:
- Use declared types and members
- Compare enums by value
- Compare tuples by their properties
- Compare anonymous types by their properties
- Compare records by their members
- Include non-browsable members
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- Without automatic conversion.
Добавление следующего исключения также не сработало:
actual.Should().BeEquivalentTo(expected, options => options.AllowingMismatchedTypes().Excluding(su =>
(su.Type == typeof(DataColumn)) && (su.Path.EndsWith("DataType"))));
Подробнее здесь: https://stackoverflow.com/questions/789 ... s-ignoring