Repository navigation
Migrating to 2.x
Jean Marc Mbouma edited this page Nov 18, 2026
·
1 revision
MockLite 2.0 tightens interaction semantics so setup, callbacks, and verification describe the same calls.
1.x counted every invocation of the selected method:
mock.Verify(x => x.Get("specific"), Times.Once);In 2.0 this verifies the call to Get("specific"). Use matchers for flexible assertions:
mock.Verify(x => x.Get(It.IsAny<string>()), Times.Exactly(2));
mock.Verify(x => x.Get(It.Matches<string>(s => s.StartsWith("admin"))), Times.Once);For the old method-wide counting behavior, use the explicit API:
mock.VerifyAnyArguments(x => x.Get(It.IsAny<string>()), Times.Exactly(2));A callback chained from Setup(expression) now fires only when that setup expression matches. Use OnCall when you want a separate hook.
Generated mocks now keep multiple method setups and select the most recently registered matching setup, matching runtime mocks.
Runtime and generated public Invocations views are stable snapshots. Generated mocks expose Reset() instead of requiring mutation of the invocation list.
- Replace assertions that relied on argument-insensitive
VerifywithVerifyAnyArguments. - Check setup callbacks that intentionally observed non-matching calls; move those to
OnCall. - Replace direct
generatedMock.Invocations.Clear()calls withgeneratedMock.Reset(). - Re-run tests where several generated setups target the same method; newest matching setup now wins consistently.