コード例 #1
0
            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();
            }
コード例 #2
0
            public async Task NoOpsIfIconFileDoesNotExist()
            {
                using (var packageStream = PrepareZippedImage("icon.xyz", new byte[] { 0xFF, 0xD8, 0xFF, 0x21, 0x17 }))
                {
                    await Target.CopyEmbeddedIconFromPackageAsync(packageStream, "icon.foo", DestinationStorageMock.Object, "somepath", CancellationToken.None, "theid", "1.2.3");
                }

                DestinationStorageMock.Verify(ds => ds.SaveAsync(It.IsAny <Uri>(), It.IsAny <StorageContent>(), It.IsAny <CancellationToken>()), Times.Never);
            }
コード例 #3
0
            public async Task DeterminesContentType(byte[] data, string expectedContentType)
            {
                using (var ms = new MemoryStream(data))
                {
                    await Target.CopyIconFromExternalSourceAsync(ms, DestinationStorageMock.Object, "somePath", CancellationToken.None, "theid", "1.2.3");
                }

                DestinationStorageMock.Verify(ds => ds.SaveAsync(
                                                  It.IsAny <Uri>(),
                                                  It.Is <StorageContent>(sc => expectedContentType == sc.ContentType),
                                                  It.IsAny <CancellationToken>()));
            }
コード例 #4
0
            public async Task ReadsAndUsesStreamData()
            {
                var data = new byte[] { 0xFF, 0xD8, 0xFF, 0xAA };

                using (var ms = new MemoryStream(data))
                {
                    await Target.CopyIconFromExternalSourceAsync(ms, DestinationStorageMock.Object, "somePath", CancellationToken.None, "theid", "1.2.3");
                }

                DestinationStorageMock.Verify(ds => ds.SaveAsync(
                                                  It.IsAny <Uri>(),
                                                  It.Is <StorageContent>(sc => SameData(data, sc)),
                                                  It.IsAny <CancellationToken>()));
            }
コード例 #5
0
            public async Task ExtractsAndSavesIcon(byte[] imageData, string expectedContentType)
            {
                const string iconFilename   = "somefile.sxt";
                var          destinationUri = new Uri("https://nuget.test/somepath");

                DestinationStorageMock
                .Setup(ds => ds.ResolveUri("somepath"))
                .Returns(destinationUri);
                using (var packageStream = PrepareZippedImage(iconFilename, imageData))
                {
                    await Target.CopyEmbeddedIconFromPackageAsync(packageStream, iconFilename, DestinationStorageMock.Object, "somepath", CancellationToken.None, "theid", "1.2.3");
                }

                DestinationStorageMock.Verify(
                    ds => ds.SaveAsync(
                        It.Is <Uri>(u => u == destinationUri),
                        It.Is <StorageContent>(sc => SameDataAndContentType(imageData, expectedContentType, sc)),
                        It.IsAny <CancellationToken>()),
                    Times.Once);
            }