I have the following test case:
[Test]
public void MarkAsSuccessfulTest()
{
//setup data
var payment = Util.DbUtil.CreateNewRecurringProfilePayment();
//unit test
var mockNotificationSender = new Mock<IMarkAsSuccessfulNotificationSender>();
var mockCommandHandler = new Mock<IDbCommandHandler<RecurringPaymentMarkAsSuccessfulCommand>>();
var classUnderTest = new RecurringProfileMarkLastPaymentAsSuccessful(mockCommandHandler.Object, mockNotificationSender.Object);
classUnderTest.MarkAsSuccessful(payment.RecurringProfile);
mockCommandHandler.Verify(x=>x.Handle(It.IsAny<RecurringPaymentMarkAsSuccessfulCommand>()), Times.Once());
mockNotificationSender.Verify(x=>x.SendNotification(payment), Times.Once());
}
The issue is with the line:
mockCommandHandler.Verify(x=>x.Handle(It.IsAny<RecurringPaymentMarkAsSuccessfulCommand>()), Times.Once())
This verifies that the .Handle() method was called. However, this is not enough for the test - This .Handle() takes a command parameter, which has one property - Payment. I would like to verify that this parameter was actually matching the payment variable.
Is this possible, or is there an issue with some of the code-design?
You can provide predicate for parameter verification:
mockCommandHandler.Verify(x =>
x.Handle(It.Is<RecurringPaymentMarkAsSuccessfulCommand>(c => c.Payment == payment))
, Times.Once());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With