0
我有一個錯誤登錄ILogger。如何驗證ILogger.LogMessage中的錯誤?
ILogger.LogMessage(Error, "Steps failed", System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
我需要在我的單元測試中驗證是否拋出同樣的錯誤。我怎樣才能做到這一點。以下是我正在嘗試使用Mock進行的操作。
var expectedException = @""Steps failed", System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
_Mocklogger.Verify(
x =>
x.LogMessage(LogSeverity.Error, expectedException,
new System.Reflection.TargetParameterCountException(expectedException)), Times.Once);
但是這個失敗,出現錯誤:
Moq.MockException :
Expected invocation on the mock once, but was 0 times: x => x.LogMessage(LogSeverity.Error, "Parameter count mismatch.