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 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(); }