public void CartContoller_RemoveItem_Added() { Mock<IProductRepository> mock = new Mock<IProductRepository>(); mock.Setup(p => p.Products).Returns(new Product[] { new Product {ProductName="P1", ProductID=1}, new Product {ProductName="P2", ProductID=2} }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); controller.AddItem(cart, 1, null); controller.AddItem(cart, 2, null); controller.RemoveItem(cart, 1, null); Assert.IsTrue(cart.Lines.Count() == 1); }
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); }