public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { //Arrange - create the mosk repo Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductID =1, Name = "P1", Category = "Apples" }, }.AsQueryable()); //Arrage - create a Cart Cart cart = new Cart(); //Arrage - 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 Can_Add_To_Cart() { //Arrange - create the mosk repo Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product {ProductID =1, Name = "P1", Category = "Apples" }, }.AsQueryable()); //Arrage - create a Cart Cart cart = new Cart(); //Arrage - create the controller CartController target = new CartController(mock.Object, null); //Act - add a product to the cart target.AddtoCart(cart, 1, null); //Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }