public ProductViewModel(Product product, IShoppingCartRepository shoppingCartRepository) { _product = product; _shoppingCartRepository = shoppingCartRepository; _image = product.ImageUri; AddToCartCommand = DelegateCommand.FromAsyncHandler(AddToCart); }
public void OnNavigatedTo_Fill_Items_And_SelectedProduct() { var repository = new MockProductCatalogRepository(); var navigationService = new MockNavigationService(); repository.GetProductAsyncDelegate = (productNumber) => { Product product = null; if (productNumber == "1") { product = new Product { ProductNumber = productNumber, SubcategoryId = 1 }; } return Task.FromResult(product); }; repository.GetProductsAsyncDelegate = (subCategoryId) => { ReadOnlyCollection<Product> products = null; if (subCategoryId == 1) { products = new ReadOnlyCollection<Product>(new List<Product> { new Product(){ ProductNumber = "1", ImageUri = new Uri("http://image") }, new Product(){ ProductNumber = "2", ImageUri = new Uri("http://image") }, new Product(){ ProductNumber = "3", ImageUri = new Uri("http://image") } }); } return Task.FromResult(products); }; var target = new ItemDetailPageViewModel(repository, navigationService, new MockShoppingCartRepository(), null, null, null, new MockSearchPaneService()); target.OnNavigatedTo("1", NavigationMode.New, null); Assert.IsNotNull(target.Items); Assert.AreEqual(3, ((IReadOnlyCollection<ProductViewModel>)target.Items).Count); Assert.AreEqual(target.Items.First(), target.SelectedProduct); }
public ProductViewModel(Product product) : this(product, null) { }