=============================================================
Instead of something like this:
=============================================================
public class YourClassUnderTest
{
public YourClassUnderTest()
{
}
public void ShowMessage(User user)
{
if(user.IsLoggedIn)
{
ShowDialog(firstThing);
}
else
{
ShowDialog(somethingElse);
}
}
}
=============================================================
Try something like this:
=============================================================
public interface IDialogProvider
{
void ShowDialog(object something);
}
public class YourClassUnderTest
{
private IDialogProvider dialogProvider;
public YourClassUnderTest(IDialogProvider dialogProvider)
{
this.dialogProvider = dialogProvider;
}
public void ShowMessage(User user)
{
if(user.IsLoggedIn)
{
dialogProvider.ShowDialog(firstThing);
}
else
{
dialogProvider.ShowDialog(somethingElse);
}
}
}
=============================================================
Then you can provide a fake (or mock) to YourClassUnderTest and
the implementation of ShowDialog is up to your test. It could
just do nothing, but you check that it was called with certain
parameters.
I don't do a lot of winforms programming, but hopefully this will get his point across. If this situation isn't what you're running into, let us know. Emanuele, if this isn't what you meant, sorry, this is what I understood you were speaking of.
To get a bit more out of what I'm attempting to do with this example code, look up articles on the "Dependency Inversion Principle" and "Inversion of Control". These two programming techniques will make testing and mocking much, much easier.