< Summary

Class:Azure.Search.Documents.Models.SuggestResults`1
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Models\SuggestResults{T}.cs
Covered lines:29
Uncovered lines:0
Coverable lines:29
Total lines:130
Line coverage:100% (29 of 29)
Covered branches:12
Total branches:12
Branch coverage:100% (12 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Coverage()-100%100%
get_Results()-100%100%
.ctor()-100%100%
DeserializeAsync()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Models\SuggestResults{T}.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Collections.ObjectModel;
 6using System.IO;
 7using System.Text.Json;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using Azure.Core;
 11#if EXPERIMENTAL_SERIALIZER
 12using Azure.Core.Serialization;
 13#endif
 14
 15#pragma warning disable SA1402 // File may only contain a single type
 16
 17namespace Azure.Search.Documents.Models
 18{
 19    // Hide the untyped SuggestDocumentsResult
 20    [CodeGenModel("SuggestDocumentsResult")]
 21    internal partial class SuggestDocumentsResult { }
 22
 23    /// <summary>
 24    /// Response containing suggestion query results from an index.
 25    /// </summary>
 26    /// <typeparam name="T">
 27    /// The .NET type that maps to the index schema. Instances of this type can
 28    /// be retrieved as documents from the index.
 29    /// </typeparam>
 30    public partial class SuggestResults<T>
 31    {
 32        /// <summary>
 33        /// A value indicating the percentage of the index that was included in
 34        /// the query, or null if minimumCoverage was not set in the request.
 35        /// </summary>
 836        public double? Coverage { get; internal set; }
 37
 38        /// <summary>
 39        /// The sequence of suggestions returned by the query.
 40        /// </summary>
 6641        public IReadOnlyList<SearchSuggestion<T>> Results { get; internal set; }
 42
 43        /// <summary>
 44        /// Initializes a new instance of the SuggestResults class.
 45        /// </summary>
 4446        internal SuggestResults() { }
 47
 48        #pragma warning disable CS1572 // Not all parameters will be used depending on feature flags
 49        /// <summary>
 50        /// Deserialize the SuggestResults.
 51        /// </summary>
 52        /// <param name="json">A JSON stream.</param>
 53        /// <param name="serializer">
 54        /// Optional serializer that can be used to customize the serialization
 55        /// of strongly typed models.
 56        /// </param>
 57        /// <param name="async">Whether to execute sync or async.</param>
 58        /// <param name="cancellationToken">
 59        /// Optional <see cref="CancellationToken"/> to propagate notifications
 60        /// that the operation should be canceled.
 61        /// </param>
 62        /// <returns>Deserialized SuggestResults.</returns>
 63        internal static async Task<SuggestResults<T>> DeserializeAsync(
 64            Stream json,
 65#if EXPERIMENTAL_SERIALIZER
 66            ObjectSerializer serializer,
 67#endif
 68            bool async,
 69            CancellationToken cancellationToken)
 70        #pragma warning restore CS1572
 71        {
 72            // Parse the JSON
 2273            using JsonDocument doc = async ?
 2274                await JsonDocument.ParseAsync(json, cancellationToken: cancellationToken).ConfigureAwait(false) :
 2275                JsonDocument.Parse(json);
 76
 2277            JsonSerializerOptions defaultSerializerOptions = JsonSerialization.SerializerOptions;
 78
 2279            SuggestResults<T> suggestions = new SuggestResults<T>();
 9280            foreach (JsonProperty prop in doc.RootElement.EnumerateObject())
 81            {
 2482                if (prop.NameEquals(Constants.SearchCoverageKeyJson.EncodedUtf8Bytes) &&
 2483                    prop.Value.ValueKind != JsonValueKind.Null)
 84                {
 285                    suggestions.Coverage = prop.Value.GetDouble();
 86                }
 2287                else if (prop.NameEquals(Constants.ValueKeyJson.EncodedUtf8Bytes))
 88                {
 2289                    List<SearchSuggestion<T>> results = new List<SearchSuggestion<T>>();
 13290                    foreach (JsonElement element in prop.Value.EnumerateArray())
 91                    {
 4492                        SearchSuggestion<T> suggestion = await SearchSuggestion<T>.DeserializeAsync(
 4493                            element,
 4494#if EXPERIMENTAL_SERIALIZER
 4495                            serializer,
 4496#endif
 4497                            defaultSerializerOptions,
 4498                            async,
 4499                            cancellationToken)
 44100                            .ConfigureAwait(false);
 44101                        results.Add(suggestion);
 102                    }
 22103                    suggestions.Results = new ReadOnlyCollection<SearchSuggestion<T>>(results);
 22104                }
 105            }
 22106            return suggestions;
 22107        }
 108    }
 109
 110    public static partial class SearchModelFactory
 111    {
 112        /// <summary> Initializes a new instance of SearchResult. </summary>
 113        /// <typeparam name="T">
 114        /// The .NET type that maps to the index schema. Instances of this type
 115        /// can be retrieved as documents from the index.
 116        /// </typeparam>
 117        /// <param name="results">
 118        /// The sequence of suggestions returned by the query.
 119        /// </param>
 120        /// <param name="coverage">
 121        /// A value indicating the percentage of the index that was included in
 122        /// the query, or null if minimumCoverage was not set in the request.
 123        /// </param>
 124        /// <returns>A new SuggestResults instance for mocking.</returns>
 125        public static SuggestResults<T> SuggestResults<T>(
 126            IReadOnlyList<SearchSuggestion<T>> results,
 127            double? coverage) =>
 128            new SuggestResults<T>() { Coverage = coverage, Results = results };
 129    }
 130}