【发布时间】:2017-10-06 06:03:38
【问题描述】:
我正在使用 FluentAssertions 检查视图模型。我想验证是否为属性正确引发 PropertyChanged 事件。
这在单个属性信号时工作正常:
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
有没有办法检查这样的事件?
【问题讨论】:
标签: c# unit-testing inotifypropertychanged fluent-assertions