本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController.CheckOut方法的典型用法代码示例。如果您正苦于以下问题:C# CartController.CheckOut方法的具体用法?C# CartController.CheckOut怎么用?C# CartController.CheckOut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.WebUI.Controllers.CartController
的用法示例。
在下文中一共展示了CartController.CheckOut方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 - get a result back from the CartController.CheckOut() method
ViewResult result = target.CheckOut(cart, shippingDetails);
// assert - verify that processorder method is never called
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: Cant_CheckOut_if_a_Cart_is_Empty
public void Cant_CheckOut_if_a_Cart_is_Empty()
{
Cart cart = new Cart();
CartController controller = new CartController(null);
var IsValid = controller.CheckOut(cart, null).ViewData.ModelState.IsValid;
Assert.IsFalse(IsValid);
}
示例3: Cannot_Check_Out_If_Shipping_Details_Are_Invalid
public void Cannot_Check_Out_If_Shipping_Details_Are_Invalid()
{
var cart = new Cart();
cart.AddItem(new Product(), 1);
var cartController = new CartController(null, null);
cartController.ModelState.AddModelError("any key", "any error");
var result = cartController.CheckOut(cart, new ShippingDetails());
result.ShouldBeDefaultView();
}
示例4: 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 to the processor
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: Cannot_Checkout_Empty_Cart
public void Cannot_Checkout_Empty_Cart()
{
// przygotowanie - tworzenie imitacji procesora zamówień
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// przygotowanie - tworzenie pustego koszyka
CartRepository cart = new CartRepository();
// przygotowanie - tworzenie danych do wysyłki
ShippingDetails shippingDetails = new ShippingDetails();
// przygotowanie - tworzenie egzemplarza kontrolera
CartController target = new CartController(null, mock.Object);
// działanie
ViewResult result = target.CheckOut(cart, shippingDetails);
// asercje - sprawdzenie, czy zamówienie zostało przekazane do procesora
mock.Verify(m => m.ProcessOrder(It.IsAny<CartRepository>(), It.IsAny<ShippingDetails>()),
Times.Never());
// asercje - sprawdzenie, czy metoda zwraca domyślny widok
Assert.AreEqual("", result.ViewName);
// asercje - sprawdzenie, czy przekazujemy prawidłowy model do widoku
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例6: Cannot_Checkout_Invalid_Shipping_Data
public void Cannot_Checkout_Invalid_Shipping_Data()
{
// 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 a error to the model
target.ModelState.AddModelError("error","error");
// act - try to check out
ViewResult result = target.CheckOut(cart, new ShippingDetails());
// assert - verify that processorder method is never called
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);
}
示例7: 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 check out
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 i am passing an invalid model to the view
Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
}
示例8: Can_Check_Out_And_Submit_Order
public void Can_Check_Out_And_Submit_Order()
{
var mockOrderSubmitter = new Mock<IOrderSubmitter>();
var cart = new Cart();
cart.AddItem(new Product(), 1);
var shippingDetails = new ShippingDetails();
var cartController = new CartController(null, mockOrderSubmitter.Object);
var result = cartController.CheckOut(cart, shippingDetails);
mockOrderSubmitter.Verify(x => x.SubmitOrder(cart, shippingDetails));
result.ShouldBeView("Completed");
}
示例9: Cannot_Checkout_Invalid_Shipping_Details
public void Cannot_Checkout_Invalid_Shipping_Details()
{
// arrange
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");
// act
ViewResult result = target.CheckOut(cart, new ShippingDetails());
// assert
mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
Assert.AreEqual(result.ViewName, "");
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}
示例10: Can_Checkout_And_Submit_Order
public void Can_Checkout_And_Submit_Order()
{
// arrange
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
Cart cart = new Cart();
cart.AddItem(new Product(), 1);
CartController target = new CartController(null, mock.Object);
// act
ViewResult result = target.CheckOut(cart, new ShippingDetails());
//assert
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);
}
示例11: Cannot_Checkout_Invalid_ShippingDetails
public void Cannot_Checkout_Invalid_ShippingDetails()
{
// przygotowanie - tworzenie imitacji procesora zamówień
Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
// przygotowanie - tworzenie koszyka z produktem
CartRepository cart = new CartRepository();
cart.AddItem(new Product(), 1);
// przygotowanie - tworzenie egzemplarza kontrolera
CartController target = new CartController(null, mock.Object);
// przygotowanie - dodanie błędu do modelu
target.ModelState.AddModelError("error", "error");
// działanie - próba zakończenia zamówienia
ViewResult result = target.CheckOut(cart, new ShippingDetails());
// asercje - sprawdzenie, czy zamówienie zostało przekazane do procesora
mock.Verify(m => m.ProcessOrder(It.IsAny<CartRepository>(), It.IsAny<ShippingDetails>()),
Times.Never());
// asercje - sprawdzenie, czy metoda zwraca domyślny widok
Assert.AreEqual("", result.ViewName);
// asercje - sprawdzenie, czy przekazujemy prawidłowy model do widoku
Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
}