< Summary

Class:Azure.Search.Documents.DataSourcesRestClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\DataSourcesRestClient.cs
Covered lines:163
Uncovered lines:29
Coverable lines:192
Total lines:447
Line coverage:84.8% (163 of 192)
Covered branches:37
Total branches:68
Branch coverage:54.4% (37 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-81.82%50%
CreateCreateOrUpdateRequest(...)-91.3%66.67%
CreateOrUpdateAsync()-75%50%
CreateOrUpdate(...)-75%50%
CreateDeleteRequest(...)-88.89%66.67%
DeleteAsync()-75%50%
Delete(...)-75%50%
CreateGetRequest(...)-92.86%50%
GetAsync()-80%50%
Get(...)-80%50%
CreateListRequest(...)-92.86%75%
ListAsync()-87.5%50%
List(...)-87.5%50%
CreateCreateRequest(...)-93.75%50%
CreateAsync()-80%50%
Create(...)-80%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\DataSourcesRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Search.Documents.Indexes.Models;
 16
 17namespace Azure.Search.Documents
 18{
 19    internal partial class DataSourcesRestClient
 20    {
 21        private string endpoint;
 22        private Guid? xMsClientRequestId;
 23        private string apiVersion;
 24        private ClientDiagnostics _clientDiagnostics;
 25        private HttpPipeline _pipeline;
 26
 27        /// <summary> Initializes a new instance of DataSourcesRestClient. </summary>
 28        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 29        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 30        /// <param name="endpoint"> The endpoint URL of the search service. </param>
 31        /// <param name="xMsClientRequestId"> The tracking ID sent with the request to help with debugging. </param>
 32        /// <param name="apiVersion"> Api Version. </param>
 33        /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="apiVersion"/> is nul
 534        public DataSourcesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? 
 35        {
 536            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 540            if (apiVersion == null)
 41            {
 042                throw new ArgumentNullException(nameof(apiVersion));
 43            }
 44
 545            this.endpoint = endpoint;
 546            this.xMsClientRequestId = xMsClientRequestId;
 547            this.apiVersion = apiVersion;
 548            _clientDiagnostics = clientDiagnostics;
 549            _pipeline = pipeline;
 550        }
 51
 52        internal HttpMessage CreateCreateOrUpdateRequest(string dataSourceName, SearchIndexerDataSourceConnection dataSo
 53        {
 254            var message = _pipeline.CreateMessage();
 255            var request = message.Request;
 256            request.Method = RequestMethod.Put;
 257            var uri = new RawRequestUriBuilder();
 258            uri.AppendRaw(endpoint, false);
 259            uri.AppendPath("/datasources('", false);
 260            uri.AppendPath(dataSourceName, true);
 261            uri.AppendPath("')", false);
 262            uri.AppendQuery("api-version", apiVersion, true);
 263            request.Uri = uri;
 264            if (xMsClientRequestId != null)
 65            {
 066                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 67            }
 268            if (ifMatch != null)
 69            {
 270                request.Headers.Add("If-Match", ifMatch);
 71            }
 272            if (ifNoneMatch != null)
 73            {
 074                request.Headers.Add("If-None-Match", ifNoneMatch);
 75            }
 276            request.Headers.Add("Prefer", "return=representation");
 277            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 278            request.Headers.Add("Content-Type", "application/json");
 279            var content = new Utf8JsonRequestContent();
 280            content.JsonWriter.WriteObjectValue(dataSource);
 281            request.Content = content;
 282            return message;
 83        }
 84
 85        /// <summary> Creates a new datasource or updates a datasource if it already exists. </summary>
 86        /// <param name="dataSourceName"> The name of the datasource to create or update. </param>
 87        /// <param name="dataSource"> The definition of the datasource to create or update. </param>
 88        /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t
 89        /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the 
 90        /// <param name="cancellationToken"> The cancellation token to use. </param>
 91        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> or <paramref name="dataSource"/> 
 92        public async Task<Response<SearchIndexerDataSourceConnection>> CreateOrUpdateAsync(string dataSourceName, Search
 93        {
 194            if (dataSourceName == null)
 95            {
 096                throw new ArgumentNullException(nameof(dataSourceName));
 97            }
 198            if (dataSource == null)
 99            {
 0100                throw new ArgumentNullException(nameof(dataSource));
 101            }
 102
 1103            using var message = CreateCreateOrUpdateRequest(dataSourceName, dataSource, ifMatch, ifNoneMatch);
 1104            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1105            switch (message.Response.Status)
 106            {
 107                case 200:
 108                case 201:
 109                    {
 110                        SearchIndexerDataSourceConnection value = default;
 1111                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1112                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 1113                        return Response.FromValue(value, message.Response);
 114                    }
 115                default:
 0116                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 117            }
 1118        }
 119
 120        /// <summary> Creates a new datasource or updates a datasource if it already exists. </summary>
 121        /// <param name="dataSourceName"> The name of the datasource to create or update. </param>
 122        /// <param name="dataSource"> The definition of the datasource to create or update. </param>
 123        /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t
 124        /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the 
 125        /// <param name="cancellationToken"> The cancellation token to use. </param>
 126        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> or <paramref name="dataSource"/> 
 127        public Response<SearchIndexerDataSourceConnection> CreateOrUpdate(string dataSourceName, SearchIndexerDataSource
 128        {
 1129            if (dataSourceName == null)
 130            {
 0131                throw new ArgumentNullException(nameof(dataSourceName));
 132            }
 1133            if (dataSource == null)
 134            {
 0135                throw new ArgumentNullException(nameof(dataSource));
 136            }
 137
 1138            using var message = CreateCreateOrUpdateRequest(dataSourceName, dataSource, ifMatch, ifNoneMatch);
 1139            _pipeline.Send(message, cancellationToken);
 1140            switch (message.Response.Status)
 141            {
 142                case 200:
 143                case 201:
 144                    {
 145                        SearchIndexerDataSourceConnection value = default;
 1146                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1147                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 1148                        return Response.FromValue(value, message.Response);
 149                    }
 150                default:
 0151                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 152            }
 1153        }
 154
 155        internal HttpMessage CreateDeleteRequest(string dataSourceName, string ifMatch, string ifNoneMatch)
 156        {
 3157            var message = _pipeline.CreateMessage();
 3158            var request = message.Request;
 3159            request.Method = RequestMethod.Delete;
 3160            var uri = new RawRequestUriBuilder();
 3161            uri.AppendRaw(endpoint, false);
 3162            uri.AppendPath("/datasources('", false);
 3163            uri.AppendPath(dataSourceName, true);
 3164            uri.AppendPath("')", false);
 3165            uri.AppendQuery("api-version", apiVersion, true);
 3166            request.Uri = uri;
 3167            if (xMsClientRequestId != null)
 168            {
 0169                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 170            }
 3171            if (ifMatch != null)
 172            {
 2173                request.Headers.Add("If-Match", ifMatch);
 174            }
 3175            if (ifNoneMatch != null)
 176            {
 0177                request.Headers.Add("If-None-Match", ifNoneMatch);
 178            }
 3179            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 3180            return message;
 181        }
 182
 183        /// <summary> Deletes a datasource. </summary>
 184        /// <param name="dataSourceName"> The name of the datasource to delete. </param>
 185        /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t
 186        /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the 
 187        /// <param name="cancellationToken"> The cancellation token to use. </param>
 188        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> is null. </exception>
 189        public async Task<Response> DeleteAsync(string dataSourceName, string ifMatch = null, string ifNoneMatch = null,
 190        {
 2191            if (dataSourceName == null)
 192            {
 0193                throw new ArgumentNullException(nameof(dataSourceName));
 194            }
 195
 2196            using var message = CreateDeleteRequest(dataSourceName, ifMatch, ifNoneMatch);
 2197            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2198            switch (message.Response.Status)
 199            {
 200                case 204:
 201                case 404:
 2202                    return message.Response;
 203                default:
 0204                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 205            }
 2206        }
 207
 208        /// <summary> Deletes a datasource. </summary>
 209        /// <param name="dataSourceName"> The name of the datasource to delete. </param>
 210        /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t
 211        /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the 
 212        /// <param name="cancellationToken"> The cancellation token to use. </param>
 213        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> is null. </exception>
 214        public Response Delete(string dataSourceName, string ifMatch = null, string ifNoneMatch = null, CancellationToke
 215        {
 1216            if (dataSourceName == null)
 217            {
 0218                throw new ArgumentNullException(nameof(dataSourceName));
 219            }
 220
 1221            using var message = CreateDeleteRequest(dataSourceName, ifMatch, ifNoneMatch);
 1222            _pipeline.Send(message, cancellationToken);
 1223            switch (message.Response.Status)
 224            {
 225                case 204:
 226                case 404:
 1227                    return message.Response;
 228                default:
 0229                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 230            }
 1231        }
 232
 233        internal HttpMessage CreateGetRequest(string dataSourceName)
 234        {
 2235            var message = _pipeline.CreateMessage();
 2236            var request = message.Request;
 2237            request.Method = RequestMethod.Get;
 2238            var uri = new RawRequestUriBuilder();
 2239            uri.AppendRaw(endpoint, false);
 2240            uri.AppendPath("/datasources('", false);
 2241            uri.AppendPath(dataSourceName, true);
 2242            uri.AppendPath("')", false);
 2243            uri.AppendQuery("api-version", apiVersion, true);
 2244            request.Uri = uri;
 2245            if (xMsClientRequestId != null)
 246            {
 0247                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 248            }
 2249            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2250            return message;
 251        }
 252
 253        /// <summary> Retrieves a datasource definition. </summary>
 254        /// <param name="dataSourceName"> The name of the datasource to retrieve. </param>
 255        /// <param name="cancellationToken"> The cancellation token to use. </param>
 256        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> is null. </exception>
 257        public async Task<Response<SearchIndexerDataSourceConnection>> GetAsync(string dataSourceName, CancellationToken
 258        {
 1259            if (dataSourceName == null)
 260            {
 0261                throw new ArgumentNullException(nameof(dataSourceName));
 262            }
 263
 1264            using var message = CreateGetRequest(dataSourceName);
 1265            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1266            switch (message.Response.Status)
 267            {
 268                case 200:
 269                    {
 270                        SearchIndexerDataSourceConnection value = default;
 1271                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1272                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 1273                        return Response.FromValue(value, message.Response);
 274                    }
 275                default:
 0276                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 277            }
 1278        }
 279
 280        /// <summary> Retrieves a datasource definition. </summary>
 281        /// <param name="dataSourceName"> The name of the datasource to retrieve. </param>
 282        /// <param name="cancellationToken"> The cancellation token to use. </param>
 283        /// <exception cref="ArgumentNullException"> <paramref name="dataSourceName"/> is null. </exception>
 284        public Response<SearchIndexerDataSourceConnection> Get(string dataSourceName, CancellationToken cancellationToke
 285        {
 1286            if (dataSourceName == null)
 287            {
 0288                throw new ArgumentNullException(nameof(dataSourceName));
 289            }
 290
 1291            using var message = CreateGetRequest(dataSourceName);
 1292            _pipeline.Send(message, cancellationToken);
 1293            switch (message.Response.Status)
 294            {
 295                case 200:
 296                    {
 297                        SearchIndexerDataSourceConnection value = default;
 1298                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1299                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 1300                        return Response.FromValue(value, message.Response);
 301                    }
 302                default:
 0303                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 304            }
 1305        }
 306
 307        internal HttpMessage CreateListRequest(string select)
 308        {
 2309            var message = _pipeline.CreateMessage();
 2310            var request = message.Request;
 2311            request.Method = RequestMethod.Get;
 2312            var uri = new RawRequestUriBuilder();
 2313            uri.AppendRaw(endpoint, false);
 2314            uri.AppendPath("/datasources", false);
 2315            if (select != null)
 316            {
 2317                uri.AppendQuery("$select", select, true);
 318            }
 2319            uri.AppendQuery("api-version", apiVersion, true);
 2320            request.Uri = uri;
 2321            if (xMsClientRequestId != null)
 322            {
 0323                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 324            }
 2325            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2326            return message;
 327        }
 328
 329        /// <summary> Lists all datasources available for a search service. </summary>
 330        /// <param name="select"> Selects which top-level properties of the data sources to retrieve. Specified as a com
 331        /// <param name="cancellationToken"> The cancellation token to use. </param>
 332        public async Task<Response<ListDataSourcesResult>> ListAsync(string select = null, CancellationToken cancellatio
 333        {
 1334            using var message = CreateListRequest(select);
 1335            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1336            switch (message.Response.Status)
 337            {
 338                case 200:
 339                    {
 340                        ListDataSourcesResult value = default;
 1341                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1342                        value = ListDataSourcesResult.DeserializeListDataSourcesResult(document.RootElement);
 1343                        return Response.FromValue(value, message.Response);
 344                    }
 345                default:
 0346                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 347            }
 1348        }
 349
 350        /// <summary> Lists all datasources available for a search service. </summary>
 351        /// <param name="select"> Selects which top-level properties of the data sources to retrieve. Specified as a com
 352        /// <param name="cancellationToken"> The cancellation token to use. </param>
 353        public Response<ListDataSourcesResult> List(string select = null, CancellationToken cancellationToken = default)
 354        {
 1355            using var message = CreateListRequest(select);
 1356            _pipeline.Send(message, cancellationToken);
 1357            switch (message.Response.Status)
 358            {
 359                case 200:
 360                    {
 361                        ListDataSourcesResult value = default;
 1362                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1363                        value = ListDataSourcesResult.DeserializeListDataSourcesResult(document.RootElement);
 1364                        return Response.FromValue(value, message.Response);
 365                    }
 366                default:
 0367                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 368            }
 1369        }
 370
 371        internal HttpMessage CreateCreateRequest(SearchIndexerDataSourceConnection dataSource)
 372        {
 5373            var message = _pipeline.CreateMessage();
 5374            var request = message.Request;
 5375            request.Method = RequestMethod.Post;
 5376            var uri = new RawRequestUriBuilder();
 5377            uri.AppendRaw(endpoint, false);
 5378            uri.AppendPath("/datasources", false);
 5379            uri.AppendQuery("api-version", apiVersion, true);
 5380            request.Uri = uri;
 5381            if (xMsClientRequestId != null)
 382            {
 0383                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 384            }
 5385            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 5386            request.Headers.Add("Content-Type", "application/json");
 5387            var content = new Utf8JsonRequestContent();
 5388            content.JsonWriter.WriteObjectValue(dataSource);
 5389            request.Content = content;
 5390            return message;
 391        }
 392
 393        /// <summary> Creates a new datasource. </summary>
 394        /// <param name="dataSource"> The definition of the datasource to create. </param>
 395        /// <param name="cancellationToken"> The cancellation token to use. </param>
 396        /// <exception cref="ArgumentNullException"> <paramref name="dataSource"/> is null. </exception>
 397        public async Task<Response<SearchIndexerDataSourceConnection>> CreateAsync(SearchIndexerDataSourceConnection dat
 398        {
 3399            if (dataSource == null)
 400            {
 0401                throw new ArgumentNullException(nameof(dataSource));
 402            }
 403
 3404            using var message = CreateCreateRequest(dataSource);
 3405            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 3406            switch (message.Response.Status)
 407            {
 408                case 201:
 409                    {
 410                        SearchIndexerDataSourceConnection value = default;
 3411                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 3412                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 3413                        return Response.FromValue(value, message.Response);
 414                    }
 415                default:
 0416                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 417            }
 3418        }
 419
 420        /// <summary> Creates a new datasource. </summary>
 421        /// <param name="dataSource"> The definition of the datasource to create. </param>
 422        /// <param name="cancellationToken"> The cancellation token to use. </param>
 423        /// <exception cref="ArgumentNullException"> <paramref name="dataSource"/> is null. </exception>
 424        public Response<SearchIndexerDataSourceConnection> Create(SearchIndexerDataSourceConnection dataSource, Cancella
 425        {
 2426            if (dataSource == null)
 427            {
 0428                throw new ArgumentNullException(nameof(dataSource));
 429            }
 430
 2431            using var message = CreateCreateRequest(dataSource);
 2432            _pipeline.Send(message, cancellationToken);
 2433            switch (message.Response.Status)
 434            {
 435                case 201:
 436                    {
 437                        SearchIndexerDataSourceConnection value = default;
 2438                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2439                        value = SearchIndexerDataSourceConnection.DeserializeSearchIndexerDataSourceConnection(document.
 2440                        return Response.FromValue(value, message.Response);
 441                    }
 442                default:
 0443                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 444            }
 2445        }
 446    }
 447}