protected ValidationContext CreateValidationContext(string packageResource = null)
            {
                // Add the package
                if (packageResource != null)
                {
                    var packageId      = PackageIdentity.Id.ToLowerInvariant();
                    var packageVersion = PackageIdentity.Version.ToNormalizedString().ToLowerInvariant();
                    var relativeUrl    = $"/packages/{packageId}/{packageVersion}/{packageId}.{packageVersion}.nupkg";
                    var bytes          = File.ReadAllBytes(packageResource);

                    _mockServer.SetAction(
                        relativeUrl,
                        request => Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new ByteArrayContent(bytes)
                    }));
                }

                var httpClient = new CollectorHttpClient(_mockServer);

                // Mock V2 feed response for the package's Created/LastEdited timestamps. These timestamps must match
                // the mocked catalog entry's timestamps.
                var timestamp = PackageTimestampMetadata.CreateForExistingPackage(created: PackageCreationTime, lastEdited: PackageCreationTime);
                var timestampMetadataResource = new Mock <IPackageTimestampMetadataResource>();

                timestampMetadataResource.Setup(t => t.GetAsync(It.IsAny <ValidationContext>()))
                .ReturnsAsync(timestamp);

                return(ValidationContextStub.Create(
                           PackageIdentity,
                           _catalogEntries,
                           client: httpClient,
                           timestampMetadataResource: timestampMetadataResource.Object));
            }
Beispiel #2
0
            protected ValidationContext CreateValidationContext(IEnumerable <CatalogIndexEntry> catalogEntries = null)
            {
                catalogEntries = catalogEntries ?? new CatalogIndexEntry[0];

                var httpClient = new CollectorHttpClient(_mockServer);

                return(ValidationContextStub.Create(
                           PackageIdentity,
                           catalogEntries,
                           client: httpClient));
            }
Beispiel #3
0
            protected ValidationContext CreateValidationContext()
            {
                var timestamp = PackageTimestampMetadata.CreateForExistingPackage(created: PackageCreationTime, lastEdited: PackageCreationTime);
                var timestampMetadataResource = new Mock <IPackageTimestampMetadataResource>();

                timestampMetadataResource.Setup(t => t.GetAsync(It.IsAny <ValidationContext>())).ReturnsAsync(timestamp);

                var v2Resource = new Mock <IPackageRegistrationMetadataResource>();

                v2Resource
                .Setup(x => x.GetIndexAsync(
                           It.IsAny <PackageIdentity>(),
                           It.IsAny <NuGet.Common.ILogger>(),
                           It.IsAny <CancellationToken>()))
                .ReturnsAsync(() => DatabaseIndex);

                return(ValidationContextStub.Create(
                           PackageIdentity,
                           CatalogEntries,
                           clientHandler: MockServer,
                           timestampMetadataResource: timestampMetadataResource.Object,
                           v2Resource: v2Resource.Object));
            }
Beispiel #4
0
 private static ValidationContext CreateContext()
 {
     return(ValidationContextStub.Create());
 }