Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void StoreThrowsIfTypeNotSupported()
        {
            // assemble
            ResourceListCacheManager sut  = CreateSut();
            TestResourceList         list = new TestResourceList();

            // assert
            Assert.Throws <NotSupportedException>(() =>
            {
                // act
                sut.Store(testUrl, list);
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }