我有一个非常简单的方法,我正在尝试测试它。_interactionService会弹出对话框,询问用户是否确认删除客户。如果在对话框上点击了适当的按钮,则调用提供的操作。该操作会操纵上下文并保存更改。保存完成后,将调用另一个操作。
private void Delete(object entity)
{
_interactionService.ShowConfirmationBox("Delete?", "Are you sure you want to delete this customer?", () =>
{
Customer customer = entity as Customer;
Context.Attach(customer);
Context.Delete(customer);
Context.Save(() => DoSomethingElseWhenSaveComplete);
});
}
我不知道怎样测试这个方法。我已经模拟了服务和上下文,但是如何测试这些闭包呢?