更新到最新的 FluentAssertions 破坏了我的单元测试
Update to latest FluentAssertions breaks my unittests
我正在尝试使用最新版本的 FluentAssertions (4.0.1) 更新我的 Unittest 项目,但由于 API 的更改,我的测试不再编译。在更新之前,我使用的是 3.4.1 版,以下代码已编译并成功运行。
测试序列化和反序列化 class 的实例,然后使用 FluentAssertions 比较两个对象,并设置排除用 IgnoreDataMemberAttribute
.
修饰的属性
var item = this.fixture.Create<CustomClass>();
var readObject = TestHelper.SerializeAndDeserializeObject(item);
readObject.ShouldBeEquivalentTo(item,
options => options.Excluding(
p => p.PropertyInfo.GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));
所以 PropertyInfo
不再存在,我必须使用 ISubjectInfo
,但是提供的属性(SelectedMemberInfo
等)中的 none 对我有帮助我的测试运行到绿色。
我现在的问题是,如何更新我的测试代码,使其适用于 FluentAssertions 4.0.1?
我们热衷于同时支持字段和属性并简化等效性 API,我们不小心删除了该选项。得想办法重新加了。
我已经用下面的代码修复了我的单元测试。现在他们又回到了绿色
readObject.ShouldBeEquivalentTo(item,
options => options.Excluding(
p => p.SelectedMemberInfo.DeclaringType.GetProperty(p.SelectedMemberInfo.Name).GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));
我正在尝试使用最新版本的 FluentAssertions (4.0.1) 更新我的 Unittest 项目,但由于 API 的更改,我的测试不再编译。在更新之前,我使用的是 3.4.1 版,以下代码已编译并成功运行。
测试序列化和反序列化 class 的实例,然后使用 FluentAssertions 比较两个对象,并设置排除用 IgnoreDataMemberAttribute
.
var item = this.fixture.Create<CustomClass>();
var readObject = TestHelper.SerializeAndDeserializeObject(item);
readObject.ShouldBeEquivalentTo(item,
options => options.Excluding(
p => p.PropertyInfo.GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));
所以 PropertyInfo
不再存在,我必须使用 ISubjectInfo
,但是提供的属性(SelectedMemberInfo
等)中的 none 对我有帮助我的测试运行到绿色。
我现在的问题是,如何更新我的测试代码,使其适用于 FluentAssertions 4.0.1?
我们热衷于同时支持字段和属性并简化等效性 API,我们不小心删除了该选项。得想办法重新加了。
我已经用下面的代码修复了我的单元测试。现在他们又回到了绿色
readObject.ShouldBeEquivalentTo(item,
options => options.Excluding(
p => p.SelectedMemberInfo.DeclaringType.GetProperty(p.SelectedMemberInfo.Name).GetCustomAttributes(typeof(IgnoreDataMemberAttribute), true).Length != 0));