我想使用 NSubstitute 创建一个间谍,但在经过大量谷歌搜索和阅读文档后无法找到。
这个想法是用一个覆盖的方法来替代,我可以像往常一样使用模拟来监控收到的呼叫等。但是如何使用 NSubstitute 来实现呢?
我宁愿既不放松protected也不放松abstract修饰符。
这是我想做的事情:
[Test]
public void Items_Add_shouldCall_ItemAddedMethod()
{
var sut = Substitute.For<ItemsRepository>();
// how to configure???
sut.Items.Add(Substitute.For<IItem>());
sut.Received().ItemAdded(); // currently cannot do this
// ...
public abstract class ItemsRepository
{
public ObservableCollection<IItem> Items { get; set; }
= new ObservableCollection<IItem>();
// ...
protected abstract void ItemAdded();
}