[英]Nsubstitute return different based on the object properties
我有如下代碼。 第一次調用 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??
我剛剛發現解決方案超級簡單
workItem
.When(x => x.Save())
.Do(obj => { if (workItem.Field.Equals("Ok")) throw new AggregateException(new Exception("Assigned")); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.