我使用FluentAssertions來檢查視圖模型。我想驗證是否正確地提升了屬性的PropertyChanged
事件。如何檢查在爲所有屬性進行內部提升時使用FluentAssertions發送信號的屬性更改?
信號單獨的屬性時,這是工作的罰款:
public string MyName {
get => this.myName;
set => {
this.myName = value;
this.FirePropertyChanged(nameof(this.MyName));
}
}
...
sut.MonitorEvents();
sut.ShouldRaisePropertyChangeFor(model => model.MyName); // OK
一些複雜的視圖模型要刷新所有特性,並提出null
或string.Empty
這將導致以刷新(MSDN)。 但FluentAssertions調用不接受這作爲有效的更改。
public string IsServer {
get => this.isServer;
set => {
this.isServer = value;
this.FirePropertyChanged(string.Empty);
}
}
...
sut.MonitorEvents();
sut.ShouldRaisePropertyChangeFor(model => model.IsServer); // FAILED
有沒有一個選項來檢查這樣的事件?
'null'有效,但不適用於'string.Empty'。爲該邊緣情況創建了額外的擴展程序。 – Nkosi