断言记录同时排除特定属性 - NUnit

问题描述 投票:0回答:0

我有一个包含多个属性的记录。

我想根据类型断言记录的属性,而不是全部使用 NUnit。

public record Employee(
       int id,
       string Name,
       double Salary
       ....
)

我可以使用

Assert.That(result.Id, Is.EqualTo(id))

单独断言记录的属性

但是想知道我们是否可以根据类型比较记录,排除它的某些属性? 喜欢

Assert.That(result, Is.EqualTo(employeeRecord).And.<Types within employeerRecord for comparision>)

试过

Assert.That(result.ToString(), Is.EqualTo(employeeRecord.ToString()))

但是,在这种情况下,我们可能无法比较数据类型,因为所有数据都已转换为字符串。

换句话说,我可以根据数据类型过滤记录,然后仅断言其中的特定字段吗?

c# unit-testing asp.net-core nunit nunit-3.0
© www.soinside.com 2019 - 2024. All rights reserved.