adrianiftode / Moq.ILogger

Easy verify ILogger Moq mocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed test due to unexpected exception

iriapb opened this issue · comments

Message: 
Moq.VerifyLogUnexpectedException : Moq.ILogger found an unexpected exception.

Please open an issue at https://github.com/adrianiftode/Moq.ILogger/issues/new, provide the exception details and a sample code if possible.
Below will follow the unexpected exception details.

----> System.FormatException : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

System.FormatException : Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Stack Trace: 
VerifyLogExtensions.Verify[T](Mock1 loggerMock, Expression1 expression, Nullable1 times, Func1 timesFunc, String failMessage)
VerifyLogExtensions.VerifyLog[T](Mock1 loggerMock, Expression1 expression)
SendKCITests.FailedToSendMessageToCommunicationManagement_SendReminderPriorDeletion_BadIdentityProvider() line 385
GenericAdapter1.GetResult() AsyncToSyncAdapter.Await(Func1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.b__0()
BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--FormatException
<6 more frames...>
<>c__DisplayClass7_01.<Is>b__0(Object argument, Type parameterType) line 172 MatchFactory.Matches(Object argument, Type parameterType) line 251 IMatcher.Matches(Object argument, Type parameterType) line 78 InvocationShape.IsMatch(Invocation invocation) line 132 WhereArrayIterator1.MoveNext()
Mock.GetMatchingInvocationCount(Mock mock, ImmutablePopOnlyStack1& parts, HashSet1 visitedInnerMocks, List1 invocationsToBeMarkedAsVerified) line 467 Mock.GetMatchingInvocationCount(Mock mock, LambdaExpression expression, List1& invocationsToBeMarkedAsVerified) line 439
Mock.Verify(Mock mock, LambdaExpression expression, Times times, String failMessage) line 323
Mock1.Verify(Expression1 expression, String failMessage) line 764
VerifyLogExtensions.Verify[T](Mock1 loggerMock, Expression1 expression, Nullable1 times, Func1 timesFunc, String failMessage)

sample code:
_loggerMock.VerifyLog(logger => logger.LogError(EventCodes.Cids.AutoDelete.Errors.AZFUNC_SENDKCI_SENDMESSAGE_EXCEPTION_FUNCTIONALITYNOTAVAILABLE,
"Send email reminder of user login before deletion not available for brand: {staleCidsAccount.Brand}, objectId: {staleCidsAccount.ObjectId} and correlationId: {correlationId}. Response : {response.Reason}",
_staleCidsAccountReminderToSendBT.Brand,
_staleCidsAccountReminderToSendBT.ObjectId,
_staleCidsAccountReminderToSendBT.CorrelationId
));

Thanks for raising this issue. I have one question. Instead of

_loggerMock.VerifyLog(logger => logger.LogError(EventCodes.Cids.AutoDelete.Errors.AZFUNC_SENDKCI_SENDMESSAGE_EXCEPTION_FUNCTIONALITYNOTAVAILABLE,
"Send email reminder of user login before deletion not available for brand: {staleCidsAccount.Brand}, objectId: {staleCidsAccount.ObjectId} and correlationId: {correlationId}. Response : {response.Reason}",
_staleCidsAccountReminderToSendBT.Brand,
_staleCidsAccountReminderToSendBT.ObjectId,
_staleCidsAccountReminderToSendBT.CorrelationId
));

shouldn't be

_loggerMock.VerifyLog(logger => logger.LogError(EventCodes.Cids.AutoDelete.Errors.AZFUNC_SENDKCI_SENDMESSAGE_EXCEPTION_FUNCTIONALITYNOTAVAILABLE,
"Send email reminder of user login before deletion not available for brand: {staleCidsAccount.Brand}, objectId: {staleCidsAccount.ObjectId} and correlationId: {correlationId}. Response : {response.Reason}",
_staleCidsAccountReminderToSendBT.Brand,
_staleCidsAccountReminderToSendBT.ObjectId,
_staleCidsAccountReminderToSendBT.CorrelationId,
response.Reason
));

Isn't the response.Reason part missing?

@iriapb closing this issue, as it is the expected bahaviour. You can reopen if there are more details.