adrianiftode / Moq.ILogger

Easy verify ILogger Moq mocks
Apache License 2.0
66 stars 7 forks source link

failed test due to unexpected exception #12

Closed iriapb closed 1 year ago

iriapb commented 2 years ago

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_0`1.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 WhereArrayIterator`1.MoveNext() Mock.GetMatchingInvocationCount(Mock mock, ImmutablePopOnlyStack`1& parts, HashSet`1 visitedInnerMocks, List`1 invocationsToBeMarkedAsVerified) line 467 Mock.GetMatchingInvocationCount(Mock mock, LambdaExpression expression, List`1& invocationsToBeMarkedAsVerified) line 439 Mock.Verify(Mock mock, LambdaExpression expression, Times times, String failMessage) line 323 Mock`1.Verify(Expression`1 expression, String failMessage) line 764 VerifyLogExtensions.Verify[T](Mock`1 loggerMock, Expression`1 expression, Nullable`1 times, Func`1 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 ));
adrianiftode commented 1 year ago

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?

adrianiftode commented 1 year ago

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