FluentAssertions图比较,ExcludingNestedObjects被忽略了吗?

时间:2015-04-16 14:18:29

标签: entity-framework fluent-assertions

我有一个单元/集成测试如下。

using (var repository = _factory.Get())
{
    applicationBefore = repository.Applications
        .Include(a => a.AcceptedAgreements)
        .Single(a => a.AggregateId == applicationId);
}

// Perform an operation that deletes an Application and all
// related data and then rebuilds it from the event store.

Repo.Application applicationAfter = null;

using (var repository = _factory.Get())
{
    applicationAfter = repository.Applications
        .Include(a => a.AcceptedAgreements)
        .Single(a => a.AggregateId == applicationId);
}

applicationAfter.AcceptedAgreements.ShouldAllBeEquivalentTo(applicationBefore.AcceptedAgreements, options => options
    .ExcludingNestedObjects());

repository引用为DbContextAcceptedAgreements为导航属性。

此测试失败,并显示以下消息。

Result Message: 
FluentAssertions.Execution.AssertionFailedException : 
Expected item[0].Application.Id to be 1, but found 2.
<more failures where stuff inside Application is different>

With configuration:
- Use declared types and members
- Compare enums by value
- Include all non-private properties
- Include all non-private fields
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- FluentAssertions.Equivalency.ShouldAllBeEquivalentToHelper+CollectionMemberOrderingRuleDecorator

如果我按如下方式修改断言:

applicationAfter.AcceptedAgreements.ShouldAllBeEquivalentTo(applicationBefore.AcceptedAgreements, options => options
    .Excluding(o => o.Application));

现在测试通过了。

请帮助我理解为什么ExcludingNestedObjects()不会排除Application属性,这实际上是一个嵌套对象,我不得不单独排除每个导航属性。上面的代码略有简化,因为我实际上有多个导航属性,必须单独排除它们。

0 个答案:

没有答案