When doing this to project has
Moq.4.16.1 and the namespace I used was
Moq.Language but it was just resolved with
.Verify where you passed
DynamicParameters its also possible to instead use
It.Is<DynamicParameters>(x => x.Foo == "foo") but I wanted to try the callback option. There are some It.Is examples here.
I was unit testing a command that runs a stored procedure for Dapper using DynamicParameters. The DynamicParameters are created privately inside the unit of work (the method Im testing).
The stack is
IDbUtility. For the purpose of this post I dont look at
MyController, it only gives some context.
I needed to verify that
bar are set in the parameters in
public public class MyCommand : IMyCommand
_dbUtility is injected into the constructor of my class under test, I was mocking it. So in the test I could use a
.CallBack() to reach in and inspect the parameters.
.Setup() to tell Moq which method and overload, I called
.Callback. From the docs:
.Callback(…) Specifies a callback to invoke when the method is called that receives the original arguments
So then all I needed to do was call the unit of work and then check what was captured as
I’ve used this
.Callback() on the past for CancellationToken.