public Facts(ITestOutputHelper output)
            {
                CatalogClient          = new Mock <ICatalogClient>();
                V3TelemetryService     = new Mock <IV3TelemetryService>();
                CommitCollectorOptions = new Mock <IOptionsSnapshot <CommitCollectorConfiguration> >();
                RegistrationUpdater    = new Mock <IRegistrationUpdater>();
                Options = new Mock <IOptionsSnapshot <Catalog2RegistrationConfiguration> >();

                CommitCollectorConfiguration = new CommitCollectorConfiguration {
                    MaxConcurrentCatalogLeafDownloads = 1
                };
                CommitCollectorOptions.Setup(x => x.Value).Returns(() => CommitCollectorConfiguration);
                Configuration = new Catalog2RegistrationConfiguration {
                    MaxConcurrentIds = 1
                };
                Options.Setup(x => x.Value).Returns(() => Configuration);

                Target = new RegistrationCollectorLogic(
                    new CommitCollectorUtility(
                        CatalogClient.Object,
                        V3TelemetryService.Object,
                        CommitCollectorOptions.Object,
                        output.GetLogger <CommitCollectorUtility>()),
                    RegistrationUpdater.Object,
                    Options.Object,
                    output.GetLogger <RegistrationCollectorLogic>());
            }
            public BaseFacts(ITestOutputHelper output)
            {
                _catalogClient             = new Mock <ICatalogClient>();
                _catalogIndexActionBuilder = new Mock <ICatalogIndexActionBuilder>();
                _batchPusher        = new Mock <IBatchPusher>();
                _fixUpEvaluator     = new Mock <IDocumentFixUpEvaluator>();
                _utilityOptions     = new Mock <IOptionsSnapshot <CommitCollectorConfiguration> >();
                _collectorOptions   = new Mock <IOptionsSnapshot <Catalog2AzureSearchConfiguration> >();
                _utilityConfig      = new CommitCollectorConfiguration();
                _collectorConfig    = new Catalog2AzureSearchConfiguration();
                _telemetryService   = new Mock <IAzureSearchTelemetryService>();
                _v3TelemetryService = new Mock <IV3TelemetryService>();
                _logger             = output.GetLogger <AzureSearchCollectorLogic>();
                _utilityLogger      = output.GetLogger <CommitCollectorUtility>();

                _batchPusher.SetReturnsDefault(Task.FromResult(new BatchPusherResult()));
                _utilityOptions.Setup(x => x.Value).Returns(() => _utilityConfig);
                _utilityConfig.MaxConcurrentCatalogLeafDownloads = 1;
                _collectorOptions.Setup(x => x.Value).Returns(() => _collectorConfig);
                _collectorConfig.MaxConcurrentBatches = 1;
                _fixUpEvaluator
                .Setup(x => x.TryFixUpAsync(
                           It.IsAny <IReadOnlyList <CatalogCommitItem> >(),
                           It.IsAny <ConcurrentBag <IdAndValue <IndexActions> > >(),
                           It.IsAny <InvalidOperationException>()))
                .ReturnsAsync(() => DocumentFixUp.IsNotApplicable());

                _utility = new CommitCollectorUtility(
                    _catalogClient.Object,
                    _v3TelemetryService.Object,
                    _utilityOptions.Object,
                    _utilityLogger);

                _target = new AzureSearchCollectorLogic(
                    _catalogIndexActionBuilder.Object,
                    () => _batchPusher.Object,
                    _fixUpEvaluator.Object,
                    _utility,
                    _collectorOptions.Object,
                    _telemetryService.Object,
                    _logger);
            }
Exemple #3
0
        public AzureSearchCollectorLogicIntegrationTests(ITestOutputHelper output)
        {
            _utilityConfig = new CommitCollectorConfiguration
            {
                MaxConcurrentCatalogLeafDownloads = 1,
            };
            _utilityOptions = new Mock <IOptionsSnapshot <CommitCollectorConfiguration> >();
            _utilityOptions.Setup(x => x.Value).Returns(() => _utilityConfig);

            _config = new Catalog2AzureSearchConfiguration
            {
                MaxConcurrentBatches            = 1,
                MaxConcurrentVersionListWriters = 1,
                StorageContainer           = "integration-tests-container",
                StoragePath                = "integration-tests-path",
                RegistrationsBaseUrl       = "https://example/registrations/",
                GalleryBaseUrl             = Data.GalleryBaseUrl,
                FlatContainerBaseUrl       = Data.FlatContainerBaseUrl,
                FlatContainerContainerName = Data.FlatContainerContainerName,

                Scoring = new AzureSearchScoringConfiguration()
            };
            _options = new Mock <IOptionsSnapshot <Catalog2AzureSearchConfiguration> >();
            _options.Setup(x => x.Value).Returns(() => _config);

            _developmentConfig  = new AzureSearchJobDevelopmentConfiguration();
            _developmentOptions = new Mock <IOptionsSnapshot <AzureSearchJobDevelopmentConfiguration> >();
            _developmentOptions.Setup(x => x.Value).Returns(() => _developmentConfig);

            _telemetryClient    = new Mock <ITelemetryClient>();
            _telemetryService   = new AzureSearchTelemetryService(_telemetryClient.Object);
            _v3TelemetryService = new V3TelemetryService(_telemetryClient.Object);

            // Mock the database that is used for fetching owner information. The product code only reads
            // from the database so it is less important to have a realistic, stateful implementation.
            _entitiesContextFactory = new Mock <IEntitiesContextFactory>();
            _entitiesContext        = new Mock <IEntitiesContext>();
            _entitiesContextFactory.Setup(x => x.CreateAsync(It.IsAny <bool>())).ReturnsAsync(() => _entitiesContext.Object);
            _entitiesContext.Setup(x => x.PackageRegistrations).Returns(DbSetMockFactory.Create <PackageRegistration>());
            _ownerFetcher = new DatabaseAuxiliaryDataFetcher(
                new Mock <ISqlConnectionFactory <GalleryDbConfiguration> >().Object,
                _entitiesContextFactory.Object,
                _telemetryService,
                output.GetLogger <DatabaseAuxiliaryDataFetcher>());

            _cloudBlobClient       = new InMemoryCloudBlobClient();
            _versionListDataClient = new VersionListDataClient(
                _cloudBlobClient,
                _options.Object,
                output.GetLogger <VersionListDataClient>());
            _registrationClient = new InMemoryRegistrationClient();
            _catalogClient      = new InMemoryCatalogClient();
            _leafFetcher        = new CatalogLeafFetcher(
                _registrationClient,
                _catalogClient,
                _options.Object,
                _telemetryService,
                output.GetLogger <CatalogLeafFetcher>());
            _baseDocumentBuilder = new BaseDocumentBuilder(_options.Object);
            _search  = new SearchDocumentBuilder(_baseDocumentBuilder);
            _hijack  = new HijackDocumentBuilder(_baseDocumentBuilder);
            _builder = new CatalogIndexActionBuilder(
                _versionListDataClient,
                _leafFetcher,
                _ownerFetcher,
                _search,
                _hijack,
                output.GetLogger <CatalogIndexActionBuilder>());

            _searchIndex     = new Mock <ISearchIndexClientWrapper>();
            _searchDocuments = new InMemoryDocumentsOperations();
            _searchIndex.Setup(x => x.Documents).Returns(() => _searchDocuments);
            _hijackIndex     = new Mock <ISearchIndexClientWrapper>();
            _hijackDocuments = new InMemoryDocumentsOperations();
            _hijackIndex.Setup(x => x.Documents).Returns(() => _hijackDocuments);

            _fixUpEvaluator = new DocumentFixUpEvaluator(
                _versionListDataClient,
                _leafFetcher,
                output.GetLogger <DocumentFixUpEvaluator>());

            _commitCollectorUtility = new CommitCollectorUtility(
                _catalogClient,
                _v3TelemetryService,
                _utilityOptions.Object,
                output.GetLogger <CommitCollectorUtility>());

            _collector = new AzureSearchCollectorLogic(
                _builder,
                () => new BatchPusher(
                    _searchIndex.Object,
                    _hijackIndex.Object,
                    _versionListDataClient,
                    _options.Object,
                    _developmentOptions.Object,
                    _telemetryService,
                    output.GetLogger <BatchPusher>()),
                _fixUpEvaluator,
                _commitCollectorUtility,
                _options.Object,
                _telemetryService,
                output.GetLogger <AzureSearchCollectorLogic>());
        }