Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void StoreThrowsIfTypeNotSupported()
        {
            // assemble
            ResourceListCacheManager sut  = CreateSut();
            TestResourceList         list = new TestResourceList();

            // assert
            Assert.Throws <NotSupportedException>(() =>
            {
                // act
                sut.Store(testUrl, list);
            });
        }
Пример #5
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);
        }
Пример #6
0
        public void GetApiResourceList_WithStoredUri_ReturnsResource()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

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

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

            // assert
            Assert.Same(list, cached);
        }
Пример #7
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);
        }
Пример #8
0
        public void GetApiResourceList_WithNonStoredUri_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = new ResourceListCacheManager();

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

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

            // assert
            Assert.Null(cached);
        }