Not quite sure what you are trying to do, but it may help.
To mock a printer (or any other external device), you must encapsulate all calls to the printer behind the interface, for example.
interface IPrinter
{
void Print(PrintData data);
}
Then all other codes should talk to the printer through this interface.
Then you can implement one version of this interface that speaks to a real printer, and one fake object that you can use for testing, etc.
, , Rhino Mocks Moq, .
public class FakePrinter : IPrinter
{
public void Print(PrintData data)
{
}
}
Update:
, , :
public class ClassThatPrints
{
private IPrinter _Printer;
public ClassThatPrints() : this(new RealPrinter())
{
}
public ClassThatPrints(IPrinter printer)
{
_Printer = printer;
}
public void MethodThatPrints()
{
...
_Printer.Print(printData)
}
}
BTW, IoC, . IoC.