Example #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);
            }
Example #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);
            }