Verifying generic method called using Moq

后端 未结 2 1467
無奈伤痛
無奈伤痛 2021-01-17 18:12

I\'m having trouble verifying that mock of IInterface.SomeMethod(T arg) was called using Moq.Mock.Verify.

I\'m can verify that met

相关标签:
2条回答
  • 2021-01-17 18:35

    I'm going to wing it. Since GenericMethod<T> requires that a T argument be provided, would it be possible to do:

    mockInterface.Verify(serviceInterface => serviceInterface.GenericMethod(It.Is<object>(x=> typeof(ISpecificCommand).IsAssignableFrom(x.GetType()))), Times.Once());
    
    0 讨论(0)
  • 2021-01-17 18:56

    It is a known issue in the Moq 4.0.10827 which is a current release version. See this discussion at GitHub https://github.com/Moq/moq4/pull/25. I have downloaded its dev branch, compiled and referenced it and now your test passes.

    0 讨论(0)
提交回复
热议问题