// method to load PokemonList from the internet over API
        private async Task LoadFromApi()
        {
            // MAX limit currently: 807
            int maxPokemons = 807;

            NamedApiResourceList <Pokemon> allPokemons = await pokeClient.GetNamedResourcePageAsync <Pokemon>(maxPokemons, 0);

            for (int i = 1; i <= allPokemons.Results.Count; i++)
            {
                PokemonSpecies pokemonNameLang = await pokeClient.GetResourceAsync <PokemonSpecies>(i);

                for (int j = 0; j < pokemonNameLang.Names.Count; j++)
                {
                    if (pokemonNameLang.Names[j].Language.Name == Language)
                    {
                        PokeList.Add(new PokemonModel
                        {
                            Id = i,
                            PokeNameOriginal = allPokemons.Results[i - 1].Name,
                            PokeName         = pokemonNameLang.Names[j].Name,
                            PokeUrl          = allPokemons.Results[i - 1].Url
                        });
                        SearchPokeList.Add(new PokemonModel
                        {
                            Id = i,
                            PokeNameOriginal = allPokemons.Results[i - 1].Name,
                            PokeName         = pokemonNameLang.Names[j].Name,
                            PokeUrl          = allPokemons.Results[i - 1].Url
                        });
                    }
                }
                // Brings loading status to front-end in ProgressBar
                await _events.PublishOnUIThreadAsync(new LoadingBarEvent { LoadingCount = i }, CancellationToken.None);
            }
        }
Example #2
0
        private async void carregamentoInicial()
        {
            NamedApiResourceList <Pokemon> listaFull = await pokeClient.GetNamedResourcePageAsync <Pokemon>(25, page);

            //RootObject lista = await PokeApi.listaPokemons();

            lstPokemons.ItemsSource = listaFull.Results;
        }
Example #3
0
        /// <summary>
        /// Upserts many entries into the data store.
        /// </summary>
        public virtual async Task <IEnumerable <TEntry> > UpsertMany(NamedApiResourceList <TSource> resources)
        {
            var sourceType = typeof(TSource).Name;
            var entryType  = typeof(TEntry).Name;

            Logger.LogInformation($"Upserting {resources.Results.Count} {entryType} entries for {sourceType} in data store...");

            return(await UpsertMany(resources.Results));
        }
Example #4
0
        public async Task GetLocationPagedResourceIntegrationTest()
        {
            // assemble
            PokeApiClient client = new PokeApiClient();

            // act
            NamedApiResourceList <Location> page = await client.GetNamedResourcePageAsync <Location>();

            // assert
            Assert.True(page.Results.Any());
        }
Example #5
0
        public async Task GetEncounterConditionValuePagedResourceIntegrationTest()
        {
            // assemble
            PokeApiClient client = new PokeApiClient();

            // act
            NamedApiResourceList <EncounterConditionValue> page = await client.GetNamedResourcePageAsync <EncounterConditionValue>();

            // assert
            Assert.True(page.Results.Any());
        }
Example #6
0
        public void GetNamedResourceList_OnEmptyCache_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

            // act
            NamedApiResourceList <Berry> cached = sut.GetNamedResourceList <Berry>(testUrl);

            // assert
            Assert.Null(cached);
        }
Example #7
0
        public void GetNamedResourceList_WithNonStoredUri_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

            (string url, NamedApiResourceList <Berry> list) = CreateFakeNamedResourceList <Berry>();
            sut.Store(url, list);

            // act
            NamedApiResourceList <Berry> cached = sut.GetNamedResourceList <Berry>(testUrl);

            // assert
            Assert.Null(cached);
        }
Example #8
0
        public void GetNamedResourceList_WithStoredUri_ReturnsResource()
        {
            // assemble
            ResourceListCacheManager sut = new ResourceListCacheManager();

            (string url, NamedApiResourceList <Berry> list) = CreateFakeNamedResourceList <Berry>();
            sut.Store(url, list);

            // act
            NamedApiResourceList <Berry> cached = sut.GetNamedResourceList <Berry>(url);

            // assert
            Assert.Same(list, cached);
        }
        public async Task GetApiResourcePageLimitOffsetAsyncCancellation()
        {
            // assemble
            NamedApiResourceList <Berry> berryPage = new NamedApiResourceList <Berry>();

            MockHttpMessageHandler mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect("*evolution-chain?limit=1&offset=50").Respond("application/json", JsonConvert.SerializeObject(berryPage));

            PokeApiClient     client            = new PokeApiClient(mockHttp);
            CancellationToken cancellationToken = new CancellationToken(true);

            // act / assert
            await Assert.ThrowsAsync <OperationCanceledException>(async() => { await client.GetApiResourcePageAsync <EvolutionChain>(1, 50, cancellationToken); });
        }
        public async Task GetApiResourcePageLimitOffsetAsync()
        {
            // assemble
            NamedApiResourceList <Berry> berryPage = new NamedApiResourceList <Berry>();

            MockHttpMessageHandler mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect("*evolution-chain?limit=1&offset=50").Respond("application/json", JsonConvert.SerializeObject(berryPage));

            PokeApiClient client = new PokeApiClient(mockHttp);

            // act
            ApiResourceList <EvolutionChain> page = await client.GetApiResourcePageAsync <EvolutionChain>(1, 50);

            // assert
            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task GetNamedResourcePageAsync()
        {
            // assemble
            NamedApiResourceList <Berry> berryPage = new NamedApiResourceList <Berry>();

            MockHttpMessageHandler mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect("*berry").Respond("application/json", JsonConvert.SerializeObject(berryPage));

            PokeApiClient client = new PokeApiClient(mockHttp);

            // act
            NamedApiResourceList <Berry> page = await client.GetNamedResourcePageAsync <Berry>();

            // assert
            mockHttp.VerifyNoOutstandingExpectation();
        }
Example #12
0
        public void CacheIsClearedForSpecificType()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

            (string berryUri, NamedApiResourceList <Berry> berryList)  = CreateFakeNamedResourceList <Berry>();
            (string machineUri, ApiResourceList <Machine> machineList) = CreateFakeApiResourceList <Machine>();
            sut.Store(berryUri, berryList);
            sut.Store(machineUri, machineList);

            // act
            sut.Clear <Berry>();

            // assert
            NamedApiResourceList <Berry> cachedBerryList   = sut.GetNamedResourceList <Berry>(berryUri);
            ApiResourceList <Machine>    cachedMachineList = sut.GetApiResourceList <Machine>(machineUri);

            Assert.Null(cachedBerryList);
            Assert.NotNull(cachedMachineList);
        }
Example #13
0
        public void AllCacheIsCleared()
        {
            // assemble
            ResourceListCacheManager sut = new ResourceListCacheManager();

            (string berryUri, NamedApiResourceList <Berry> berryList)  = CreateFakeNamedResourceList <Berry>();
            (string machineUri, ApiResourceList <Machine> machineList) = CreateFakeApiResourceList <Machine>();
            sut.Store(berryUri, berryList);
            sut.Store(machineUri, machineList);

            // act
            sut.ClearAll();

            // assert
            NamedApiResourceList <Berry> cacheddBerryList  = sut.GetNamedResourceList <Berry>(berryUri);
            ApiResourceList <Machine>    cachedMachineList = sut.GetApiResourceList <Machine>(machineUri);

            Assert.Null(cacheddBerryList);
            Assert.Null(cachedMachineList);
        }