我不知道,如果你能幫助我理解下面一行:It.IsAny <Cart>(),It.IsAny <ShippingDetails>(),Times.Never()。他們在做什麼?
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(),
It.IsAny<ShippingDetails>()),
Times.Never());
測試方法:
[TestMethod]
public void Cannot_Checkout_Empty_Cart()
{
// Arrange - create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create an empty cart
Cart cart = new Cart();
// Arrange - create shipping details
ShippingDetails shippingDetails = new ShippingDetails();
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Act
ViewResult result = target.Checkout(cart, shippingDetails);
// Assert - check that the order hasn't been passed on to the processor
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
// Assert - check that the method is returning the default view
Assert.AreEqual("", result.ViewName);
// Assert - check that we are passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
之間的區別「否則驗證將只作爲參數的特定情況下發生」,很抱歉,但是這絕對不會發生,對吧?它將如何匹配實例?它不依賴於任何值類型的標準,我是對的嗎? – SomeUser
太好了,謝謝.. – SomeUser