【发布时间】:2021-09-10 10:28:08
【问题描述】:
我有如下代码。 第一次调用 save(),我希望它抛出异常。 而当 obj.field="ok" 时的第二次调用,我不希望它抛出异常。 我如何通过 Nsubstitute 实现这一目标?
Try { //Source codes
workItem.save() //save() has void as return type
} catch (Exception e) {
if (somecondition){
workItem.field = "OK";
workItem.save();
}
}
// Unit Test
workItem.When(fake => fake.Save()).Do(call => { throw new AggregateException(); });
// How do I make the second call to workItem.save() not throw any exception??
【问题讨论】:
标签: c# unit-testing nsubstitute