I have a method that looks like:
public void CloseInputTab()
{
if (MessageBox.Show("Are you sure you want to cancel? Any Unsaved changes will be lost", "Confirm Cancel", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
//Do Stuff
}
}
I’m working on writing two automated test cases.
1) Verify Stuff happens if OK was clicked
2) Verify Stuff didn’t happen if Cancel was clicked
Is there a way in the Visual Studio testing tools to Click the appropriate button for each test.
If not I could copy the code out to a Mocked class that is available to me but I’d prefer not to.
If you are using WinForms, it would be great to stick to the Model-View-Presenter pattern. (How to: Unit Test a Presenter)
If you are using WPF, please consider using Model-View-ViewModel pattern.
They are both provide testability.
Update
Here is an example: (MVP) Model View Presenter – Passive View with the message box.