public async Task AddPackageAsync_WithStorage_WithIStorage_PopulatesStorageWithNupkgAndNuspec(string version) { var catalogToDnxStorage = new AzureStorageStub(); var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name)); var maker = new DnxMaker(catalogToDnxStorageFactory); var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version); var sourceStorage = new AzureStorageStub(); var dnxEntry = await maker.AddPackageAsync( sourceStorage, _nuspecData, _packageId, normalizedVersion, CancellationToken.None); var expectedNuspecUri = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.nuspec"); var expectedNupkgUri = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.{normalizedVersion}.nupkg"); var expectedSourceUri = new Uri(sourceStorage.BaseAddress, $"{_packageId}.{normalizedVersion}.nupkg"); var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId); Assert.Equal(expectedNuspecUri, dnxEntry.Nuspec); Assert.Equal(expectedNupkgUri, dnxEntry.Nupkg); Assert.Equal(2, catalogToDnxStorage.Content.Count); Assert.Equal(2, storageForPackage.Content.Count); Verify(catalogToDnxStorage, expectedNupkgUri, expectedSourceUri.AbsoluteUri, _expectedCacheControl, _expectedPackageContentType); Verify(catalogToDnxStorage, expectedNuspecUri, _nuspecData, _expectedCacheControl, _expectedNuspecContentType); Verify(storageForPackage, expectedNupkgUri, expectedSourceUri.AbsoluteUri, _expectedCacheControl, _expectedPackageContentType); Verify(storageForPackage, expectedNuspecUri, _nuspecData, _expectedCacheControl, _expectedNuspecContentType); }
public async Task AddPackageAsync_WithStorage_WhenEmbeddedIconPresent_SavesIcon(string iconFilename, string expectedContentType) { const string version = "1.2.3"; const string imageContent = "Test image data"; var imageDataBuffer = Encoding.UTF8.GetBytes(imageContent); var catalogToDnxStorage = new AzureStorageStub(); var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name)); var maker = new DnxMaker(catalogToDnxStorageFactory, Mock.Of <ITelemetryService>(), Mock.Of <ILogger>()); var sourceStorageMock = new Mock <IAzureStorage>(); using (var nupkgStream = await CreateNupkgStreamWithIcon(iconFilename, imageDataBuffer)) { var cloudBlobMock = new Mock <ICloudBlockBlob>(); cloudBlobMock .Setup(cb => cb.GetStreamAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(nupkgStream); sourceStorageMock .Setup(ss => ss.GetCloudBlockBlobReferenceAsync(It.IsAny <Uri>())) .ReturnsAsync(cloudBlobMock.Object); await maker.AddPackageAsync(sourceStorageMock.Object, _nuspecData, _packageId, version, iconFilename, CancellationToken.None); var expectedIconUrl = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{version}/icon"); Verify(catalogToDnxStorage, expectedIconUrl, imageContent, _expectedCacheControl, expectedContentType); } }
public async Task AddPackageAsync_WithValidVersion_PopulatesStorageWithNupkgAndNuspec(string version) { var catalogToDnxStorage = new MemoryStorage(); var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name)); var maker = new DnxMaker(catalogToDnxStorageFactory); var normalizedVersion = NuGetVersionUtility.NormalizeVersion(version); using (var nupkgStream = CreateFakePackageStream(_nupkgData)) { var dnxEntry = await maker.AddPackageAsync(nupkgStream, _nuspecData, _packageId, version, CancellationToken.None); var expectedNuspec = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.nuspec"); var expectedNupkg = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{normalizedVersion}/{_packageId}.{normalizedVersion}.nupkg"); var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId); Assert.Equal(expectedNuspec, dnxEntry.Nuspec); Assert.Equal(expectedNupkg, dnxEntry.Nupkg); Assert.Equal(2, catalogToDnxStorage.Content.Count); Assert.Equal(2, storageForPackage.Content.Count); Verify(catalogToDnxStorage, expectedNupkg, _nupkgData, _expectedCacheControl, _expectedPackageContentType); Verify(catalogToDnxStorage, expectedNuspec, _nuspecData, _expectedCacheControl, _expectedNuspecContentType); Verify(storageForPackage, expectedNupkg, _nupkgData, _expectedCacheControl, _expectedPackageContentType); Verify(storageForPackage, expectedNuspec, _nuspecData, _expectedCacheControl, _expectedNuspecContentType); } }
public async Task AddPackageAsync_WhenEmbeddedIconPresent_SavesIcon(string iconFilename, string expectedContentType) { const string version = "1.2.3"; const string imageContent = "Test image data"; var imageDataBuffer = Encoding.UTF8.GetBytes(imageContent); var catalogToDnxStorage = new MemoryStorage(); var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name)); var maker = new DnxMaker(catalogToDnxStorageFactory, Mock.Of <ITelemetryService>(), Mock.Of <ILogger>()); using (var nupkgStream = await CreateNupkgStreamWithIcon(iconFilename, imageDataBuffer)) { await maker.AddPackageAsync(nupkgStream, _nuspecData, _packageId, version, iconFilename, CancellationToken.None); var expectedIconUrl = new Uri($"{catalogToDnxStorage.BaseAddress}{_packageId}/{version}/icon"); Verify(catalogToDnxStorage, expectedIconUrl, imageContent, _expectedCacheControl, expectedContentType); } }
public async Task DeletePackageAsync_WithValidVersion_RemovesNupkgAndNuspecFromStorage(string version) { var catalogToDnxStorage = new MemoryStorage(); var catalogToDnxStorageFactory = new TestStorageFactory(name => catalogToDnxStorage.WithName(name)); var maker = new DnxMaker(catalogToDnxStorageFactory); using (var nupkgStream = CreateFakePackageStream(_nupkgData)) { var dnxEntry = await maker.AddPackageAsync(nupkgStream, _nuspecData, _packageId, version, CancellationToken.None); var storageForPackage = (MemoryStorage)catalogToDnxStorageFactory.Create(_packageId); Assert.Equal(2, catalogToDnxStorage.Content.Count); Assert.Equal(2, storageForPackage.Content.Count); await maker.DeletePackageAsync(_packageId, version, CancellationToken.None); Assert.Equal(0, catalogToDnxStorage.Content.Count); Assert.Equal(0, storageForPackage.Content.Count); } }