private V2SearchPackage ToV2SearchPackage(HijackDocument.Full result, bool semVer2) { var package = BaseMetadataDocumentToPackage(result); // The owners are not used in the hijack scenarios. package.PackageRegistration.Owners = Array.Empty <string>(); package.Listed = result.Listed.Value; package.IsLatestStable = semVer2 ? result.IsLatestStableSemVer2.Value : result.IsLatestStableSemVer1.Value; package.IsLatest = semVer2 ? result.IsLatestSemVer2.Value : result.IsLatestSemVer1.Value; return(package); }
public V2SearchResponse V2FromHijackDocument( V2SearchRequest request, string documentKey, HijackDocument.Full document, TimeSpan duration) { return(ToResponse( request, _options.Value.HijackIndexName, documentKey, document, duration, p => ToV2SearchPackage(p, request.IncludeSemVer2))); }
public BaseFacts() { _operationBuilder = new Mock <IIndexOperationBuilder>(); _searchIndex = new Mock <ISearchIndexClientWrapper>(); _searchOperations = new Mock <IDocumentsOperationsWrapper>(); _hijackIndex = new Mock <ISearchIndexClientWrapper>(); _hijackOperations = new Mock <IDocumentsOperationsWrapper>(); _responseBuilder = new Mock <ISearchResponseBuilder>(); _telemetryService = new Mock <IAzureSearchTelemetryService>(); _v2Request = new V2SearchRequest(); _v3Request = new V3SearchRequest(); _autocompleteRequest = new AutocompleteRequest(); _key = "key"; _text = "search"; _parameters = new SearchParameters(); _operation = IndexOperation.Search(_text, _parameters); _searchResult = new DocumentSearchResult <SearchDocument.Full>(); _searchDocument = new SearchDocument.Full(); _hijackResult = new DocumentSearchResult <HijackDocument.Full>(); _hijackDocument = new HijackDocument.Full(); _v2Response = new V2SearchResponse(); _v3Response = new V3SearchResponse(); _autocompleteResponse = new AutocompleteResponse(); _operationBuilder .Setup(x => x.V2SearchWithHijackIndex(It.IsAny <V2SearchRequest>())) .Returns(() => _operation); _operationBuilder .Setup(x => x.V2SearchWithSearchIndex(It.IsAny <V2SearchRequest>())) .Returns(() => _operation); _operationBuilder .Setup(x => x.V3Search(It.IsAny <V3SearchRequest>())) .Returns(() => _operation); _operationBuilder .Setup(x => x.Autocomplete(It.IsAny <AutocompleteRequest>())) .Returns(() => _operation); // Set up the search to take at least one millisecond. This allows us to test the measured duration. _searchOperations .Setup(x => x.SearchAsync <SearchDocument.Full>(It.IsAny <string>(), It.IsAny <SearchParameters>())) .ReturnsAsync(() => _searchResult) .Callback(() => Thread.Sleep(TimeSpan.FromMilliseconds(1))); _searchOperations .Setup(x => x.GetOrNullAsync <SearchDocument.Full>(It.IsAny <string>())) .ReturnsAsync(() => _searchDocument) .Callback(() => Thread.Sleep(TimeSpan.FromMilliseconds(1))); _hijackOperations .Setup(x => x.SearchAsync <HijackDocument.Full>(It.IsAny <string>(), It.IsAny <SearchParameters>())) .ReturnsAsync(() => _hijackResult) .Callback(() => Thread.Sleep(TimeSpan.FromMilliseconds(1))); _hijackOperations .Setup(x => x.GetOrNullAsync <HijackDocument.Full>(It.IsAny <string>())) .ReturnsAsync(() => _hijackDocument) .Callback(() => Thread.Sleep(TimeSpan.FromMilliseconds(1))); _responseBuilder .Setup(x => x.V2FromHijack( It.IsAny <V2SearchRequest>(), It.IsAny <string>(), It.IsAny <SearchParameters>(), It.IsAny <DocumentSearchResult <HijackDocument.Full> >(), It.IsAny <TimeSpan>())) .Returns(() => _v2Response); _responseBuilder .Setup(x => x.V2FromHijackDocument( It.IsAny <V2SearchRequest>(), It.IsAny <string>(), It.IsAny <HijackDocument.Full>(), It.IsAny <TimeSpan>())) .Returns(() => _v2Response); _responseBuilder .Setup(x => x.V2FromSearch( It.IsAny <V2SearchRequest>(), It.IsAny <string>(), It.IsAny <SearchParameters>(), It.IsAny <DocumentSearchResult <SearchDocument.Full> >(), It.IsAny <TimeSpan>())) .Returns(() => _v2Response); _responseBuilder .Setup(x => x.V2FromSearchDocument( It.IsAny <V2SearchRequest>(), It.IsAny <string>(), It.IsAny <SearchDocument.Full>(), It.IsAny <TimeSpan>())) .Returns(() => _v2Response); _responseBuilder .Setup(x => x.V3FromSearch( It.IsAny <V3SearchRequest>(), It.IsAny <string>(), It.IsAny <SearchParameters>(), It.IsAny <DocumentSearchResult <SearchDocument.Full> >(), It.IsAny <TimeSpan>())) .Returns(() => _v3Response); _responseBuilder .Setup(x => x.V3FromSearchDocument( It.IsAny <V3SearchRequest>(), It.IsAny <string>(), It.IsAny <SearchDocument.Full>(), It.IsAny <TimeSpan>())) .Returns(() => _v3Response); _responseBuilder .Setup(x => x.AutocompleteFromSearch( It.IsAny <AutocompleteRequest>(), It.IsAny <string>(), It.IsAny <SearchParameters>(), It.IsAny <DocumentSearchResult <SearchDocument.Full> >(), It.IsAny <TimeSpan>())) .Returns(() => _autocompleteResponse); _responseBuilder .Setup(x => x.EmptyV2(It.IsAny <V2SearchRequest>())) .Returns(() => _v2Response); _responseBuilder .Setup(x => x.EmptyV3(It.IsAny <V3SearchRequest>())) .Returns(() => _v3Response); _responseBuilder .Setup(x => x.EmptyAutocomplete(It.IsAny <AutocompleteRequest>())) .Returns(() => _autocompleteResponse); _searchIndex.Setup(x => x.Documents).Returns(() => _searchOperations.Object); _hijackIndex.Setup(x => x.Documents).Returns(() => _hijackOperations.Object); _target = new AzureSearchService( _operationBuilder.Object, _searchIndex.Object, _hijackIndex.Object, _responseBuilder.Object, _telemetryService.Object); }