You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To start with explaining my own wrong expectation: I thought that a strict mock would implicitly verify all when it was disposed. This is somewhat a stupid assumption, since IMock doesn't implement IDisposable at all... So that was quite the revelation when I removed a call on an interface and expected the unit test would fail, which injected a strict mock for that dependency. The test passes all the same, until I explicitly call into mock.VerifyAll()
We use moq for years, and recently started out with autofac and thus Autofac.Extras.Moq to unleash the power of AutoMock. I am a fan from the moment we started out with this.
The mock repository returned by AutoMock.GetStrict() gives me an instance which is disposable. That's where I made the wrong assumption, and assumed that disposing the instance return by AutoMock.GetStrict() would also dispose all the mocks registered in the autofac container, and consequently it would call VerifyAll on these mocks. Now I know, this is not the case. But I was wondering, could you? Would it make sense to have such a feature? Especially for strict mocks I would really like the implicit check if all expectations were satisfied. Rather that, then having to add the boilerplate in every unit test to call VerifyAll on all registered mocks...
Even without AutoMock I would be able to declare a mock as follows
using var mock = new Mock<ISomeDependency>();
And when the mock runs out of scope, it would call VerifyAll in the dispose and I would be notified if I had expectations which weren't met.
The text was updated successfully, but these errors were encountered:
Due to lack of recent activity, this issue has been labeled as 'stale'.
It will be closed if no further activity occurs within 30 more days.
Any new comment will remove the label.
To start with explaining my own wrong expectation: I thought that a strict mock would implicitly verify all when it was disposed. This is somewhat a stupid assumption, since
IMock
doesn't implementIDisposable
at all... So that was quite the revelation when I removed a call on an interface and expected the unit test would fail, which injected a strict mock for that dependency. The test passes all the same, until I explicitly call intomock.VerifyAll()
We use moq for years, and recently started out with autofac and thus Autofac.Extras.Moq to unleash the power of
AutoMock
. I am a fan from the moment we started out with this.The mock repository returned by
AutoMock.GetStrict()
gives me an instance which is disposable. That's where I made the wrong assumption, and assumed that disposing the instance return byAutoMock.GetStrict()
would also dispose all the mocks registered in the autofac container, and consequently it would callVerifyAll
on these mocks. Now I know, this is not the case. But I was wondering, could you? Would it make sense to have such a feature? Especially for strict mocks I would really like the implicit check if all expectations were satisfied. Rather that, then having to add the boilerplate in every unit test to callVerifyAll
on all registered mocks...Even without
AutoMock
I would be able to declare a mock as followsusing var mock = new Mock<ISomeDependency>();
And when the mock runs out of scope, it would call
VerifyAll
in the dispose and I would be notified if I had expectations which weren't met.The text was updated successfully, but these errors were encountered: