tags:

views:

50

answers:

2

Let's assume I have some method that executes CLI application. For example:

public string SomeMethod(string cmd)
{
    var p = new ProcessStartInfo(cmd);
    // processing execution results
    return result;
}

How can I change this method to make it testable?

I see that I can split that method into 2:
1. Executes CLI app and passes the execution result to the second
2. Processes the results in some way and returns the answer

May be some other handy ways?

A: 

I am not quite sure I fully understand what you are doing but it you could intercept STDOUT and STDERR of the process. However, this does require setting the UseShellExecute, RedirectStandardError, and RedirectStandardOut flags on the `ProcessStartInfo' instance to true.

linuxuser27
yes, you did not understand :-) http://en.wikipedia.org/wiki/Unit_testing
zerkms
A: 

Well, I've decided to implement that as i offered in the question.

zerkms