I'm using Moq version 4.8 and have a method to mock and assert its parameter. I started with this mocked method:
mock.Setup(m => m.Update(It.IsAny<MyClass>))
.Callback((MyClass c) =>
{
// some assertions
})
.Returns(Task.FromResult(updatedClass));
where I update an object of type MyClass and do a number of assertions on that object. This works just fine.
I've just added logic to the method calling Update to retry calling it if exceptions are thrown. So I want to implement a new unit test that throws exceptions a few times and then returns and be able to do the assertions like before. So I tried SetupSequence as follows:
mock.SetupSequence(m => m.Update(It.IsAny<MyClass>))
.Throws(new Exception("test exception 1"))
.Throws(new Exception("test exception 2"))
.Callback((MyClass c) =>
{
// some assertions
})
.Returns(Task.FromResult(updatedClass));
But ISetupSequence doesn't support Callback. Is there a way to mock Throws and Returns calls in order while keeping a pre call Callback to Returns?