public void ShouldPerformSearchCommandMarkRetrieveSearchResults()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);
            PopularBrandsViewModel popularBrandsViewModel = new PopularBrandsViewModel();

            //act
            Task.Run(async() =>
            {
                await viewModel.LoadData();
            }).GetAwaiter().GetResult();

            popularBrandsViewModel = viewModel.PopularBrands.FirstOrDefault();

            Task.Run(async() =>
            {
                await viewModel.ExecuteOnPerformSearchCommandAsync(popularBrandsViewModel.ItemTitle);
            }).GetAwaiter().GetResult();

            var searchResults = new ObservableCollection <PopularBrandsViewModel>(
                viewModel.PopularBrandsFromServer.Where(x => x.ItemTitle.ToUpper().Contains(popularBrandsViewModel.ItemTitle.ToUpper()) ||
                                                        x.Text.ToUpper().Contains(popularBrandsViewModel.ItemTitle.ToUpper())));

            IEnumerable <PopularBrandsViewModel> differences = viewModel.PopularBrands.Except(searchResults);

            //assert
            Assert.AreEqual(searchResults.Count, viewModel.PopularBrands.Count);
            Assert.AreEqual(0, differences.Count());
        }
        public async Task LoadData(bool forceReload = false)
        {
            if (PopularBrands == null || forceReload)
            {
                PopularBrands           = new ObservableCollection <PopularBrandsViewModel>();
                PopularBrandsFromServer = new ObservableCollection <PopularBrandsViewModel>();

                var brands = await DataManager.Brands.GetBrands();

                foreach (var item in brands)
                {
                    PopularBrandsViewModel popularBrandsViewModel = new PopularBrandsViewModel()
                    {
                        ItemTitle  = item.ItemTitle,
                        Text       = item.Text,
                        Image      = item.Image,
                        IsFavorite = item.IsFavorite
                    };
                    PopularBrands.Add(popularBrandsViewModel);
                    PopularBrandsFromServer.Add(popularBrandsViewModel);
                }
            }

            if (forceReload)
            {
                IsRefreshing = false;
            }
        }
        public async Task ExecuteOnFavoriteCommandAsync(object sender)
        {
            PopularBrandsViewModel popularBrandsViewModel = (PopularBrandsViewModel)sender;

            popularBrandsViewModel.IsFavorite = !popularBrandsViewModel.IsFavorite;
            PopularBrandsFromServer[PopularBrandsFromServer.IndexOf(popularBrandsViewModel)].IsFavorite = popularBrandsViewModel.IsFavorite;
        }
        public async Task ExecuteOnDeleteCommandAsync(object sender)
        {
            PopularBrandsViewModel popularBrandsViewModel = (PopularBrandsViewModel)sender;

            PopularBrands.Remove(popularBrandsViewModel);
            PopularBrandsFromServer.Remove(popularBrandsViewModel);
        }
        public void ShouldDeleteCommandRemoveElementFromDataSources()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);
            PopularBrandsViewModel popularBrandsViewModel = new PopularBrandsViewModel();

            //act
            Task.Run(async() =>
            {
                await viewModel.LoadData();
            }).GetAwaiter().GetResult();

            popularBrandsViewModel = viewModel.PopularBrands.FirstOrDefault();

            Task.Run(async() =>
            {
                await viewModel.ExecuteOnDeleteCommandAsync(popularBrandsViewModel);
            }).GetAwaiter().GetResult();

            //assert
            Assert.IsFalse(viewModel.PopularBrands.Contains(popularBrandsViewModel));
            Assert.IsFalse(viewModel.PopularBrandsFromServer.Contains(popularBrandsViewModel));
        }
        public void ShouldFavoriteCommandMarkElementAsNotFavoriteWhenIsAlreadyFavorite()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);
            PopularBrandsViewModel popularBrandsViewModel = new PopularBrandsViewModel();

            //act
            Task.Run(async() =>
            {
                await viewModel.LoadData();
            }).GetAwaiter().GetResult();

            popularBrandsViewModel            = viewModel.PopularBrands.FirstOrDefault();
            popularBrandsViewModel.IsFavorite = true;

            Task.Run(async() =>
            {
                await viewModel.ExecuteOnFavoriteCommandAsync(popularBrandsViewModel);
            }).GetAwaiter().GetResult();

            //assert
            Assert.IsFalse(popularBrandsViewModel.IsFavorite);
            Assert.IsFalse(viewModel.PopularBrandsFromServer[viewModel.PopularBrandsFromServer.IndexOf(popularBrandsViewModel)].IsFavorite);
        }