public ProtocolFixture() { var httpClient = new HttpClient(new TestDataHttpMessageHandler()); NuGetClientFactory = new NuGetClientFactory(httpClient, TestData.ServiceIndexUrl); NuGetClient = new NuGetClient(NuGetClientFactory); ServiceIndexClient = new RawServiceIndexClient(httpClient, TestData.ServiceIndexUrl); ContentClient = new RawPackageContentClient(httpClient, TestData.PackageContentUrl); MetadataClient = new RawPackageMetadataClient(httpClient, TestData.PackageMetadataUrl); SearchClient = new RawSearchClient(httpClient, TestData.SearchUrl); AutocompleteClient = new RawAutocompleteClient(httpClient, TestData.AutocompleteUrl); CatalogClient = new RawCatalogClient(httpClient, TestData.CatalogIndexUrl); }
private async Task <T> GetAsync <T>(Func <NuGetClients, T> clientFactory, CancellationToken cancellationToken) { if (_clients == null) { await _mutex.WaitAsync(cancellationToken); try { if (_clients == null) { var serviceIndexClient = new RawServiceIndexClient(_httpClient, _serviceIndexUrl); var serviceIndex = await serviceIndexClient.GetAsync(cancellationToken); var contentResourceUrl = serviceIndex.GetPackageContentResourceUrl(); var metadataResourceUrl = serviceIndex.GetPackageMetadataResourceUrl(); var catalogResourceUrl = serviceIndex.GetCatalogResourceUrl(); var searchResourceUrl = serviceIndex.GetSearchQueryResourceUrl(); var autocompleteResourceUrl = serviceIndex.GetSearchAutocompleteResourceUrl(); var contentClient = new RawPackageContentClient(_httpClient, contentResourceUrl); var metadataClient = new RawPackageMetadataClient(_httpClient, metadataResourceUrl); var searchClient = new RawSearchClient(_httpClient, searchResourceUrl); var autocompleteClient = new RawAutocompleteClient(_httpClient, autocompleteResourceUrl); var catalogClient = catalogResourceUrl == null ? new NullCatalogClient() as ICatalogClient : new RawCatalogClient(_httpClient, catalogResourceUrl); _clients = new NuGetClients { ServiceIndex = serviceIndex, PackageContentClient = contentClient, PackageMetadataClient = metadataClient, SearchClient = searchClient, AutocompleteClient = autocompleteClient, CatalogClient = catalogClient, }; } } finally { _mutex.Release(); } } // TODO: This should periodically refresh the service index response. return(clientFactory(_clients)); }
public RawAutocompleteClientTests(ProtocolFixture fixture) { _target = fixture.AutocompleteClient; }