public void ShouldRefreshCommandRefreshMainBrandListFirstTest()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);
            int originalCollectionCount = 0;

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

            viewModel.PopularBrands.Remove(viewModel.PopularBrands.FirstOrDefault());
            viewModel.PopularBrands.Remove(viewModel.PopularBrands.FirstOrDefault());
            originalCollectionCount = viewModel.PopularBrands.Count();

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

            //assert
            viewModel.PopularBrands.Count.ShouldBeGreaterThan(originalCollectionCount);
            viewModel.PopularBrandsFromServer.Count.ShouldBeGreaterThan(originalCollectionCount);
        }
        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 void ShouldReLoadItemsSetIsRefreshingEqualsToFalse()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);

            //act
            viewModel.IsRefreshing = true;
            bool reLoadData = true;

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

            //assert
            Assert.IsFalse(viewModel.IsRefreshing);
        }
        public void ShouldSelectItemSelectElementOfTheCollectionView()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);

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

            if (viewModel.PopularBrands.Count > 0)
            {
                viewModel.SelectedBrand = new PopularBrandsViewModel();
                viewModel.SelectedBrand = viewModel.PopularBrands.FirstOrDefault();
            }

            //assert
            Assert.IsNotNull(viewModel.SelectedBrand);
        }
        public void ShouldLoadDataMethodRetrieveBrandList()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);

            //act
            Task.Run(async() =>
            {
                await viewModel.LoadData();
            }).GetAwaiter().GetResult();
            IEnumerable <PopularBrandsViewModel> differences = viewModel.PopularBrands.Except(viewModel.PopularBrandsFromServer);

            //assert
            Assert.IsNotNull(viewModel.PopularBrands);
            Assert.IsNotNull(viewModel.PopularBrandsFromServer);
            viewModel.PopularBrands.Count.ShouldBeGreaterThan(0);
            viewModel.PopularBrandsFromServer.Count.ShouldBeGreaterThan(0);
            Assert.AreEqual(viewModel.PopularBrands.Count, viewModel.PopularBrandsFromServer.Count);
            Assert.AreEqual(0, differences.Count());
        }
        public void ShouldRefreshCommandRefreshMainBrandListSecondTest()
        {
            //arrange
            viewModel = new CollectionViewSampleViewModel(DataManager);
            ObservableCollection <PopularBrandsViewModel> originalData  = new ObservableCollection <PopularBrandsViewModel>();
            ObservableCollection <PopularBrandsViewModel> refreshedData = new ObservableCollection <PopularBrandsViewModel>();
            IEnumerable <PopularBrandsViewModel>          differences;

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

            if (viewModel.PopularBrands.Count > 1000)
            {
                originalData = new ObservableCollection <PopularBrandsViewModel>(viewModel.PopularBrands);

                Task.Run(async() =>
                {
                    await viewModel.ExecuteOnRefreshCommandAsync();
                }).GetAwaiter().GetResult();
                refreshedData = new ObservableCollection <PopularBrandsViewModel>(viewModel.PopularBrands);

                differences = originalData.Except(refreshedData);
            }
            else
            {
                List <PopularBrandsViewModel> list = new List <PopularBrandsViewModel>();
                list.Add(new PopularBrandsViewModel());
                IEnumerable <PopularBrandsViewModel> en = list;
                differences = en;
            }

            //assert
            Assert.AreEqual(originalData.Count, refreshedData.Count);
            differences.Count().ShouldBeGreaterThan(0);
        }
        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);
        }