Example #1
0
        public void GetApiResourceList_OnEmptyCache_ReturnsNull()
        {
            // assemble
            ResourceListCacheManager sut = CreateSut();

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

            // assert
            Assert.Null(cached);
        }
        /// <summary>
        /// Handles cache manipulation
        /// </summary>
        private async Task <ApiResourceList <T> > GetApiResourcePageAsync <T>(Func <string, string> urlFn, CancellationToken cancellationToken)
            where T : ApiResource
        {
            string pageUrl = urlFn(GetApiEndpointString <T>());
            ApiResourceList <T> resources = _resourceListCache.GetApiResourceList <T>(pageUrl);

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

                _resourceListCache.Store(pageUrl, resources);
            }
            return(resources);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #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);
        }
Example #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);
        }