I have some simple interface and I'm writing a simple unit test that invokes a Mock<>
of it.
public interface IMy() {
void Method(ISomething foo, byte[] bar);
}
var mock = new Mock<IMy>;
// ...
mock.Verify(m => m.Method(It.IsAny<ISomething>(), It.IsAny<byte[]>()), Times.Exactly(10));
However, the Verify
throws the following exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Linq.Enumerable.<OfTypeIterator>d__92`1.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at Moq.Extensions.GetValue(Object value)
at Moq.Extensions.<>c.<Format>b__1_1(Object a)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Moq.Extensions.Format(ICallContext invocation)
at Moq.Mock.<>c.<FormatInvocations>b__63_0(ICallContext i)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Moq.Mock.FormatInvocations(IEnumerable`1 invocations)
at Moq.Mock.ThrowVerifyException(MethodCall expected, IEnumerable`1 setups, IEnumerable`1 actualCalls, Expression expression, Times times, Int32 callCount)
at Moq.Mock.VerifyCalls(Interceptor targetInterceptor, MethodCall expected, Expression expression, Times times)
at Moq.Mock.Verify[T,TResult](Mock`1 mock, Expression`1 expression, Times times, String failMessage)
at Moq.Mock`1.Verify[TResult](Expression`1 expression, Times times)
Debugger doesn't help much to find what exactly could be null
here. Did anyone encounter it using Moq
library?