fluentassertions / fluentassertions/fluentassertions.json

Configuration of IJsonAssertionOptions slows down comparison a log

未关闭
#77 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
C#
星标
73
派生
30
PR 合并指标
30 天内没有已合并 PR

描述

To check doubles using precision when comparing JSON's, I am using the following options callback in `BeEquivalentTo`:

```cs
options => options.Using(d => d.Subject.Should().BeApproximately(d.Expectation, 0.001))
.WhenTypeIs()
```

But it seems that this builder callback is being called for every value comparison.
JTokenDifferentiator.CompareValues contains:

```cs
using (var scope = new AssertionScope())
{
actual.Value.Should().BeEquivalentTo(expected.Value, options =>
(JsonAssertionOptions)config.Invoke(new JsonAssertionOptions(options)));

hasMismatches = scope.Discard().Length > 0;
}
```

With the addition of the Using, a bigger json (MB's) goes from 200ms to +10s on my PC.

As a workaround, I replicated the behavior of the builder by accessing the `userEquivalencySteps` field on `SelfReferenceEquivalencyAssertionOptions` using reflection and inserting a custom `IEquivalencyStep`, instead of using the fluent API.
This brings it to 1s, which is acceptable for my use case.

Would it make sense to not call this options callback for every JSON value and build it once?
Or would adding API to add a custom `IEquivalencyStep` instead of the builder make sense?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。