c# - How to use Microsoft Fakes Assemblies on Process.Start -
i mock system.diagnostics.process.start call, added fakes assembly system assembly.
the problem start static method on system.diagnostics.process i'm not getting shim able hock on delegate start method.
what correct way of doing this?
so first of need generate shim process class.
after create fakes system should see folder called 'fakes'. inside folder need edit system.fakes file generate shims system.diagnostics.process:
<fakes xmlns="http://schemas.microsoft.com/fakes/2011/" diagnostic="true"> <assembly name="system" version="4.0.0.0"/> <shimgeneration> <add fullname="system.diagnostics.process"/> </shimgeneration> </fakes>
after compiling able see in object explorer fakes shims process have been genereated.
to use shim in test need configure fake process.start delegate. test might end looking this:
using (shimscontext.create()) { system.diagnostics.fakes.shimprocess.startstring = s => { console.writeline(s); return new stubprocess(); }; // call method under test exectues process.start rather calling directly var process = process.start("somestring"); assert.istrue(process stubprocess); }
obviously might want include more relevant scenario test in delegate , assertions.
see msdn link
Comments
Post a Comment