Exemple #1
0
        /// <summary>
        /// Upserts many entries into the data store.
        /// </summary>
        public virtual async Task <IEnumerable <TEntry> > UpsertMany(ApiResourceList <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));
        }
Exemple #2
0
        public async Task GetEvolutionChainPagedResourceIntegrationTest()
        {
            // assemble
            PokeApiClient client = new PokeApiClient();

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

            // assert
            Assert.True(page.Results.Any());
        }
Exemple #3
0
        public async Task GetSuperContestEffectPagedResourceIntegrationTest()
        {
            // assemble
            PokeApiClient client = new PokeApiClient();

            // act
            ApiResourceList <SuperContestEffect> page = await client.GetApiResourcePageAsync <SuperContestEffect>();

            // assert
            Assert.True(page.Results.Any());
        }
Exemple #4
0
        public async Task GetCharacteristicPagedResourceIntegrationTest()
        {
            // assemble
            PokeApiClient client = new PokeApiClient();

            // act
            ApiResourceList <Characteristic> page = await client.GetApiResourcePageAsync <Characteristic>();

            // assert
            Assert.True(page.Results.Any());
        }
Exemple #5
0
        public void GetApiResourceList_OnEmptyCache_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

            // act
            ApiResourceList <Machine> cached = sut.GetApiResourceList <Machine>(testUrl);

            // assert
            Assert.Null(cached);
        }
Exemple #6
0
        public void GetApiResourceList_WithNonStoredUri_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

            (string url, ApiResourceList <Machine> list) = CreateFakeApiResourceList <Machine>();
            sut.Store(url, list);

            // act
            ApiResourceList <Machine> cached = sut.GetApiResourceList <Machine>(testUrl);

            // assert
            Assert.Null(cached);
        }
Exemple #7
0
        public void GetApiResourceList_WithStoredUri_ReturnsResource()
        {
            // assemble
            ResourceListCacheManager sut = new ResourceListCacheManager();

            (string url, ApiResourceList <Machine> list) = CreateFakeApiResourceList <Machine>();
            sut.Store(url, list);

            // act
            ApiResourceList <Machine> cached = sut.GetApiResourceList <Machine>(url);

            // assert
            Assert.Same(list, cached);
        }
        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();
        }
Exemple #9
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);
        }
Exemple #10
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);
        }