Пример #1
0
        public void GetNamedResourceList_OnEmptyCache_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

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

            // assert
            Assert.Null(cached);
        }
Пример #2
0
        /// <summary>
        /// Handles cache manipulation
        /// </summary>
        private async Task <NamedApiResourceList <T> > GetNamedResourcePageAsync <T>(Func <string, string> urlFn, CancellationToken cancellationToken)
            where T : NamedApiResource
        {
            string pageUrl = urlFn(GetApiEndpointString <T>());
            NamedApiResourceList <T> resources = _resourceListCache.GetNamedResourceList <T>(pageUrl);

            if (resources == null)
            {
                resources = await GetPageAsync(JsonConvert.DeserializeObject <NamedApiResourceList <T> >, cancellationToken)(pageUrl) as NamedApiResourceList <T>;

                _resourceListCache.Store(pageUrl, resources);
            }
            return(resources);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }