public void Adding_Game_To_Cart_Goes_To_Cart_Screen() { // Организация - создание имитированного хранилища Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game {GameId = 1, Name = "Игра1", Category = "Кат1"}, }.AsQueryable()); // Организация - создание корзины Cart cart = new Cart(); // Организация - создание контроллера CartController controller = new CartController(mock.Object); // Действие - добавить игру в корзину RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl"); // Утверждение Assert.AreEqual(result.RouteValues["action"], "Index"); Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl"); }
public void Can_Add_To_Cart() { // Организация - создание имитированного хранилища Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game {GameId = 1, Name = "Игра1", Category = "Кат1"}, }.AsQueryable()); // Организация - создание корзины Cart cart = new Cart(); // Организация - создание контроллера CartController controller = new CartController(mock.Object); // Действие - добавить игру в корзину controller.AddToCart(cart, 1, null); // Утверждение Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToList()[0].Game.GameId, 1); }
public void Can_View_Cart_Contents() { // Организация - создание корзины Cart cart = new Cart(); // Организация - создание контроллера CartController target = new CartController(null); // Действие - вызов метода действия Index() CartIndexViewModel result = (CartIndexViewModel)target.Index(cart, "myUrl").ViewData.Model; // Утверждение Assert.AreSame(result.Cart, cart); Assert.AreEqual(result.ReturnUrl, "myUrl"); }
public void CanAddToCart() { Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game {GameId = 1, Name = "Game 1", Category = "Ctg 1"}, }.AsQueryable()); Cart cart = new Cart(); CartController controller = new CartController(mock.Object, null); controller.AddToCart(cart, 1, null); Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.ToList()[0].Game.GameId, 1); }
public void CanCheckoutAndSubmitOrder() { Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>(); Cart cart = new Cart(); cart.AddItem(new Game(), 1); CartController controller = new CartController(null, mock.Object); ViewResult result = controller.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 CannotCheckoutInvalidShippingDetails() { Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>(); Cart cart = new Cart(); cart.AddItem(new Game(), 1); CartController controller = new CartController(null, mock.Object); controller.ModelState.AddModelError("error", "error"); ViewResult result = controller.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 CannotCheckoutEmptyCart() { Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>(); Cart cart = new Cart(); ShippingDetails shippingDetails = new ShippingDetails(); CartController controller = new CartController(null, mock.Object); ViewResult result = controller.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 CanViewCartContents() { Cart cart = new Cart(); CartController target = new CartController(null, null); CartIndexViewModel result = (CartIndexViewModel)target.Index(cart, "myUrl").ViewData.Model; Assert.AreSame(result.Cart, cart); Assert.AreEqual(result.Url, "myUrl"); }
public void AddingGameToCartGoesToCartScreen() { Mock<IGameRepository> mock = new Mock<IGameRepository>(); mock.Setup(m => m.Games).Returns(new List<Game> { new Game {GameId = 1, Name = "Game 1", Category = "Ctg 1"}, }.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["Url"], "myUrl"); }