本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController.Checkout方法的典型用法代码示例。如果您正苦于以下问题:C# CartController.Checkout方法的具体用法?C# CartController.Checkout怎么用?C# CartController.Checkout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.WebUI.Controllers.CartController
的用法示例。
在下文中一共展示了CartController.Checkout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cannot_Checkout_Empty_Cart
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 I am passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例2: Cannot_Checkout_Invalid_ShippingDetails
public void Cannot_Checkout_Invalid_ShippingDetails()
{
// Arrange - create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create a cart with an item
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Arrange - add an error to the model
target.ModelState.AddModelError("error", "error");
// Act - try to checkout
ViewResult result = target.Checkout(cart, new 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 I am passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例3: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
// Arragne - Mock 주문 처리기 생성
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - 빈 Cart 개체 생성
Cart cart = new Cart();
// Arragne - 배송 정보 생성
ShippingDetails shippingDetails = new ShippingDetails();
// Arrange - 컨트롤러의 인스턴스 생성
CartController target = new CartController(null, mock.Object);
// Act
ViewResult result = target.Checkout(cart, shippingDetails);
// Assert - 주문이 주문 처리기에 전달되지 않은 것을 확인한다.
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
Times.Never());
// Assert - 메서드가 기본 뷰를 반환했는지 확인한다.
Assert.AreEqual("", result.ViewName);
// Assert - 유효하지 않은 모델을 뷰에 전달하는지 확인한다
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例4: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
ShippingDetails shippingDetails = new ShippingDetails();
CartController target = new CartController(null, mock.Object);
ViewResult result = target.Checkout(cart, shippingDetails);
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
Assert.AreEqual("", result.ViewName);
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例5: Can_Checkout_And_Submit_Order
public void Can_Checkout_And_Submit_Order()
{
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
CartController target = new CartController(null,mock.Object);
ViewResult result = target.Checkout(cart, new ShippingDetails());
mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once());
Assert.AreEqual("Completed", result.ViewName);
Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
}
示例6: Cannot_Checkout_Invalid_ShippingDetails
public void Cannot_Checkout_Invalid_ShippingDetails()
{
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
CartController target = new CartController(null, mock.Object);
target.ModelState.AddModelError("error", "error");
ViewResult result = target.Checkout(cart, new ShippingDetails());
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
Assert.AreEqual("", result.ViewName);
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例7: Cannot_Checkout_empty_cart
public void Cannot_Checkout_empty_cart()
{
var mock = new Mock<IOrderProcessor>();
var cart = new Cart();
var shipping = new ShippingDetails();
var controller = new CartController(null, mock.Object);
var result = controller.Checkout(cart, shipping);
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never);
Assert.AreEqual("", result.ViewName);
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例8: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
Mock<IOrderProcessor> mockProc = new Mock<IOrderProcessor>();
Cart cart = new Cart();
ShippingDetails shippingDetails = new ShippingDetails();
CartController target = new CartController(null, mockProc.Object);
ViewResult result = target.Checkout(cart, shippingDetails);
//Assert - check that the order hasn't been passed on to the processor, means that ProcessorOrder was never invoked
mockProc.Verify(mock=> mock.ProcessorOrder(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 i am passing an invalid model to the view
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例9: Cannot_Checkout_And_Submit_Order
public void Cannot_Checkout_And_Submit_Order()
{
Mock<IOrderProcessor> mockProc = new Mock<IOrderProcessor>();
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
CartController target = new CartController(null, mockProc.Object);
ViewResult result = target.Checkout(cart, new ShippingDetails());
//Assert - check that the order hasn't been passed on to the processor, means that ProcessorOrder was never invoked
mockProc.Verify(mock=> mock.ProcessorOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once);
//Assert - check that the method is returning the default view
Assert.AreEqual("Completed", result.ViewName);
//Assert- check that i am passing an invalid model to the view
Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
}
示例10: Cannot_Chechout_Empty_Cart
public void Cannot_Chechout_Empty_Cart()
{
// Arrange
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
ShippingDetails shippingDetails = new ShippingDetails();
CartController target = new CartController(null, mock.Object);
// Act
ViewResult result = target.Checkout(cart, shippingDetails);
// Assert
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never()); //Verify that order is never sent to the processor
Assert.AreEqual("", result.ViewName); // Check that method is returning same view
Assert.IsFalse(result.ViewData.ModelState.IsValid);
}
示例11: Can_checkout_and_submit_order
public void Can_checkout_and_submit_order()
{
var mock = new Mock<IOrderProcessor>();
var cart = new Cart();
cart.AddItem(new Product(), 1);
var shipping = new ShippingDetails();
var controller = new CartController(null, mock.Object);
var result = controller.Checkout(cart, shipping);
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once);
Assert.AreEqual("Completed", result.ViewName);
Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
}
示例12: Cannot_Checkout_EmptyCart
public void Cannot_Checkout_EmptyCart()
{
//arrange - Create a mock order process
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
ShippingDetails shippingDetails = new ShippingDetails();
CartController controller = new CartController(null, mock.Object );
ViewResult result = controller.Checkout(cart, shippingDetails);
mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.AtLeastOnce());
Assert.AreEqual("", result.ViewName);
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例13: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
// Arrange
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
ShippingDetails shippingDetails = new ShippingDetails();
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.AreEqual(string.Empty, result.ViewName);
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例14: Can_Checkout_And_Submit_Order
public void Can_Checkout_And_Submit_Order() {
// Arrange - create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create a cart with an item
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Act - try to checkout
ViewResult result = target.Checkout(cart, new ShippingDetails());
// Assert - check that the order has been passed on to the processor
mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
Times.Once());
// Assert - check that the method is returning the Completed view
Assert.AreEqual("Completed", result.ViewName);
// Assert - check that we are passing an valid model to the view
Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
}
示例15: Cannot_Checkout_Imvalid_ShippingDetails
public void Cannot_Checkout_Imvalid_ShippingDetails()
{
// Arrange - Create a mock order processor
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// Arrange - create a cart with an item
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
// Arrange - create an instance of the controller
CartController target = new CartController(null, mock.Object);
// Arrage - add an erro to the model
target.ModelState.AddModelError("error", "error");
// Act - try to checkout
ViewResult result = target.Checkout(cart, new ShippingDetails());
// Assert - check that the model 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);
}