public ProductViewModel(ShoppingCartViewModel shoppingCartViewModel,
                                IShoppingCartRepository shoppingCartRepository,
                                IProductRepository productRepository,
                                Product product,
                                int quantity = 0)
        {
            Product  = product;
            Quantity = quantity;

            var addToCartCommand =
                new AddToCartCommand(shoppingCartRepository, productRepository, product);

            var increaseQuantityCommand =
                new ChangeQuantityCommand(ChangeQuantityCommand.Operation.Increase,
                                          shoppingCartRepository,
                                          productRepository,
                                          product);

            var decreaseQuantityCommand =
                new ChangeQuantityCommand(ChangeQuantityCommand.Operation.Decrease,
                                          shoppingCartRepository,
                                          productRepository,
                                          product);

            var removeFromCartCommand =
                new RemoveFromCartCommand(shoppingCartRepository,
                                          productRepository,
                                          product);

            AddToCartCommand = new RelayCommand(
                execute: () => {
                addToCartCommand.Execute();
                shoppingCartViewModel.Refresh();
            },
                canExecute: () => addToCartCommand.CanExecute());

            IncreaseQuantityCommand = new RelayCommand(
                execute: () => {
                increaseQuantityCommand.Execute();
                shoppingCartViewModel.Refresh();
            },
                canExecute: () => increaseQuantityCommand.CanExecute());

            DecreaseQuantityCommand = new RelayCommand(
                execute: () => {
                decreaseQuantityCommand.Execute();
                shoppingCartViewModel.Refresh();
            },
                canExecute: () => decreaseQuantityCommand.CanExecute());

            RemoveFromCartCommand = new RelayCommand(
                execute: () => {
                removeFromCartCommand.Execute();
                shoppingCartViewModel.Refresh();
            },
                canExecute: () => removeFromCartCommand.CanExecute());
        }
Exemplo n.º 2
0
        public void ReturnCustomErrorMessage_WhenUserIsNotLogged()
        {
            // Arange
            var contextMock            = new Mock <IStoreContext>();
            var writerMock             = new Mock <IWriter>();
            var readerMock             = new Mock <IReader>();
            var factoryMock            = new Mock <IModelFactory>();
            var userServiceMock        = new Mock <IUserService>();
            var loggedUserProviderMock = new Mock <ILoggedUserProvider>();

            userServiceMock.Setup(m => m.IsUserLogged()).Returns(false);

            var command = new AddToCartCommand(loggedUserProviderMock.Object, userServiceMock.Object,
                                               factoryMock.Object, contextMock.Object, writerMock.Object, readerMock.Object);

            string expectedResult = "You must Login First!";
            // Act
            var actualResul = command.Execute();

            // Assert
            Assert.AreEqual(expectedResult, actualResul);
        }
 private void MessageCenterSubmitAsync(RecorderViewModel arg1, PredictionData data)
 {
     Device.BeginInvokeOnMainThread(async() =>
     {
         if (data == null)
         {
             await Application.Current.MainPage.DisplayAlert("Error", "No data returned. Please record your command again or contact support", "Cancel", "ok");
         }
         if (data.ClassId.Trim() == "Add to cart" && data.Probability > 70.0)
         {
             AddToCartCommand.Execute(this);
         }
         else if (data.ClassId.Trim() == "Open Cart" && data.Probability > 70.0)
         {
             CardItemCommand.Execute(null);
         }
         else
         {
             await Application.Current.MainPage.DisplayAlert("Error", "Please record your command again. Recording is not clear enough", "Cancel", "ok");
         }
     });
 }