What is the purpose of Verifiable(Func<Times> times)
if not deferral?
#1566
-
I expected this to work: var pushCount = 0;
var stackMock = new Mock<Stack<string>>();
stackMock.Setup(s => s.Push(It.IsAny<string>())).Callback(() => pushCount += 1);
stackMock.Setup(s => s.Pop()).Verifiable(() => Times.Exactly(pushCount));
var sut = new MyClass(stackMock.Object);
var act = MyClass.MethodThatShouldNotLeakStackOnError;
await act.Should().ThrowAsync<InvalidOperationException>();
mock.VerifyAll(); However, when I debug this, the lamba in
What then is the purpose of that overload, if not deferral? It seems its current use means that I might just as well run the code in the lambda on the line before the setup. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The For example you can use |
Beta Was this translation helpful? Give feedback.
The
Verifiable(Func<Times> times)
allows to use someTimes
methods, likeTimes.Once()
orTimes.AtLeastOnce()
without using()
.For example you can use
Verify(Times.Once())
orVerify(Times.Once)
, it is exactly the same behavior.It is just a syntax sugar to make the Verify() method more
natural
to read...