public GetGitIgnoreTemplates ( ) : IObservable |
||
return | IObservable |
public async Task ReturnsCollectionOnlyContainingTheNoneOptionnWhenGitIgnoreEndpointNotFound() { var apiClient = Substitute.For<IApiClient>(); apiClient.GetGitIgnoreTemplates() .Returns(Observable.Throw<string>(new NotFoundException("Not Found", HttpStatusCode.NotFound))); var cache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>()); var fetched = await modelService.GetGitIgnoreTemplates(); Assert.Equal(1, fetched.Count); Assert.Equal("None", fetched[0].Name); }
public async Task CanRetrieveAndCacheGitIgnores() { var templates = new[] { "dotnet", "peanuts", "bloomcounty" }; var apiClient = Substitute.For<IApiClient>(); apiClient.GetGitIgnoreTemplates().Returns(templates.ToObservable()); var cache = new InMemoryBlobCache(); var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>()); var fetched = await modelService.GetGitIgnoreTemplates(); Assert.Equal(4, fetched.Count); Assert.Equal("None", fetched[0].Name); Assert.Equal("dotnet", fetched[1].Name); Assert.Equal("peanuts", fetched[2].Name); Assert.Equal("bloomcounty", fetched[3].Name); var cached = await cache.GetObject<IReadOnlyList<string>>("gitignores"); Assert.Equal(3, cached.Count); Assert.Equal("dotnet", cached[0]); Assert.Equal("peanuts", cached[1]); Assert.Equal("bloomcounty", cached[2]); }
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 ReturnsCollectionOnlyContainingTheNoneOptionIfCacheReadFails() { var apiClient = Substitute.For<IApiClient>(); apiClient.GetGitIgnoreTemplates() .Returns(Observable.Throw<string>(new NotFoundException("Not Found", HttpStatusCode.NotFound))); var cache = Substitute.For<IBlobCache>(); cache.Get(Args.String) .Returns(Observable.Throw<byte[]>(new InvalidOperationException("Unknown"))); var modelService = new ModelService(apiClient, cache, Substitute.For<IAvatarProvider>()); var fetched = await modelService.GetGitIgnoreTemplates(); Assert.Equal(1, fetched.Count); Assert.Equal("None", fetched[0].Name); }