Beispiel #1
0
            public Facts(ITestOutputHelper output)
            {
                _id = "NuGet.Versioning";
                _accessCondition = new Mock <IAccessCondition>();
                _versionList     = new VersionListData(new Dictionary <string, VersionPropertiesData>
                {
                    { "2.0.0", new VersionPropertiesData(listed: true, semVer2: false) },
                });

                _cloudBlobClient    = new Mock <ICloudBlobClient>();
                _cloudBlobContainer = new Mock <ICloudBlobContainer>();
                _cloudBlob          = new Mock <ISimpleCloudBlob>();
                _options            = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _logger             = output.GetLogger <VersionListDataClient>();
                _config             = new AzureSearchJobConfiguration
                {
                    StorageContainer = "unit-test-container",
                };

                _options
                .Setup(x => x.Value)
                .Returns(() => _config);
                _cloudBlobClient
                .Setup(x => x.GetContainerReference(It.IsAny <string>()))
                .Returns(() => _cloudBlobContainer.Object);
                _cloudBlobContainer
                .Setup(x => x.GetBlobReference(It.IsAny <string>()))
                .Returns(() => _cloudBlob.Object);
                _cloudBlob
                .Setup(x => x.UploadFromStreamAsync(It.IsAny <Stream>(), It.IsAny <AccessCondition>()))
                .Returns(Task.CompletedTask)
                .Callback <Stream, AccessCondition>((s, _) =>
                {
                    using (s)
                        using (var buffer = new MemoryStream())
                        {
                            s.CopyTo(buffer);
                            var bytes = buffer.ToArray();
                            _savedBytes.Add(bytes);
                            _savedStrings.Add(Encoding.UTF8.GetString(bytes));
                        }
                });
                _cloudBlob
                .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>()))
                .ThrowsAsync(new StorageException(
                                 new RequestResult
                {
                    HttpStatusCode = (int)HttpStatusCode.NotFound,
                },
                                 message: "Not found.",
                                 inner: null));
                _cloudBlob
                .Setup(x => x.Properties)
                .Returns(new CloudBlockBlob(new Uri("https://example/blob")).Properties);

                _target = new VersionListDataClient(
                    _cloudBlobClient.Object,
                    _options.Object,
                    _logger);
            }
Beispiel #2
0
            public BaseFacts(ITestOutputHelper output)
            {
                _serviceClient     = new Mock <ISearchServiceClientWrapper>();
                _indexesOperations = new Mock <IIndexesOperationsWrapper>();
                _options           = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _config            = new AzureSearchJobConfiguration
                {
                    SearchIndexName = "search",
                    HijackIndexName = "hijack",

                    Scoring = new AzureSearchScoringConfiguration
                    {
                        FieldWeights = new Dictionary <string, double>
                        {
                            { nameof(IndexFields.PackageId), 3.0 },
                            { nameof(IndexFields.TokenizedPackageId), 4.0 },
                        },

                        DownloadScoreBoost = 5.0,
                    }
                };
                _logger = output.GetLogger <IndexBuilder>();

                _options
                .Setup(x => x.Value)
                .Returns(() => _config);
                _serviceClient
                .Setup(x => x.Indexes)
                .Returns(() => _indexesOperations.Object);

                _target = new IndexBuilder(
                    _serviceClient.Object,
                    _options.Object,
                    _logger);
            }
Beispiel #3
0
            public BaseFacts(ITestOutputHelper output)
            {
                _cloudBlobClient    = new Mock <ICloudBlobClient>();
                _cloudBlobContainer = new Mock <ICloudBlobContainer>();
                _options            = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _config             = new AzureSearchJobConfiguration
                {
                    StorageContainer = "container-name",
                };
                _logger        = output.GetLogger <BlobContainerBuilder>();
                _retryDuration = TimeSpan.FromMilliseconds(10);

                _options
                .Setup(x => x.Value)
                .Returns(() => _config);
                _cloudBlobClient
                .Setup(x => x.GetContainerReference(It.IsAny <string>()))
                .Returns(() => _cloudBlobContainer.Object);

                _target = new BlobContainerBuilder(
                    _cloudBlobClient.Object,
                    _options.Object,
                    _logger,
                    _retryDuration);
            }
Beispiel #4
0
            public Facts()
            {
                Options = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                Config  = new AzureSearchJobConfiguration
                {
                    GalleryBaseUrl             = Data.GalleryBaseUrl,
                    FlatContainerBaseUrl       = Data.FlatContainerBaseUrl,
                    FlatContainerContainerName = Data.FlatContainerContainerName,
                };

                Options.Setup(o => o.Value).Returns(() => Config);

                Target = new BaseDocumentBuilder(Options.Object);
            }
            public BaseFacts(ITestOutputHelper output)
            {
                _output              = output;
                _options             = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _baseDocumentBuilder = new BaseDocumentBuilder(_options.Object); // We intentionally don't mock this.
                _config              = new AzureSearchJobConfiguration
                {
                    GalleryBaseUrl             = Data.GalleryBaseUrl,
                    FlatContainerBaseUrl       = Data.FlatContainerBaseUrl,
                    FlatContainerContainerName = Data.FlatContainerContainerName,
                };

                _options.Setup(o => o.Value).Returns(() => _config);

                _target = new HijackDocumentBuilder(_baseDocumentBuilder);
            }
Beispiel #6
0
            public BaseFacts(ITestOutputHelper output)
            {
                _logger = output.GetLogger <BatchPusher>();
                _searchIndexClientWrapper = new Mock <ISearchIndexClientWrapper>();
                _searchDocumentsWrapper   = new Mock <IDocumentsOperationsWrapper>();
                _hijackIndexClientWrapper = new Mock <ISearchIndexClientWrapper>();
                _hijackDocumentsWrapper   = new Mock <IDocumentsOperationsWrapper>();
                _versionListDataClient    = new Mock <IVersionListDataClient>();
                _config             = new AzureSearchJobConfiguration();
                _developmentConfig  = new AzureSearchJobDevelopmentConfiguration();
                _options            = new Mock <IOptionsSnapshot <AzureSearchJobConfiguration> >();
                _developmentOptions = new Mock <IOptionsSnapshot <AzureSearchJobDevelopmentConfiguration> >();
                _telemetryService   = new Mock <IAzureSearchTelemetryService>();

                _searchIndexClientWrapper.Setup(x => x.IndexName).Returns("search");
                _searchIndexClientWrapper.Setup(x => x.Documents).Returns(() => _searchDocumentsWrapper.Object);
                _hijackIndexClientWrapper.Setup(x => x.IndexName).Returns("hijack");
                _hijackIndexClientWrapper.Setup(x => x.Documents).Returns(() => _hijackDocumentsWrapper.Object);
                _versionListDataClient
                .Setup(x => x.TryReplaceAsync(It.IsAny <string>(), It.IsAny <VersionListData>(), It.IsAny <IAccessCondition>()))
                .ReturnsAsync(true);
                _options.Setup(x => x.Value).Returns(() => _config);
                _developmentOptions.Setup(x => x.Value).Returns(() => _developmentConfig);

                _searchBatches = new List <IndexBatch <KeyedDocument> >();
                _hijackBatches = new List <IndexBatch <KeyedDocument> >();

                _searchDocumentsWrapper
                .Setup(x => x.IndexAsync(It.IsAny <IndexBatch <KeyedDocument> >()))
                .ReturnsAsync(() => new DocumentIndexResult(new List <IndexingResult>()))
                .Callback <IndexBatch <KeyedDocument> >(b => _searchBatches.Add(b));
                _hijackDocumentsWrapper
                .Setup(x => x.IndexAsync(It.IsAny <IndexBatch <KeyedDocument> >()))
                .ReturnsAsync(() => new DocumentIndexResult(new List <IndexingResult>()))
                .Callback <IndexBatch <KeyedDocument> >(b => _hijackBatches.Add(b));

                _config.AzureSearchBatchSize            = 2;
                _config.MaxConcurrentVersionListWriters = 1;

                _searchDocumentA = IndexAction.Upload(new KeyedDocument());
                _searchDocumentB = IndexAction.Upload(new KeyedDocument());
                _searchDocumentC = IndexAction.Upload(new KeyedDocument());
                _searchDocuments = new List <IndexAction <KeyedDocument> >
                {
                    _searchDocumentA,
                    _searchDocumentB,
                    _searchDocumentC,
                };

                _hijackDocumentA = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentB = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentC = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentD = IndexAction.Upload(new KeyedDocument());
                _hijackDocumentE = IndexAction.Upload(new KeyedDocument());
                _hijackDocuments = new List <IndexAction <KeyedDocument> >
                {
                    _hijackDocumentA,
                    _hijackDocumentB,
                    _hijackDocumentC,
                    _hijackDocumentD,
                    _hijackDocumentE,
                };

                _indexActions = new IndexActions(
                    _searchDocuments,
                    _hijackDocuments,
                    new ResultAndAccessCondition <VersionListData>(
                        new VersionListData(new Dictionary <string, VersionPropertiesData>()),
                        AccessConditionWrapper.GenerateEmptyCondition()));

                _target = new BatchPusher(
                    _searchIndexClientWrapper.Object,
                    _hijackIndexClientWrapper.Object,
                    _versionListDataClient.Object,
                    _options.Object,
                    _developmentOptions.Object,
                    _telemetryService.Object,
                    _logger);
            }