我有以下测试用例:
[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());
}
问题在于这一行:
mockCommandHandler.Verify(x=>x.Handle(It.IsAny<RecurringPaymentMarkAsSuccessfulCommand>()), Times.Once())
这将验证该.Handle()
方法是否被调用。但是,这对于测试来说是不够的 - 这.Handle()
需要一个命令参数,它有一个属性 - Payment
。我想验证此参数是否实际上与payment
变量匹配。
这是可能的,还是某些代码设计存在问题?