public async Task CallsCopyEmbeddedIconFromPackageProperly(string packageId, string packageVersion, bool hasIconUrl, string expectedPath) { var leaf = CreateCatalogLeaf(packageId, packageVersion); const string iconFilename = "iconFilename"; await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, hasIconUrl?IconUrlString : null, iconFilename, CancellationToken.None); IconProcessorMock .Verify( ip => ip.CopyEmbeddedIconFromPackageAsync( It.IsAny <Stream>(), iconFilename, DestinationStorageMock.Object, expectedPath, CancellationToken.None, It.Is <string>(p => leaf.PackageIdentity.Id.Equals(p, StringComparison.OrdinalIgnoreCase)), It.Is <string>(v => leaf.PackageIdentity.Version.ToNormalizedString().Equals(v, StringComparison.OrdinalIgnoreCase))), Times.Once); }
public async Task CopiesIconFromExternalLocation(string packageId, string packageVersion, string expectedPath) { var leaf = CreateCatalogLeaf(packageId, packageVersion); 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); IconProcessorMock .Verify( ip => ip.CopyIconFromExternalSourceAsync( ExternalIconStream, DestinationStorageMock.Object, expectedPath, CancellationToken.None, packageId, leaf.PackageIdentity.Version.ToNormalizedString()), Times.Once); }
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 CallsDeleteIconProperly(string packageId, string packageVersion, string expectedPath) { var leaf = CreateCatalogLeaf(packageId, packageVersion); var destinationStorageMock = new Mock <Storage>(new Uri("https://base/storage")); await Target.ProcessPackageDeleteLeafAsync(destinationStorageMock.Object, leaf, CancellationToken.None); IconProcessorMock .Verify(ip => ip.DeleteIconAsync(destinationStorageMock.Object, expectedPath, CancellationToken.None, It.IsAny <string>(), It.IsAny <string>())); }
private void VerifyNoCopyFromExternalSource() { IconProcessorMock .Verify( ip => ip.CopyIconFromExternalSourceAsync( It.IsAny <Stream>(), It.IsAny <IStorage>(), It.IsAny <string>(), It.IsAny <CancellationToken>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
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 RetriesExternalLocationFailures() { var leaf = CreateCatalogLeaf(); ExternalIconContentProviderMock .SetupSequence(cp => cp.TryGetResponseAsync( It.Is <Uri>(u => u.AbsoluteUri == IconUrlString), CancellationToken.None)) .ReturnsAsync(TryGetResponseResult.FailCanRetry()) .ReturnsAsync( TryGetResponseResult.Success( new HttpResponseMessage(HttpStatusCode.OK) { Content = ExternalIconContentMock.Object })); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, IconUrlString, null, CancellationToken.None); ExternalIconContentProviderMock .Verify( cp => cp.TryGetResponseAsync( It.Is <Uri>(u => u.AbsoluteUri == IconUrlString), 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 DeletesIconOnCopyFailure() { var leaf = CreateCatalogLeaf(); ExternalIconContentProviderMock .Setup(cp => cp.TryGetResponseAsync( It.Is <Uri>(u => u.AbsoluteUri == IconUrlString), CancellationToken.None)) .ReturnsAsync(TryGetResponseResult.FailCannotRetry()); 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 IgnoresPackageNotFoundExceptions() { var leaf = CreateCatalogLeaf("packageid", "1.2.3"); var packageUri = new Uri("https://package/url"); var cloudBlockBlobMock = new Mock <ICloudBlockBlob>(); PackageStorageMock .Setup(ps => ps.ResolveUri(It.IsAny <string>())) .Returns(packageUri); PackageStorageMock .Setup(ps => ps.GetCloudBlockBlobReferenceAsync(packageUri)) .ReturnsAsync(cloudBlockBlobMock.Object); var exception = new StorageException(new RequestResult { HttpStatusCode = 404 }, message: "Exception!!1", inner: null); cloudBlockBlobMock .Setup(cbb => cbb.GetStreamAsync(It.IsAny <CancellationToken>())) .ThrowsAsync(exception); await Target.ProcessPackageDetailsLeafAsync( DestinationStorageMock.Object, IconCacheStorageMock.Object, leaf, null, "icon.png", CancellationToken.None); IconProcessorMock .Verify(ip => ip.CopyEmbeddedIconFromPackageAsync( It.IsAny <Stream>(), It.IsAny <string>(), It.IsAny <IStorage>(), It.IsAny <string>(), It.IsAny <CancellationToken>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }