はい、ShouldBeEquivalentToを使用すると可能です。
:あなたが唯一のX、YおよびZの性質は、このような場合には、制約を変更比較したい場合は
double precision = 0.1;
calculated.ShouldBeEquivalentTo(expected, option => options
.Using<double>(ctx => ctx.Subject.Should().BeApproximately(ctx.Expectation, precision))
.WhenTypeIs<double>());
:次のコードでは、タイプの0.1の精度で重されているすべてのプロパティをチェックします
double precision = 0.1;
calculated.ShouldBeEquivalentTo(b, options => options
.Using<double>(ctx => ctx.Subject.Should().BeApproximately(ctx.Expectation, precision))
.When(info => info.SelectedMemberPath == "X" ||
info.SelectedMemberPath == "Y" ||
info.SelectedMemberPath == "Z"));
別のアプローチは、明示的にウィッヒ性質が比較されるべきFluentAssertionsに伝えることですが、それは少し小さいエレガントです:
double precision = 0.1;
calculated.ShouldBeEquivalentTo(b, options => options
.Including(info => info.SelectedMemberPath == "X" ||
info.SelectedMemberPath == "Y" ||
info.SelectedMemberPath == "Z")
.Using<double>(ctx => ctx.Subject.Should().BeApproximately(ctx.Expectation, precision))
.When(info => true));
Using
ステートメントはEquivalencyAssertionOptions<T>
を返しませんので、常に真の式でWhen
ステートメントを呼び出すことでハックする必要があります。
これはきれいです。だから同値テストにどのプロパティを使うかを指定するのに '.Including'ではなく' .When'をこの特定の場合に使用しなければならないのでしょうか? – Ayb4btu
Includingは、比較中に使用するプロパティをFluentAssertionsに明示的に伝えることです。私は解説で自分の答えを更新しました。 –
私はそれは好みの問題だと思いますが、 '.Including(info => info.X).Including(info => info.Y).Including(info => info.Z) '' info.SelectedMemberPath == "X" ... '? – Ayb4btu