Beispiel #1
0
            public async Task GetLocalPackageMetadataAsync_WhenGlobalSourceHasPackage_WithoutDeprecationMetadata()
            {
                // Arrange
                var emptyTestMetadata = PackageSearchMetadataBuilder.FromIdentity(TestPackageIdentity).Build();

                Mock.Get(_globalMetadataResource)
                .Setup(x => x.GetMetadataAsync(TestPackageIdentity.Id, true, true, It.IsAny <SourceCacheContext>(), It.IsAny <Common.ILogger>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new[] { emptyTestMetadata });

                Mock.Get(_metadataResource)
                .Setup(x => x.GetMetadataAsync(TestPackageIdentity.Id, true, false, It.IsAny <SourceCacheContext>(), It.IsAny <Common.ILogger>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new[] { emptyTestMetadata });

                // Act
                var metadata = await _target.GetLocalPackageMetadataAsync(
                    TestPackageIdentity,
                    includePrerelease : true,
                    cancellationToken : CancellationToken.None);

                // Assert
                Mock.Get(_metadataResource).Verify(
                    x => x.GetMetadataAsync(TestPackageIdentity.Id, true, false, It.IsAny <SourceCacheContext>(), It.IsAny <Common.ILogger>(), It.IsAny <CancellationToken>()),
                    Times.Once);

                Assert.Equal(new[] { "1.0.0" }, (await metadata.GetVersionsAsync()).Select(v => v.Version.ToString()).OrderBy(v => v));
                Assert.Null(await metadata.GetDeprecationMetadataAsync());
            }
            public async Task GetLocalPackageMetadataAsync_CancellationThrows()
            {
                // Arrange
                CancellationToken token = new CancellationToken(canceled: true);

                // Act
                //Note: Private method MultiSourcePackageMetadataProvider.FetchAndMergeVersionsAndDeprecationMetadataAsync
                // is called within this method, but this test does not enter into that logic.
                Task task() => _target.GetLocalPackageMetadataAsync(
                    TestPackageIdentity,
                    includePrerelease: true,
                    cancellationToken: token);

                await Assert.ThrowsAsync <OperationCanceledException>(task);
            }