我使用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