0
最近、FluentAssertionsで内部オブジェクト状態の検証を避けるためにをと記載したSO questionと回答しました。今私は同じ問題に直面して、なぜ FluentAssertionsは内部プロパティOOTBを検証するのですか?なぜFluentAssertionsは内部を検証するために同等かどうか?
public class Class1
{
[Fact]
public void CompareCultureInternalFields()
{
var foo1 = new Foo();
var foo2 = new Foo();
foo1.ShouldBeEquivalentTo(foo2); // fails
}
public object Culture { get; set; }
}
public class Foo
{
public Foo()
{
InternalProp = Guid.NewGuid();
}
internal Guid InternalProp { get; }
}
例外の詳細:
Xunit.Sdk.XunitException: Expected member InternalProp to be {61625b04-c4e6-4e08-a45a-5ff8bb7d53e7}, but found {df589d73-e382-4104-8157-a41da2ca17f5}.
With configuration:
- Use declared types and members
- Compare enums by value
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
がfoo1
とfoo2
オブジェクトは、公開APIを扱う消費者のための同等ではないでしょうか?
例では、クラスが別のアセンブリ/プロジェクトにある場合は、内部プロパティにアクセスできません。クラスが同じアセンブリ内にある場合、これは良い例ではありません – Nkosi
良い点。自動生成された内部フィールドでサンプルを書き直すとどうなりますか? –
今、私はあなたが何を意味しているのか理解しています。 – Nkosi