TypeMock - 伪造Console.Error.WriteLine()

时间:2015-05-06 16:10:31

标签: c# unit-testing typemock

我正在尝试使用TypeMock伪造控制台输出日志记录:

[Test]
public void Log_Error_LogsToStdErr()
{
    var logger = SetupFakeLogger();

    logger.Log( "text to log", true );

    Isolate.Verify.WasCalledWithAnyArguments( () => logger.LogToFile( "" ) );
    Isolate.Verify.WasCalledWithAnyArguments( () => Console.Error.WriteLine( "" ) );
}

private static WrapperLogger SetupFakeLogger()
{
    Isolate.Fake.StaticMethods( typeof(Console), Members.ReturnRecursiveFakes );

    Isolate.WhenCalled( () => Console.Error.WriteLine( "" ) ).IgnoreCall();    

    return Isolate.Fake.Instance<WrapperLogger>( Members.CallOriginal, ConstructorWillBe.Called, "dir", "file.log" );
}

但是我在第二个断言中遇到以下异常(对 Console.Error.WriteLine Isolate.Verify > ):

TypeMock Verification: Method System.Environment.NewLine was expected but was not called

这是某种错误,还是我做错了?

0 个答案:

没有答案