我有以下的測試案例:使用起訂量來驗證與正確的命令參數一個CommandHandler方法調用
[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
變量匹配。
這是可能的,還是有一些代碼設計的問題?
哇這很快:)完美的作品,謝謝! –