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 void OnNavigatedTo_When_Service_Not_Available_Then_Pops_Alert() { var repository = new MockProductCatalogRepository(); var navigationService = new MockNavigationService(); var alertService = new MockAlertMessageService(); var resourceLoader = new MockResourceLoader(); bool alertCalled = false; repository.GetProductAsyncDelegate = (productNumber) => { throw new HttpRequestException(); }; repository.GetProductsAsyncDelegate = (subCategoryId) => { throw new HttpRequestException(); }; alertService.ShowAsyncDelegate = (msg, title) => { alertCalled = true; return Task.FromResult(string.Empty); }; var target = new ItemDetailPageViewModel(repository, navigationService, new MockShoppingCartRepository(), alertService, resourceLoader, null, new MockSearchPaneService()); target.OnNavigatedTo("1", NavigationMode.New, null); Assert.IsTrue(alertCalled); }