I have this code:
Have a method like this:
private void Invoke(string executablePathAndFile, string commandLineArguments)
{
Process process = ProcessInstance;
ProcessStartInfo startInfo = ProcessStartInfo;
startInfo.FileName = executablePathAndFile;
startInfo.Arguments = commandLineArguments;
process.StartInfo = startInfo;
process.Start();
if (WaitForExit)
process.WaitForExit();
}
I am trying to stub or shim out Process class' method calls. Microsoft Fakes only creates a Stub and not a Shim (not sure why). I can provide StubProcess in a shimmed out call to ProcessInstanceGet:
InvokeExecutableAction sut = new InvokeExecutableAction(actionElement);
StubProcess stubProcess = new StubProcess();
ShimInvokeExecutableAction sutShim = new ShimInvokeExecutableAction(sut)
{
ProcessInstanceGet = () => stubProcess
};
but when the code under test gets to process.Start() , it comes back with a Win32Exception. I am unable to provide an alternate implementation for the stub's Start method like:
Is there a way to achieve what I need (i.e. provide an alternate execution for Start() method) or refactor the code to be more testable (without going overboard!!!)?
Aucun commentaire:
Enregistrer un commentaire