I am struggling to mock a particular method:
internal interface IEditScreen
{
void ShowWindow(
Customer cust, int position, bool allowDelete, bool allowSave,
out EN_EDIT_RESULT buttonResult,
out string customerId,
out int positionResult,
out int reportResults);
}
I want to call a method "Controller.ClickOnCustomer(2)" and:
1) Verify Controller calls ShowWindow()
2) Verify the values of position, allowDelete, and allowSave
3) Ignore what particular instance of cust was passed-in
4) Return certain values for the out parameters
5) Test some state after the ShowWindow() call was made.
I know how to do #1, and #5. But not #2,#3, and #4. Here is the syntax I used with Moq:
EN_EDIT_RESULT result = EN_EDIT_RESULT.SAVE;
string customerId = "";
int positionResult = 2;
int reportResults = 0;
_mockScreen.Setup(
screen => screen.ShowWindow(
It.IsAny<Customer>(),
2, false, true,
out result, out customerId, out positionResult, out reportResults)
);
How Moq handles this:
The Setup() method in Moq implicitly assumes .WithExactArguments(). The It.IsAny<> allows me to disregard the instance of Customer that was provided. I do this because Controller.ClickOnCustomer(2) creates a Customer object in this case. Now, I could probably find a way to override that constructor so I know the instance of Customer that I will get. But I haven't gone that far, and I really don't want to do that unless I must.
How to do this in TypeMock?
1) Can I use .DoInstead() and write a method body that verifies just the arguments I want to verify, and returns the out parameters I require? I am not sure how to use the DoInstead(), and it became overwhelming when I included out parameters.
2) I did Isolate.Swap.CallsOn + created another class that implements ShowWindow() the way I want. This worked, but making that class largely defeats the purpose of a mock object framework.
Goal:
I will probably be testing a dozen permutations of this call. My goal is to ensure that Controller.ClickOnCustomer() passes the right arguments in each situation, and that it does the correct state updates based on what ShowWindow() returns. The state verification stuff is no problem though.