public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange // - Create the mock repository Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product { ProductID = 1, Name = "P1", Category = "Apples" } }.AsQueryable()); // Arrange // - Create a Cart Cart cart = new Cart(); // Arrange // - Create the controller CartController target = new CartController(mock.Object, null); // Act // - Add a product to the cart RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); // Assert Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
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); }
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); }
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); }
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); }
public void Cannot_Check_Out_If_Cart_Is_Empty() { var emptyCart = new Cart(); var shippingDetails = new ShippingDetails(); var result = new CartController(null, null).CheckOut(emptyCart, shippingDetails); result.ShouldBeDefaultView(); }
public void Adding_Products_To_Cart_Goes_To_Cart_Screen() { var productsArray = products.Products.ToArray(); Cart cart = new Cart(); CartController target = new CartController(products, orderProcessor); RedirectToRouteResult result = target.AddToCart(cart, 1, "testUrl"); Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); }
public void Cannot_Check_Out_If_Cart_Is_Empty() { // Arrange/act: When a user tries to check out with an empty cart var emptyCart = new Cart(); var shippingDetails = new ShippingDetails(); var result = new CartController(null, null).CheckOut(emptyCart, shippingDetails); // Assert result.ShouldBeDefaultView(); }
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); }
public void Can_view_cart_contents() { var cart = new Cart(); var controller = new CartController(null, null); var result = (CartIndexViewModel)controller.Index(cart, "myurl").ViewData.Model; Assert.AreSame(cart, result.Cart); Assert.AreEqual("myurl", result.ReturnUrl); }
public void Adding_product_goes_to_cart_screen() { var cart = new Cart(); var controller = new CartController(CreateRepositoryMock().Object, null); var result = controller.AddToCart(cart, 2, "my url"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "my url"); }
public void Can_View_Cart_Content() { Cart cart = new Cart(); CartController target = new CartController(null, null); CartIndexViewModel res = (CartIndexViewModel)target.Index(cart, "MyUrl").ViewData.Model; Assert.AreSame(res.Cart, cart); Assert.AreEqual(res.ReturnUrl, "MyUrl"); }
public void Can_Add_To_Cart() { var productsArray = products.Products.ToArray(); Cart cart = new Cart(); CartController target = new CartController(products, orderProcessor); target.AddToCart(cart, 1, "testUrl"); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Can_add_to_cart() { var mockRepository = CreateRepositoryMock(); var controller = new CartController(mockRepository.Object, null); var cart = new Cart(); controller.AddToCart(cart, 1, null); Assert.AreEqual(1, cart.Lines.Count()); Assert.AreEqual(cart.Lines.ElementAt(0).Product.ProductID, 1); }
public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen() { var mockProductsRepository = UnitTestHelpers.MockProductsRepository( new Product { ProductId = 1 } ); var cartController = new CartController(mockProductsRepository, null); var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl"); result.ShouldBeRedirectionTo(new {action = "Index", returnUrl = "someReturnUrl"}); }
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(); }
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); }
public void Can_View_Cart_Contents() { // Arrange - create a Cart Cart cart = new Cart(); // Arrange - create the controller CartController target = new CartController(null, null); // Act - call the Index action method CartIndexViewModel result = (CartIndexViewModel)target.Index(cart, "myUrl").ViewData.Model; // Assert Assert.AreSame(result.Cart, cart); Assert.AreEqual(result.ReturnUrl, "myUrl"); }
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); }
public void CartController_AddItem_Added() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(p => p.Products).Returns(new Product[] { new Product {ProductName="P1", Category=new Category{CategoryID=1}, ProductID=1, UnitPrice=10m}, new Product {ProductName="P2", Category=new Category{CategoryID=2}, ProductID=2, UnitPrice=10m} }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); var result = controller.AddItem(cart, 1, "/cart/index"); CartLine [] lines = cart.Lines.ToArray(); Assert.AreEqual("P1", lines[0].Product.ProductName); }
public void AddingProductToCartGoesToCartScreen() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new[] {new Product {ProductID = 1, Name = "P1", Category = "Apples"}} ); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); var result = target.AddToCart(cart, 1, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[]{ new Product{ProductID = 1, Name = "P1",Category = "Apples"}, }.AsQueryable()); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); target.AddToCart(cart, 1, null); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }
public void Adding_Prod_To_Cart_Goes_To_Cart_Screen() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[]{ new Product{ProductID = 1, Name = "P1",Category = "Apples"}, }.AsQueryable()); Cart cart = new Cart(); CartController target = new CartController(mock.Object, null); RedirectToRouteResult res = target.AddToCart(cart, 2, "MyUrl"); Assert.AreEqual(res.RouteValues["action"], "Index"); Assert.AreEqual(res.RouteValues["returnUrl"], "MyUrl"); }
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); }
public void Can_Add_Product_To_Cart() { var mockProductsRepository = UnitTestHelpers.MockProductsRepository( new Product {ProductId = 123} , new Product {ProductId = 456} ); var cartController = new CartController(mockProductsRepository, null); var cart = new Cart(); cartController.AddToCart(cart, 456, null); cart.Lines.Count.ShouldEqual(1); cart.Lines[0].Product.ProductId.ShouldEqual(456); }
public void Can_View_Cart_Contents() { //arrange create a cart Cart cart = new Cart(); // arrange create the controller CartController controller = new CartController(null, null); // act call the index action method var result = (CartIndexViewModel)controller.Index(cart, "myUrl").ViewData.Model; // assert Assert.AreEqual(result.Cart, cart); Assert.AreEqual(result.ReturnUrl, "myUrl"); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { //Arrange Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(products.AsQueryable()); CartController target = new CartController(mock.Object, null); // TODO: Initialize to an appropriate value Cart cart = new Cart(); // TODO: Initialize to an appropriate value //Act RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); //Assert Assert.AreEqual("Index", result.RouteValues["Action"]); Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]); }
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); }
public void AddingProductToCartScreen() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product(){Id = 1, Name = "P1", Category = "Jabłka"} }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Remove_From_Cart() { var productsArray = products.Products.ToArray(); Cart cart = new Cart(); cart.AddItem(productsArray[0], 1); cart.AddItem(productsArray[1], 1); cart.AddItem(productsArray[2], 1); CartController target = new CartController(products, orderProcessor); RedirectToRouteResult result = (RedirectToRouteResult)target.RemoveFromCart(cart, productsArray[1].ProductID, "testUrl"); Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(cart.Lines.ToArray()[0].Product, productsArray[0]); Assert.AreEqual(cart.Lines.ToArray()[1].Product, productsArray[2]); }