public async Task DoesNotTryToCopyPrevioslyFailedIcons() { var leaf = CreateCatalogLeaf(); IconCopyResultCacheMock .Setup(c => c.Get(It.Is <Uri>(u => u.AbsoluteUri == IconUrlString))) .Returns(ExternalIconCopyResult.Fail(new Uri(IconUrlString), TimeSpan.FromMinutes(1))); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, IconUrlString, null, CancellationToken.None); DestinationStorageMock .Verify( ds => ds.CopyAsync( It.IsAny <Uri>(), It.IsAny <IStorage>(), It.IsAny <Uri>(), It.IsAny <IReadOnlyDictionary <string, string> >(), It.IsAny <CancellationToken>()), Times.Never); VerifyNoCopyFromExternalSource(); }
public async Task FallsBackToRetrievingFromExternalStoreIfCopyFromCacheFails() { var leaf = CreateCatalogLeaf(); IconCopyResultCacheMock .Setup(c => c.Get(It.Is <Uri>(u => u.AbsoluteUri == IconUrlString))) .Returns(ExternalIconCopyResult.Success(new Uri(IconUrlString), new Uri(CachedResult))); IconCacheStorageMock .Setup( ds => ds.CopyAsync( It.Is <Uri>(u => u.AbsoluteUri == CachedResult), DestinationStorageMock.Object, It.Is <Uri>(u => u.AbsoluteUri == ResolvedUriString), It.IsAny <IReadOnlyDictionary <string, string> >(), CancellationToken.None)) .Throws(new Exception("Core meltdown")); ExternalIconContentProviderMock .Setup(cp => cp.TryGetResponseAsync( It.Is <Uri>(u => u.AbsoluteUri == IconUrlString), CancellationToken.None)) .ReturnsAsync( TryGetResponseResult.Success( new HttpResponseMessage(HttpStatusCode.OK) { Content = ExternalIconContentMock.Object })); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, IconUrlString, null, CancellationToken.None); IconCacheStorageMock .Verify( ds => ds.CopyAsync( It.Is <Uri>(u => u.AbsoluteUri == CachedResult), DestinationStorageMock.Object, It.Is <Uri>(u => u.AbsoluteUri == ResolvedUriString), It.IsAny <IReadOnlyDictionary <string, string> >(), CancellationToken.None), Times.AtLeast(2)); IconProcessorMock .Verify( ip => ip.CopyIconFromExternalSourceAsync( ExternalIconStream, DestinationStorageMock.Object, "theid/3.4.2/icon", CancellationToken.None, "theid", leaf.PackageIdentity.Version.ToNormalizedString()), Times.Once); }
public async Task DeletesIconOnCachedCopyFailure() { var leaf = CreateCatalogLeaf(); IconCopyResultCacheMock .Setup(c => c.Get(It.Is <Uri>(u => u.AbsoluteUri == IconUrlString))) .Returns(ExternalIconCopyResult.Fail(new Uri(IconUrlString), TimeSpan.FromHours(1))); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, IconUrlString, null, CancellationToken.None); IconProcessorMock .Verify(ip => ip.DeleteIconAsync(DestinationStorageMock.Object, "theid/3.4.2/icon", CancellationToken.None, leaf.PackageIdentity.Id, leaf.PackageIdentity.Version.ToNormalizedString())); }
public async Task RetriesFailedCopyFromOperationsCache() { var leaf = CreateCatalogLeaf(); IconCopyResultCacheMock .Setup(c => c.Get(It.Is <Uri>(u => u.AbsoluteUri == IconUrlString))) .Returns(ExternalIconCopyResult.Success(new Uri(IconUrlString), new Uri(CachedResult))); IconCacheStorageMock .SetupSequence( ds => ds.CopyAsync( It.Is <Uri>(u => u.AbsoluteUri == CachedResult), DestinationStorageMock.Object, It.Is <Uri>(u => u.AbsoluteUri == ResolvedUriString), It.IsAny <IReadOnlyDictionary <string, string> >(), CancellationToken.None)) .Throws(new Exception("Core meltdown")) .Returns(Task.CompletedTask); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, IconUrlString, null, CancellationToken.None); IconCacheStorageMock .Verify( ds => ds.CopyAsync( It.Is <Uri>(u => u.AbsoluteUri == CachedResult), DestinationStorageMock.Object, It.Is <Uri>(u => u.AbsoluteUri == ResolvedUriString), It.IsAny <IReadOnlyDictionary <string, string> >(), CancellationToken.None), Times.AtLeast(2)); VerifyNoCopyFromExternalSource(); }