Beispiel #1
0
        public void RemoveProductToCartWhichExist()
        {
            FakeDataStore dataStore = MusicStoreEntitiesFactory.GetEmpty();

            dataStore.GenerateAndAddGenre(1);
            dataStore.GenerateAndAddArtist(1);
            dataStore.GenerateAndAddAlbum(3, 1, 1, 10);
            ShoppingCartController controller = ControllerFactory.GetWiredUpController((s) => new ShoppingCartController(s), store: dataStore);

            controller.AddToCart(3, 5);
            RedirectToRouteResult result = controller.RemoveFromCart(0) as RedirectToRouteResult;

            controller.CartSummary();
            var cartCount = controller.ViewData["CartCount"].ToString();

            Assert.IsTrue(cartCount == "4");
        }
        public void ReturnPartialView()
        {
            // Arrange
            Mock <IShoppingCart>   shoppingCartMock   = new Mock <IShoppingCart>();
            Mock <ICartIdentifier> cartIdentifierMock = new Mock <ICartIdentifier>();

            Mock <HttpContextBase> httpContextBaseMock = new Mock <HttpContextBase>();
            var id = Guid.NewGuid().ToString();

            cartIdentifierMock.Setup(m => m.GetCardId(It.IsAny <HttpContextBase>())).Returns(id);
            shoppingCartMock.Setup(m => m.GetShoppingCart(It.IsAny <string>())).Returns(shoppingCartMock.Object);

            ShoppingCartController shoppingCartController = new ShoppingCartController(shoppingCartMock.Object, cartIdentifierMock.Object);

            //Act
            var result = shoppingCartController.CartSummary();

            // Assert
            Assert.That(result, Is.InstanceOf <PartialViewResult>());
        }
        public void CallGetShoppingCart()
        {
            // Arrange
            Mock <IShoppingCart>   shoppingCartMock   = new Mock <IShoppingCart>();
            Mock <ICartIdentifier> cartIdentifierMock = new Mock <ICartIdentifier>();

            Mock <HttpContextBase> httpContextBaseMock = new Mock <HttpContextBase>();
            var id = Guid.NewGuid().ToString();

            cartIdentifierMock.Setup(m => m.GetCardId(It.IsAny <HttpContextBase>())).Returns(id);
            shoppingCartMock.Setup(m => m.GetShoppingCart(It.IsAny <string>())).Returns(shoppingCartMock.Object);

            ShoppingCartController shoppingCartController = new ShoppingCartController(shoppingCartMock.Object, cartIdentifierMock.Object);

            //Act
            shoppingCartController.CartSummary();

            // Assert
            shoppingCartMock.Verify(m => m.GetShoppingCart(It.IsAny <string>()), Times.Once());
        }
        public void SetViewData()
        {
            // Arrange
            Mock <IShoppingCart>   shoppingCartMock   = new Mock <IShoppingCart>();
            Mock <ICartIdentifier> cartIdentifierMock = new Mock <ICartIdentifier>();

            Mock <HttpContextBase> httpContextBaseMock = new Mock <HttpContextBase>();
            var id    = Guid.NewGuid().ToString();
            var count = 10;

            cartIdentifierMock.Setup(m => m.GetCardId(It.IsAny <HttpContextBase>())).Returns(id);
            shoppingCartMock.Setup(m => m.GetShoppingCart(It.IsAny <string>())).Returns(shoppingCartMock.Object);
            shoppingCartMock.Setup(m => m.GetCount()).Returns(count);

            ShoppingCartController shoppingCartController = new ShoppingCartController(shoppingCartMock.Object, cartIdentifierMock.Object);

            //Act
            shoppingCartController.CartSummary();

            // Assert
            shoppingCartMock.Verify(m => m.GetCount(), Times.Once());
            Assert.That(shoppingCartController.ViewData["CartCount"], Is.EqualTo(count));
        }