chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
What if I want to get a count of how many times the _cache method was called regardless of parameters passed in?
related to an answer for: Verifying method has been called
asked by donniedarko (3.8k points)
I see the "WasCalledWithAnyArguments" verify method but if the method I am checking takes parameters I still have to specify them when calling the Verify method.

Isolate.Verify.WasCalledWithAnyArguments(Function() _fakeDbContext.InstrumentFormEntities.Add(New InstrumentFormEntity()))

The "Add" method takes a parameter, and I don't care what parameter is passed in I just want to ensure the "Add" method was called. I was looking for something similar to this:

Isolate.Verify.WasCalledWithAnyArguments(Function() _fakeDbContext.InstrumentFormEntities.Add(It.IsAny(Function() InstrumentFormEntity))))

I hope that makes sense, thanks!

 

 

 

1 Answer

0 votes
 
Best answer
To ignore the actual parameter when checking the number of times it was called:

​<TestMethod()>
Public Sub verifyCalledWithParams_TimesCalled_IgnorParams()

    Dim a As New AClass
    Isolate.WhenCalled(Sub() a.DoWorkWithParams(Nothing)).CallOriginal()

    a.DoWorkWithParams(0)
    a.DoWorkWithParams(1)
    a.DoWorkWithParams(15)

    Dim timesCallsd = Isolate.Verify.GetTimesCalled(Sub() a.DoWorkWithParams(Nothing))

    Assert.AreEqual(3, timesCallsd)

End Sub

To Check if a method was called regardless to parameters just use WasCalledWithAnyArguments:
<TestMethod()>
Public Sub verifyCalledWithParams_IgnorParams()

    Dim a As New AClass
    Isolate.WhenCalled(Sub() a.DoWorkWithParams(Nothing)).CallOriginal()

    a.DoWorkWithParams(0)

    Isolate.Verify.WasCalledWithAnyArguments(Sub() a.DoWorkWithParams(Nothing))

End Sub

 

answered by alex (17k points)
selected by donniedarko
Perfect, thanks!
...