public void AddToCartTest_CanAddToCart() { var mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product{ ProductID=1,Name="P1", Category="Apples"} }.AsQueryable()); var cart = new Cart(); var 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 AddToCartTest_AddingProductToCartGoesToCartScreen() { var mock = new Mock<IProductRepository>(); mock.Setup(m => m.Products).Returns(new Product[] { new Product{ ProductID=1,Name="P1", Category="Apples"} }.AsQueryable()); var cart = new Cart(); var target = new CartController(mock.Object, null); RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Adding_Product_To_Cart_Goes_To_Cart_Screen() { // Arrange - create the mock repository Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); 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 Adding_Game_To_Cart_Goes_To_Cart_Screen() { //arrange Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game { GameId=1, Name="Game1", Category="Categ1" }, new Game {GameId=2, Name="Game2", Category="Categ2" }, new Game {GameId=3, Name="Game3", Category="Categ1" }, new Game {GameId=4, Name="Game4", Category="Categ4" }, new Game {GameId=5, Name="Game5", Category="Categ2" } }); Cart cart = new Cart(); CartController ctrl = new CartController(mock.Object, null); //Act RedirectToRouteResult result = ctrl.AddToCart(cart, 2, "myUrl"); // Утверждение Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Adding_Product_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 = "Jab" }, }.AsQueryable()); Cart cart = new Cart(); CartController target = new CartController(mock.Object,null); RedirectToRouteResult result = target.AddToCart(cart, 1, "myUrl"); Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { //arrange Mock < IGameRepository > mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game { GameId=1, Name="Game1", Category="Categ1" }, new Game {GameId=2, Name="Game2", Category="Categ2" }, new Game {GameId=3, Name="Game3", Category="Categ1" }, new Game {GameId=4, Name="Game4", Category="Categ4" }, new Game {GameId=5, Name="Game5", Category="Categ2" } }); Cart cart = new Cart(); CartController ctrl = new CartController(mock.Object, null); //Act ctrl.AddToCart(cart, 1, null); //assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToList()[0].Game.GameId, 1); }
public void Can_Add_To_Cart() { // Arrange - create the mock repository Mock<IProductsRepository> mock = new Mock<IProductsRepository>(); 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 target.AddToCart(cart, 1, null); // Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1); }