Exemple #1
0
            public ProduceWorkAsync(ITestOutputHelper output)
            {
                _entitiesContextFactory = new Mock <IEntitiesContextFactory>();
                _entitiesContext        = new Mock <IEntitiesContext>();
                _options = new Mock <IOptionsSnapshot <Db2AzureSearchConfiguration> >();
                _config  = new Db2AzureSearchConfiguration
                {
                    DatabaseBatchSize = 2,
                };
                _developmentOptions   = new Mock <IOptionsSnapshot <Db2AzureSearchDevelopmentConfiguration> >();
                _developmentConfig    = new Db2AzureSearchDevelopmentConfiguration();
                _logger               = output.GetLogger <NewPackageRegistrationProducer>();
                _packageRegistrations = DbSetMockFactory.Create <PackageRegistration>();
                _packages             = DbSetMockFactory.Create <Package>();
                _work  = new ConcurrentBag <NewPackageRegistration>();
                _token = CancellationToken.None;

                _auxiliaryFileClient = new Mock <IAuxiliaryFileClient>();
                _excludedPackages    = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                _auxiliaryFileClient
                .Setup(x => x.LoadExcludedPackagesAsync())
                .ReturnsAsync(() => _excludedPackages);
                _downloads = new DownloadData();
                _auxiliaryFileClient
                .Setup(x => x.LoadDownloadDataAsync())
                .ReturnsAsync(() => _downloads);
                _downloadOverrides = new Dictionary <string, long>(StringComparer.OrdinalIgnoreCase);
                _auxiliaryFileClient
                .Setup(x => x.LoadDownloadOverridesAsync())
                .ReturnsAsync(() => _downloadOverrides);

                _entitiesContextFactory
                .Setup(x => x.CreateAsync(It.IsAny <bool>()))
                .ReturnsAsync(() => _entitiesContext.Object);
                _entitiesContext
                .Setup(x => x.Set <PackageRegistration>())
                .Returns(() => _packageRegistrations);
                _entitiesContext
                .Setup(x => x.Set <Package>())
                .Returns(() => _packages);
                _options
                .Setup(x => x.Value)
                .Returns(() => _config);
                _developmentOptions
                .Setup(x => x.Value)
                .Returns(() => _developmentConfig);

                _target = new NewPackageRegistrationProducer(
                    _entitiesContextFactory.Object,
                    _auxiliaryFileClient.Object,
                    _options.Object,
                    _developmentOptions.Object,
                    _logger);
            }
Exemple #2
0
            public ProduceWorkAsync(ITestOutputHelper output)
            {
                _entitiesContextFactory = new Mock <IEntitiesContextFactory>();
                _entitiesContext        = new Mock <IEntitiesContext>();
                _options = new Mock <IOptionsSnapshot <Db2AzureSearchConfiguration> >();
                _config  = new Db2AzureSearchConfiguration
                {
                    DatabaseBatchSize         = 2,
                    EnablePopularityTransfers = true,
                };
                _developmentOptions   = new Mock <IOptionsSnapshot <Db2AzureSearchDevelopmentConfiguration> >();
                _developmentConfig    = new Db2AzureSearchDevelopmentConfiguration();
                _logger               = output.GetLogger <NewPackageRegistrationProducer>();
                _packageRegistrations = DbSetMockFactory.Create <PackageRegistration>();
                _packages             = DbSetMockFactory.Create <Package>();
                _work  = new ConcurrentBag <NewPackageRegistration>();
                _token = CancellationToken.None;

                _auxiliaryFileClient = new Mock <IAuxiliaryFileClient>();
                _excludedPackages    = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                _auxiliaryFileClient
                .Setup(x => x.LoadExcludedPackagesAsync())
                .ReturnsAsync(() => _excludedPackages);
                _downloads = new DownloadData();
                _auxiliaryFileClient
                .Setup(x => x.LoadDownloadDataAsync())
                .ReturnsAsync(() => _downloads);

                _popularityTransfers = new PopularityTransferData();
                _databaseFetcher     = new Mock <IDatabaseAuxiliaryDataFetcher>();
                _databaseFetcher
                .Setup(x => x.GetPopularityTransfersAsync())
                .ReturnsAsync(() => _popularityTransfers);

                _downloadTransferrer = new Mock <IDownloadTransferrer>();
                _transferChanges     = new SortedDictionary <string, long>(StringComparer.OrdinalIgnoreCase);
                _downloadTransferrer
                .Setup(x => x.InitializeDownloadTransfers(
                           It.IsAny <DownloadData>(),
                           It.IsAny <PopularityTransferData>()))
                .Returns(_transferChanges);

                _featureFlags = new Mock <IFeatureFlagService>();
                _featureFlags
                .Setup(x => x.IsPopularityTransferEnabled())
                .Returns(true);

                _entitiesContextFactory
                .Setup(x => x.CreateAsync(It.IsAny <bool>()))
                .ReturnsAsync(() => _entitiesContext.Object);
                _entitiesContext
                .Setup(x => x.Set <PackageRegistration>())
                .Returns(() => _packageRegistrations);
                _entitiesContext
                .Setup(x => x.Set <Package>())
                .Returns(() => _packages);
                _options
                .Setup(x => x.Value)
                .Returns(() => _config);
                _developmentOptions
                .Setup(x => x.Value)
                .Returns(() => _developmentConfig);

                _target = new NewPackageRegistrationProducer(
                    _entitiesContextFactory.Object,
                    _auxiliaryFileClient.Object,
                    _databaseFetcher.Object,
                    _downloadTransferrer.Object,
                    _featureFlags.Object,
                    _options.Object,
                    _developmentOptions.Object,
                    _logger);
            }
Exemple #3
0
        public Db2AzureSearchCommandFacts(ITestOutputHelper output)
        {
            _producer                     = new Mock <INewPackageRegistrationProducer>();
            _builder                      = new Mock <IPackageEntityIndexActionBuilder>();
            _blobContainerBuilder         = new Mock <IBlobContainerBuilder>();
            _indexBuilder                 = new Mock <IIndexBuilder>();
            _batchPusher                  = new Mock <IBatchPusher>();
            _catalogClient                = new Mock <ICatalogClient>();
            _storageFactory               = new Mock <IStorageFactory>();
            _ownerDataClient              = new Mock <IOwnerDataClient>();
            _downloadDataClient           = new Mock <IDownloadDataClient>();
            _verifiedPackagesDataClient   = new Mock <IVerifiedPackagesDataClient>();
            _popularityTransferDataClient = new Mock <IPopularityTransferDataClient>();
            _options                      = new Mock <IOptionsSnapshot <Db2AzureSearchConfiguration> >();
            _developmentOptions           = new Mock <IOptionsSnapshot <Db2AzureSearchDevelopmentConfiguration> >();
            _logger = output.GetLogger <Db2AzureSearchCommand>();

            _config = new Db2AzureSearchConfiguration
            {
                MaxConcurrentBatches = 1,
                StorageContainer     = "container-name",
            };
            _developmentConfig    = new Db2AzureSearchDevelopmentConfiguration();
            _storage              = new TestCursorStorage(new Uri("https://example/base/"));
            _initialAuxiliaryData = new InitialAuxiliaryData(
                owners: new SortedDictionary <string, SortedSet <string> >(),
                downloads: new DownloadData(),
                excludedPackages: new HashSet <string>(),
                verifiedPackages: new HashSet <string>(),
                popularityTransfers: new PopularityTransferData());

            _options
            .Setup(x => x.Value)
            .Returns(() => _config);
            _developmentOptions
            .Setup(x => x.Value)
            .Returns(() => _developmentConfig);
            _producer
            .Setup(x => x.ProduceWorkAsync(It.IsAny <ConcurrentBag <NewPackageRegistration> >(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _initialAuxiliaryData);
            _builder
            .Setup(x => x.AddNewPackageRegistration(It.IsAny <NewPackageRegistration>()))
            .Returns(() => new IndexActions(
                         new IndexAction <KeyedDocument> [0],
                         new IndexAction <KeyedDocument> [0],
                         new ResultAndAccessCondition <VersionListData>(
                             new VersionListData(new Dictionary <string, VersionPropertiesData>()),
                             AccessConditionWrapper.GenerateEmptyCondition())));
            _batchPusher.SetReturnsDefault(Task.FromResult(new BatchPusherResult()));
            _catalogClient
            .Setup(x => x.GetIndexAsync(It.IsAny <string>()))
            .ReturnsAsync(new CatalogIndex());
            _storageFactory
            .Setup(x => x.Create(It.IsAny <string>()))
            .Returns(() => _storage);
            _blobContainerBuilder
            .Setup(x => x.DeleteIfExistsAsync())
            .ReturnsAsync(true);

            _target = new Db2AzureSearchCommand(
                _producer.Object,
                _builder.Object,
                _blobContainerBuilder.Object,
                _indexBuilder.Object,
                () => _batchPusher.Object,
                _catalogClient.Object,
                _storageFactory.Object,
                _ownerDataClient.Object,
                _downloadDataClient.Object,
                _verifiedPackagesDataClient.Object,
                _popularityTransferDataClient.Object,
                _options.Object,
                _developmentOptions.Object,
                _logger);
        }