Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would approach this using dependency injection and using a mock or fake class. Note I'm using the instance method for start instead of the class method. In your regular code, you can use the default constructor and it will create a process for you. For testing you can inject a mock or fake process and simply check that the proper methods are called on your mock object and never have to actually start a process at all. You'll need to adjust this to take account of the properties I've omitted. Ex. below:</p> <pre><code> public class UtilityManager { public Process UtilityProcess { get; private set; } private bool _isRunning; public UtilityManager() : this(null) {} public UtilityManager( Process process ) { this. UtilityProcess = process ?? new Process(); this._isRunning = false; } public void Start() { if (!_isRunning) { var startInfo = new ProcessStartInfo() { CreateNoWindow = true, UseShellExecute = true, FileName = _cmdLine, Arguments = _args }; this.UtilityProcess.Start(startInfo); _isRunning = true; } else { throw new InvalidOperationException("Process already started"); } } </code></pre> <p>Test code...</p> <pre><code> [TestMethod] public void StartTest() { Process proc = new FakeProcess(); // May need to use a wrapper class UtilityManager manager = new UtilityManager( proc ); manager.CommandLine = "command"; ... manager.Start(); Assert.IsTrue( proc.StartCalled ); Assert.IsNotNull( proc.StartInfo ); Assert.AreEqual( "command", proc.StartInfo.FileName ); ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload