Beispiel #1
0
        public async Task CanRetrieveAndCacheLicensesAsync()
        {
            var data = new[]
            {
                new LicenseMetadata("mit", null, "MIT", "foo", "https://github.com/", false),
                new LicenseMetadata("apache", null, "Apache", "foo", "https://github.com/", false)
            };

            var apiClient = Substitute.For <IApiClient>();

            apiClient.GetLicenses().Returns(data.ToObservable());
            var cache        = new InMemoryBlobCache();
            var modelService = CreateTarget(apiClient: apiClient, hostCache: cache);

            var fetched = await modelService.GetLicenses().ToList();

            Assert.That(2, Is.EqualTo(fetched.Count));
            for (int i = 0; i < data.Length; i++)
            {
                Assert.That(data[i].Name, Is.EqualTo(fetched[i].Name));
            }

            var indexKey = CacheIndex.LicensesPrefix;
            var cached   = await cache.GetObject <CacheIndex>(indexKey);

            Assert.That(2, Is.EqualTo(cached.Keys.Count));

            var items = await cache.GetObjects <LicenseCacheItem>(cached.Keys).Take(1);

            for (int i = 0; i < data.Length; i++)
            {
                Assert.That(data[i].Name, Is.EqualTo(items[indexKey + "|" + data[i].Key].Name));
            }
        }
Beispiel #2
0
        public async Task CanRetrieveAndCacheGitIgnoresAsync()
        {
            var data      = new[] { "dotnet", "peanuts", "bloomcounty" };
            var apiClient = Substitute.For <IApiClient>();

            apiClient.GetGitIgnoreTemplates().Returns(data.ToObservable());
            var cache        = new InMemoryBlobCache();
            var modelService = CreateTarget(apiClient: apiClient, hostCache: cache);

            var fetched = await modelService.GetGitIgnoreTemplates().ToList();

            Assert.That(3, Is.EqualTo(fetched.Count));
            for (int i = 0; i < data.Length; i++)
            {
                Assert.That(data[i], Is.EqualTo(fetched[i].Name));
            }

            var indexKey = CacheIndex.GitIgnoresPrefix;
            var cached   = await cache.GetObject <CacheIndex>(indexKey);

            Assert.That(3, Is.EqualTo(cached.Keys.Count));

            var items = await cache.GetObjects <GitIgnoreCacheItem>(cached.Keys).Take(1);

            for (int i = 0; i < data.Length; i++)
            {
                Assert.That(data[i], Is.EqualTo(items[indexKey + "|" + data[i]].Name));
            }
        }
        public async Task CanRetrieveAndCacheLicenses()
        {
            var data = new[]
            {
                new LicenseMetadata("mit", "MIT", new Uri("https://github.com/")),
                new LicenseMetadata("apache", "Apache", new Uri("https://github.com/"))
            };

            var apiClient = Substitute.For <IApiClient>();

            apiClient.GetLicenses().Returns(data.ToObservable());
            var cache        = new InMemoryBlobCache();
            var modelService = new ModelService(apiClient, cache, Substitute.For <IAvatarProvider>());

            var fetched = await modelService.GetLicenses().ToList();

            Assert.Equal(2, fetched.Count);
            for (int i = 0; i < data.Length; i++)
            {
                Assert.Equal(data[i].Name, fetched[i].Name);
            }

            var indexKey = CacheIndex.LicensesPrefix;
            var cached   = await cache.GetObject <CacheIndex>(indexKey);

            Assert.Equal(2, cached.Keys.Count);

            var items = await cache.GetObjects <LicenseCacheItem>(cached.Keys).Take(1);

            for (int i = 0; i < data.Length; i++)
            {
                Assert.Equal(data[i].Name, items[indexKey + "|" + data[i].Key].Name);
            }
        }
        public async Task CanRetrieveAndCacheGitIgnores()
        {
            var data = new[] { "dotnet", "peanuts", "bloomcounty" };
            var apiClient = Substitute.For<IApiClient>();
            apiClient.GetGitIgnoreTemplates().Returns(data.ToObservable());
            var cache = new InMemoryBlobCache();
            var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>());

            var fetched = await modelService.GetGitIgnoreTemplates().ToList();

            Assert.Equal(3, fetched.Count);
            for (int i = 0; i < data.Length; i++)
                Assert.Equal(data[i], fetched[i].Name);

            var indexKey = CacheIndex.GitIgnoresPrefix;
            var cached = await cache.GetObject<CacheIndex>(indexKey);
            Assert.Equal(3, cached.Keys.Count);

            var items = await cache.GetObjects<GitIgnoreCacheItem>(cached.Keys).Take(1);
            for (int i = 0; i < data.Length; i++)
                Assert.Equal(data[i], items[indexKey + "|" + data[i]].Name);
        }
        public async Task CanRetrieveAndCacheLicenses()
        {
            var data = new[]
            {
                new LicenseMetadata("mit", "MIT", new Uri("https://github.com/")),
                new LicenseMetadata("apache", "Apache", new Uri("https://github.com/"))
            };

            var apiClient = Substitute.For<IApiClient>();
            apiClient.GetLicenses().Returns(data.ToObservable());
            var cache = new InMemoryBlobCache();
            var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>());

            var fetched = await modelService.GetLicenses().ToList();

            Assert.Equal(2, fetched.Count);
            for (int i = 0; i < data.Length; i++)
                Assert.Equal(data[i].Name, fetched[i].Name);

            var indexKey = CacheIndex.LicensesPrefix;
            var cached = await cache.GetObject<CacheIndex>(indexKey);
            Assert.Equal(2, cached.Keys.Count);

            var items = await cache.GetObjects<LicenseCacheItem>(cached.Keys).Take(1);
            for (int i = 0; i < data.Length; i++)
                Assert.Equal(data[i].Name, items[indexKey + "|" + data[i].Key].Name);
        }