title: Unit Testing a Service fully dependent on third-party application
body: <p>I am currently writing a Windows Service in C# that will be responsible for hosting a WCF Service. When Service Operations are invoked, my service will execute a command line application, do some data processing on the StandardOutput and return the results. This command line application changes state of other third party services on the server.</p>
  
  <p>This is a rare instance where I'm truely able to start from scratch, so I'd like to set it up correctly and in a way that can be easily unit tested. There is no legacy code, so I have a clean slate. What I'm struggling with is how to make my service unit-testable because it is almost entierly dependent on an external application.</p>
  
  <p>My service operations have a roughly 1:1 ratio with operations the command line application does. If you have not guessed, I'm building a tool to allow remote administration of a service which only provides CLI administration.</p>
  
  <p>Is this just a case where unit-tests are more trouble than they are worth? To provide some context, here's a quick sample from my proof of concept app.</p>
  
  <pre><code>    private string RunAdmin(String arguments)
      {
          try
          {
              var exe = String.Empty;
              if (System.IO.File.Exists(@"C:\Program Files (x86)\App\admin.exe"))
              {
                  exe = @"C:\Program Files (x86)\App\admin.exe";
              }
              else
              {
                  exe= @"C:\Program Files\App\admin.exe";
              }
  
              var psi = new System.Diagnostics.ProcessStartInfo
              {
                  FileName = exe,
                  UseShellExecute = false,
                  RedirectStandardInput = true,
                  RedirectStandardOutput = true,
              };
  
              psi.Arguments = String.Format("{0} -u {1} -p {2} -y", arguments, USR, PWD);
  
              var adm= System.Diagnostics.Process.Start(psi);
  
              var output = fmsadmin.StandardOutput.ReadToEnd();
  
              return output;
          }
          catch (Exception ex)
          {
              var pth = 
                  System.IO.Path.Combine(
                      Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                      "FMSRunError.txt");
  
              System.IO.File.WriteAllText(pth, String.Format("Message:{0}\r\n\r\nStackTrace:{1}", ex.Message, ex.StackTrace));
  
              return String.Empty;
          }
      }
  
      public String Restart()
      {
          var output = this.RunAdmin("/restart");
          return output; // has cli tool return code
      }
  </code></pre>
  
  <p>Without adding a LOT of "test" code to my RunAdmin method, is there any way to unit-test this? Obviously I could add a lot of code to the RunAdmin method to "fake" output, but I'd like to avoid that if possible. If that is the recommend way, I can probably create a script for myself to create all possible output. Is there another way?</p>