public RegistrationValidator( IDictionary <FeedType, SourceRepository> feedToSource, ILogger <RegistrationValidator> logger) : base(feedToSource, logger) { V2Resource = feedToSource[FeedType.HttpV2].GetResource <IPackageRegistrationMetadataResource>(); V3Resource = feedToSource[FeedType.HttpV3].GetResource <IPackageRegistrationMetadataResource>(); }
public ValidationContext( PackageIdentity package, IEnumerable <CatalogIndexEntry> entries, IEnumerable <DeletionAuditEntry> deletionAuditEntries, IReadOnlyDictionary <FeedType, SourceRepository> feedToSource, CollectorHttpClient client, CancellationToken token, ILogger <ValidationContext> logger) { if (entries == null) { throw new ArgumentNullException(nameof(entries)); } if (deletionAuditEntries == null) { throw new ArgumentNullException(nameof(deletionAuditEntries)); } if (feedToSource == null) { throw new ArgumentNullException(nameof(feedToSource)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } Package = package ?? throw new ArgumentNullException(nameof(package)); Entries = entries.ToList(); DeletionAuditEntries = deletionAuditEntries.ToList(); Client = client ?? throw new ArgumentNullException(nameof(client)); CancellationToken = token; _timestampMetadataResourceV2 = feedToSource[FeedType.HttpV2].GetResource <IPackageTimestampMetadataResource>(); _v2Resource = feedToSource[FeedType.HttpV2].GetResource <IPackageRegistrationMetadataResource>(); _v3Resource = feedToSource[FeedType.HttpV3].GetResource <IPackageRegistrationMetadataResource>(); var commonLogger = logger.AsCommon(); _v2Index = new Lazy <Task <PackageRegistrationIndexMetadata> >( () => _v2Resource.GetIndexAsync(Package, commonLogger, CancellationToken)); _v3Index = new Lazy <Task <PackageRegistrationIndexMetadata> >( () => _v3Resource.GetIndexAsync(Package, commonLogger, CancellationToken)); _v2Leaf = new Lazy <Task <PackageRegistrationLeafMetadata> >( () => _v2Resource.GetLeafAsync(Package, commonLogger, CancellationToken)); _v3Leaf = new Lazy <Task <PackageRegistrationLeafMetadata> >( () => _v3Resource.GetLeafAsync(Package, commonLogger, CancellationToken)); _timestampMetadataV2 = new Lazy <Task <PackageTimestampMetadata> >( () => _timestampMetadataResourceV2.GetAsync(this)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { IPackageRegistrationMetadataResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { resource = new PackageRegistrationMetadataResourceDatabase(_queryService); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
internal static ValidationContextStub Create( PackageIdentity package = null, IEnumerable <CatalogIndexEntry> entries = null, IEnumerable <DeletionAuditEntry> deletionAuditEntries = null, Dictionary <FeedType, SourceRepository> feedToSource = null, CollectorHttpClient client = null, HttpClientHandler clientHandler = null, CancellationToken?token = null, ILogger <ValidationContext> logger = null, IPackageTimestampMetadataResource timestampMetadataResource = null, IPackageRegistrationMetadataResource v2Resource = null, IPackageRegistrationMetadataResource v3Resource = null) { if (feedToSource == null) { feedToSource = new Dictionary <FeedType, SourceRepository>(); var v2Repository = new Mock <SourceRepository>(); var v3Repository = new Mock <SourceRepository>(); feedToSource.Add(FeedType.HttpV2, v2Repository.Object); feedToSource.Add(FeedType.HttpV3, v3Repository.Object); v2Repository.Setup(x => x.GetResource <IPackageTimestampMetadataResource>()) .Returns(timestampMetadataResource ?? Mock.Of <IPackageTimestampMetadataResource>()); v2Repository.Setup(x => x.GetResource <IPackageRegistrationMetadataResource>()) .Returns(v2Resource ?? Mock.Of <IPackageRegistrationMetadataResource>()); v3Repository.Setup(x => x.GetResource <IPackageRegistrationMetadataResource>()) .Returns(v3Resource ?? Mock.Of <IPackageRegistrationMetadataResource>()); v3Repository.Setup(x => x.GetResource <HttpSourceResource>()) .Returns(new HttpSourceResource(new HttpSource( new PackageSource("https://example/v3/index.json"), () => Task.FromResult <HttpHandlerResource>(new HttpHandlerResourceV3( clientHandler ?? new HttpClientHandler(), clientHandler ?? Mock.Of <HttpMessageHandler>())), NullThrottle.Instance))); } var sourceRepositories = new ValidationSourceRepositories( feedToSource[FeedType.HttpV2], feedToSource[FeedType.HttpV3]); return(new ValidationContextStub( package ?? _packageIdentity, entries ?? Enumerable.Empty <CatalogIndexEntry>(), deletionAuditEntries ?? Enumerable.Empty <DeletionAuditEntry>(), sourceRepositories, client ?? new CollectorHttpClient(clientHandler), token ?? CancellationToken.None, logger ?? Mock.Of <ILogger <ValidationContext> >())); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { IPackageRegistrationMetadataResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV3) { var registration = await source.GetResourceAsync <RegistrationResourceV3>(token); var httpSourceResource = await source.GetResourceAsync <HttpSourceResource>(token); resource = new PackageRegistrationMetadataResourceV3(registration, httpSourceResource.HttpSource); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { IPackageRegistrationMetadataResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { var serviceDocumentResource = await source.GetResourceAsync <ODataServiceDocumentResourceV2>(token); var httpSourceResource = await source.GetResourceAsync <HttpSourceResource>(token); var feedParser = new V2FeedParser(httpSourceResource.HttpSource, serviceDocumentResource.BaseAddress, source.PackageSource.Source); resource = new PackageRegistrationMetadataResourceV2Feed(feedParser); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
private static ValidationContext CreateContext( PackageIdentity package = null, IEnumerable <CatalogIndexEntry> entries = null, IEnumerable <DeletionAuditEntry> deletionAuditEntries = null, Dictionary <FeedType, SourceRepository> feedToSource = null, CollectorHttpClient client = null, CancellationToken?token = null, ILogger <ValidationContext> logger = null, IPackageTimestampMetadataResource timestampMetadataResource = null, IPackageRegistrationMetadataResource v2Resource = null, IPackageRegistrationMetadataResource v3Resource = null) { if (feedToSource == null) { feedToSource = new Dictionary <FeedType, SourceRepository>(); var v2Repository = new Mock <SourceRepository>(); var v3Repository = new Mock <SourceRepository>(); feedToSource.Add(FeedType.HttpV2, v2Repository.Object); feedToSource.Add(FeedType.HttpV3, v3Repository.Object); v2Repository.Setup(x => x.GetResource <IPackageTimestampMetadataResource>()) .Returns(timestampMetadataResource ?? Mock.Of <IPackageTimestampMetadataResource>()); v2Repository.Setup(x => x.GetResource <IPackageRegistrationMetadataResource>()) .Returns(v2Resource ?? Mock.Of <IPackageRegistrationMetadataResource>()); v3Repository.Setup(x => x.GetResource <IPackageRegistrationMetadataResource>()) .Returns(v3Resource ?? Mock.Of <IPackageRegistrationMetadataResource>()); } var sourceRepositories = new ValidationSourceRepositories( feedToSource[FeedType.HttpV2], feedToSource[FeedType.HttpV3]); return(new ValidationContext( package ?? _packageIdentity, entries ?? Enumerable.Empty <CatalogIndexEntry>(), deletionAuditEntries ?? Enumerable.Empty <DeletionAuditEntry>(), sourceRepositories, client ?? new CollectorHttpClient(), token ?? CancellationToken.None, logger ?? Mock.Of <ILogger <ValidationContext> >())); }
public ValidationContext( PackageIdentity package, IEnumerable <CatalogIndexEntry> entries, IEnumerable <DeletionAuditEntry> deletionAuditEntries, ValidationSourceRepositories sourceRepositories, CollectorHttpClient client, CancellationToken token, ILogger <ValidationContext> logger) { if (deletionAuditEntries == null) { throw new ArgumentNullException(nameof(deletionAuditEntries)); } if (sourceRepositories == null) { throw new ArgumentNullException(nameof(sourceRepositories)); } Package = package ?? throw new ArgumentNullException(nameof(package)); Entries = entries?.ToList(); DeletionAuditEntries = deletionAuditEntries.ToList(); Client = client ?? throw new ArgumentNullException(nameof(client)); CancellationToken = token; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _commonLogger = logger.AsCommon(); _databasetimestampMetadataResource = sourceRepositories.V2.GetResource <IPackageTimestampMetadataResource>(); _databasePackageRegistrationMetadataResource = sourceRepositories.V2.GetResource <IPackageRegistrationMetadataResource>(); _v3PackageRegistrationMetadataResource = sourceRepositories.V3.GetResource <IPackageRegistrationMetadataResource>(); _httpSourceResource = sourceRepositories.V3.GetResource <HttpSourceResource>(); _databaseIndex = new Lazy <Task <PackageRegistrationIndexMetadata> >( () => _databasePackageRegistrationMetadataResource.GetIndexAsync(Package, _commonLogger, CancellationToken)); _v3Index = new Lazy <Task <PackageRegistrationIndexMetadata> >( () => _v3PackageRegistrationMetadataResource.GetIndexAsync(Package, _commonLogger, CancellationToken)); _databaseLeaf = new Lazy <Task <PackageRegistrationLeafMetadata> >( () => _databasePackageRegistrationMetadataResource.GetLeafAsync(Package, _commonLogger, CancellationToken)); _v3Leaf = new Lazy <Task <PackageRegistrationLeafMetadata> >( () => _v3PackageRegistrationMetadataResource.GetLeafAsync(Package, _commonLogger, CancellationToken)); _timestampMetadataDatabase = new Lazy <Task <PackageTimestampMetadata> >( () => _databasetimestampMetadataResource.GetAsync(this)); }
protected async Task <PackageRegistrationLeafMetadata> GetLeafAsync( IPackageRegistrationMetadataResource resource, ValidationContext context) { return(await resource.GetLeafAsync(context.Package, Logger.AsCommon(), context.CancellationToken)); }