Closure testing

I have a very simple method that I am trying to test. _interactionService establishes a dialog that asks the user to confirm the removal of the client. If the button is clicked on the corresponding button, the called action is called up. The action controls the context and saves the changes. After the save is complete, another action is called.

    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);
        });
}

I do not understand how to check this method. I mocked the service and context, but how do I check for a close?

+3
source share
2 answers

If the context is ridiculed, you can use the callback in your test:

Action saveAction = null;
contextMock
  .Setup(c => c.Save(It.IsAny<Action>())
  .Callback<Action>(a => saveAction = a);

// Call delete...

Assert.IsNotNull(saveAction);

saveAction();

// Assert that DoSomethingElseWhenSaveCompleted was done
+3
source

(API), . ?

  • , delete

2, .

0

All Articles