public CategoryViewModel(Category category, INavigationService navigationService) { _category = category; _navigationService = navigationService; CategoryNavigationCommand = new DelegateCommand(NavigateToCategory); _productsViewModels = new List<ProductViewModel>(); if (category != null && category.Products != null) { var position = 0; foreach (var product in category.Products) { _productsViewModels.Add(new ProductViewModel(product) { ItemPosition = position }); position++; } Products = _productsViewModels; } }
public void OnNavigatedTo_Fill_Items_And_Title() { var repository = new MockProductCatalogRepository(); var navigationService = new MockNavigationService(); var searchPaneService = new MockSearchPaneService(); repository.GetCategoryAsyncDelegate = (categoryId) => { Category category = null; if (categoryId == 1) { category = new Category { Id = categoryId, Title = "CategoryTitle" }; } return Task.FromResult(category); }; repository.GetSubcategoriesAsyncDelegate = (categoryId) => { ReadOnlyCollection<Category> categories = null; if (categoryId == 1) { categories = new ReadOnlyCollection<Category>(new List<Category> { new Category(), new Category(), new Category() }); } return Task.FromResult(categories); }; var viewModel = new GroupDetailPageViewModel(repository, navigationService, null, null, searchPaneService); viewModel.OnNavigatedTo(1, NavigationMode.New, null); Assert.IsNotNull(viewModel.Items); Assert.AreEqual(3, ((ICollection<CategoryViewModel>)viewModel.Items).Count); Assert.AreEqual("CategoryTitle", viewModel.Title); }