< Summary

Class:Azure.Search.Documents.SynonymMapsRestClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\SynonymMapsRestClient.cs
Covered lines:171
Uncovered lines:21
Coverable lines:192
Total lines:447
Line coverage:89% (171 of 192)
Covered branches:45
Total branches:68
Branch coverage:66.1% (45 of 68)

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\SynonymMapsRestClient.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 SynonymMapsRestClient
 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 SynonymMapsRestClient. </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
 634        public SynonymMapsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? 
 35        {
 636            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 640            if (apiVersion == null)
 41            {
 042                throw new ArgumentNullException(nameof(apiVersion));
 43            }
 44
 645            this.endpoint = endpoint;
 646            this.xMsClientRequestId = xMsClientRequestId;
 647            this.apiVersion = apiVersion;
 648            _clientDiagnostics = clientDiagnostics;
 649            _pipeline = pipeline;
 650        }
 51
 52        internal HttpMessage CreateCreateOrUpdateRequest(string synonymMapName, SynonymMap synonymMap, string ifMatch, s
 53        {
 454            var message = _pipeline.CreateMessage();
 455            var request = message.Request;
 456            request.Method = RequestMethod.Put;
 457            var uri = new RawRequestUriBuilder();
 458            uri.AppendRaw(endpoint, false);
 459            uri.AppendPath("/synonymmaps('", false);
 460            uri.AppendPath(synonymMapName, true);
 461            uri.AppendPath("')", false);
 462            uri.AppendQuery("api-version", apiVersion, true);
 463            request.Uri = uri;
 464            if (xMsClientRequestId != null)
 65            {
 066                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 67            }
 468            if (ifMatch != null)
 69            {
 470                request.Headers.Add("If-Match", ifMatch);
 71            }
 472            if (ifNoneMatch != null)
 73            {
 074                request.Headers.Add("If-None-Match", ifNoneMatch);
 75            }
 476            request.Headers.Add("Prefer", "return=representation");
 477            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 478            request.Headers.Add("Content-Type", "application/json");
 479            var content = new Utf8JsonRequestContent();
 480            content.JsonWriter.WriteObjectValue(synonymMap);
 481            request.Content = content;
 482            return message;
 83        }
 84
 85        /// <summary> Creates a new synonym map or updates a synonym map if it already exists. </summary>
 86        /// <param name="synonymMapName"> The name of the synonym map to create or update. </param>
 87        /// <param name="synonymMap"> The definition of the synonym map 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="synonymMapName"/> or <paramref name="synonymMap"/> 
 92        public async Task<Response<SynonymMap>> CreateOrUpdateAsync(string synonymMapName, SynonymMap synonymMap, string
 93        {
 294            if (synonymMapName == null)
 95            {
 096                throw new ArgumentNullException(nameof(synonymMapName));
 97            }
 298            if (synonymMap == null)
 99            {
 0100                throw new ArgumentNullException(nameof(synonymMap));
 101            }
 102
 2103            using var message = CreateCreateOrUpdateRequest(synonymMapName, synonymMap, ifMatch, ifNoneMatch);
 2104            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2105            switch (message.Response.Status)
 106            {
 107                case 200:
 108                case 201:
 109                    {
 110                        SynonymMap value = default;
 1111                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1112                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 1113                        return Response.FromValue(value, message.Response);
 114                    }
 115                default:
 1116                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 117            }
 1118        }
 119
 120        /// <summary> Creates a new synonym map or updates a synonym map if it already exists. </summary>
 121        /// <param name="synonymMapName"> The name of the synonym map to create or update. </param>
 122        /// <param name="synonymMap"> The definition of the synonym map 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="synonymMapName"/> or <paramref name="synonymMap"/> 
 127        public Response<SynonymMap> CreateOrUpdate(string synonymMapName, SynonymMap synonymMap, string ifMatch = null, 
 128        {
 2129            if (synonymMapName == null)
 130            {
 0131                throw new ArgumentNullException(nameof(synonymMapName));
 132            }
 2133            if (synonymMap == null)
 134            {
 0135                throw new ArgumentNullException(nameof(synonymMap));
 136            }
 137
 2138            using var message = CreateCreateOrUpdateRequest(synonymMapName, synonymMap, ifMatch, ifNoneMatch);
 2139            _pipeline.Send(message, cancellationToken);
 2140            switch (message.Response.Status)
 141            {
 142                case 200:
 143                case 201:
 144                    {
 145                        SynonymMap value = default;
 1146                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1147                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 1148                        return Response.FromValue(value, message.Response);
 149                    }
 150                default:
 1151                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 152            }
 1153        }
 154
 155        internal HttpMessage CreateDeleteRequest(string synonymMapName, 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("/synonymmaps('", false);
 3163            uri.AppendPath(synonymMapName, 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 synonym map. </summary>
 184        /// <param name="synonymMapName"> The name of the synonym map 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="synonymMapName"/> is null. </exception>
 189        public async Task<Response> DeleteAsync(string synonymMapName, string ifMatch = null, string ifNoneMatch = null,
 190        {
 3191            if (synonymMapName == null)
 192            {
 1193                throw new ArgumentNullException(nameof(synonymMapName));
 194            }
 195
 2196            using var message = CreateDeleteRequest(synonymMapName, 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 synonym map. </summary>
 209        /// <param name="synonymMapName"> The name of the synonym map 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="synonymMapName"/> is null. </exception>
 214        public Response Delete(string synonymMapName, string ifMatch = null, string ifNoneMatch = null, CancellationToke
 215        {
 2216            if (synonymMapName == null)
 217            {
 1218                throw new ArgumentNullException(nameof(synonymMapName));
 219            }
 220
 1221            using var message = CreateDeleteRequest(synonymMapName, 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 synonymMapName)
 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("/synonymmaps('", false);
 2241            uri.AppendPath(synonymMapName, 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 synonym map definition. </summary>
 254        /// <param name="synonymMapName"> The name of the synonym map to retrieve. </param>
 255        /// <param name="cancellationToken"> The cancellation token to use. </param>
 256        /// <exception cref="ArgumentNullException"> <paramref name="synonymMapName"/> is null. </exception>
 257        public async Task<Response<SynonymMap>> GetAsync(string synonymMapName, CancellationToken cancellationToken = de
 258        {
 2259            if (synonymMapName == null)
 260            {
 1261                throw new ArgumentNullException(nameof(synonymMapName));
 262            }
 263
 1264            using var message = CreateGetRequest(synonymMapName);
 1265            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1266            switch (message.Response.Status)
 267            {
 268                case 200:
 269                    {
 270                        SynonymMap value = default;
 1271                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1272                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 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 synonym map definition. </summary>
 281        /// <param name="synonymMapName"> The name of the synonym map to retrieve. </param>
 282        /// <param name="cancellationToken"> The cancellation token to use. </param>
 283        /// <exception cref="ArgumentNullException"> <paramref name="synonymMapName"/> is null. </exception>
 284        public Response<SynonymMap> Get(string synonymMapName, CancellationToken cancellationToken = default)
 285        {
 2286            if (synonymMapName == null)
 287            {
 1288                throw new ArgumentNullException(nameof(synonymMapName));
 289            }
 290
 1291            using var message = CreateGetRequest(synonymMapName);
 1292            _pipeline.Send(message, cancellationToken);
 1293            switch (message.Response.Status)
 294            {
 295                case 200:
 296                    {
 297                        SynonymMap value = default;
 1298                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1299                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 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("/synonymmaps", 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 synonym maps available for a search service. </summary>
 330        /// <param name="select"> Selects which top-level properties of the synonym maps to retrieve. Specified as a com
 331        /// <param name="cancellationToken"> The cancellation token to use. </param>
 332        public async Task<Response<ListSynonymMapsResult>> 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                        ListSynonymMapsResult value = default;
 1341                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1342                        value = ListSynonymMapsResult.DeserializeListSynonymMapsResult(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 synonym maps available for a search service. </summary>
 351        /// <param name="select"> Selects which top-level properties of the synonym maps to retrieve. Specified as a com
 352        /// <param name="cancellationToken"> The cancellation token to use. </param>
 353        public Response<ListSynonymMapsResult> 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                        ListSynonymMapsResult value = default;
 1362                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1363                        value = ListSynonymMapsResult.DeserializeListSynonymMapsResult(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(SynonymMap synonymMap)
 372        {
 3373            var message = _pipeline.CreateMessage();
 3374            var request = message.Request;
 3375            request.Method = RequestMethod.Post;
 3376            var uri = new RawRequestUriBuilder();
 3377            uri.AppendRaw(endpoint, false);
 3378            uri.AppendPath("/synonymmaps", false);
 3379            uri.AppendQuery("api-version", apiVersion, true);
 3380            request.Uri = uri;
 3381            if (xMsClientRequestId != null)
 382            {
 0383                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 384            }
 3385            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 3386            request.Headers.Add("Content-Type", "application/json");
 3387            var content = new Utf8JsonRequestContent();
 3388            content.JsonWriter.WriteObjectValue(synonymMap);
 3389            request.Content = content;
 3390            return message;
 391        }
 392
 393        /// <summary> Creates a new synonym map. </summary>
 394        /// <param name="synonymMap"> The definition of the synonym map to create. </param>
 395        /// <param name="cancellationToken"> The cancellation token to use. </param>
 396        /// <exception cref="ArgumentNullException"> <paramref name="synonymMap"/> is null. </exception>
 397        public async Task<Response<SynonymMap>> CreateAsync(SynonymMap synonymMap, CancellationToken cancellationToken =
 398        {
 3399            if (synonymMap == null)
 400            {
 1401                throw new ArgumentNullException(nameof(synonymMap));
 402            }
 403
 2404            using var message = CreateCreateRequest(synonymMap);
 2405            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2406            switch (message.Response.Status)
 407            {
 408                case 201:
 409                    {
 410                        SynonymMap value = default;
 2411                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2412                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 2413                        return Response.FromValue(value, message.Response);
 414                    }
 415                default:
 0416                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 417            }
 2418        }
 419
 420        /// <summary> Creates a new synonym map. </summary>
 421        /// <param name="synonymMap"> The definition of the synonym map to create. </param>
 422        /// <param name="cancellationToken"> The cancellation token to use. </param>
 423        /// <exception cref="ArgumentNullException"> <paramref name="synonymMap"/> is null. </exception>
 424        public Response<SynonymMap> Create(SynonymMap synonymMap, CancellationToken cancellationToken = default)
 425        {
 2426            if (synonymMap == null)
 427            {
 1428                throw new ArgumentNullException(nameof(synonymMap));
 429            }
 430
 1431            using var message = CreateCreateRequest(synonymMap);
 1432            _pipeline.Send(message, cancellationToken);
 1433            switch (message.Response.Status)
 434            {
 435                case 201:
 436                    {
 437                        SynonymMap value = default;
 1438                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1439                        value = SynonymMap.DeserializeSynonymMap(document.RootElement);
 1440                        return Response.FromValue(value, message.Response);
 441                    }
 442                default:
 0443                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 444            }
 1445        }
 446    }
 447}