Пример #1
0
            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);
            }
Пример #2
0
            public async Task TriesToGetFromCache()
            {
                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))
                .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.Once);

                VerifyNoCopyFromExternalSource();
            }