Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Mock Process()并获取其他方法的返回值_C#_Unit Testing_Process_Mocking - Fatal编程技术网

C# Mock Process()并获取其他方法的返回值

C# Mock Process()并获取其他方法的返回值,c#,unit-testing,process,mocking,C#,Unit Testing,Process,Mocking,我有以下方法,它运行一个进程并获得其输出。此输出将被返回,并作为方法的输入参数。最后,这个方法得到这个输出以返回一个值。 是否有一个很好的解决方案来模拟单元测试的逻辑? 因为目前我被卡住了,虽然CreateProcessHelper可以模拟,但是它的输出不能进入DoSomething方法,因为我无法获得预期的值 提前谢谢 private (string, int) CreateProessHelper(string command) { return the OutPut; } priv

我有以下方法,它运行一个进程并获得其输出。此输出将被返回,并作为方法的输入参数。最后,这个方法得到这个输出以返回一个值。 是否有一个很好的解决方案来模拟单元测试的逻辑? 因为目前我被卡住了,虽然CreateProcessHelper可以模拟,但是它的输出不能进入DoSomething方法,因为我无法获得预期的值

提前谢谢

private (string, int) CreateProessHelper(string command)
{
  return the OutPut; 
}

private Task DoSomething()
{
  (string outPut, int exitCode) = CreateProessHelper(command);

  // The logic to handle this Output and return a value what I need
  Coding...
}

我认为,如果你的私有方法包含复杂的逻辑,那么它的类设计问题就更大,因为你的实现应该依赖于契约(接口),而不是一些硬编码的私有方法序列。这是否回答了你的问题?嘿,您说过可以模拟CreateProessHelper返回结果,为什么这个解决方案不适合您?你能澄清一下吗?你也可以检查它是否可以模仿一切。