< Summary

Class:Azure.Search.Documents.Models.FacetResult
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FacetResult.cs
C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FacetResult.Serialization.cs
C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Models\FacetResult.cs
Covered lines:16
Uncovered lines:21
Coverable lines:37
Total lines:170
Line coverage:43.2% (16 of 37)
Covered branches:6
Total branches:14
Branch coverage:42.8% (6 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-0%100%
.ctor(...)-100%100%
get_Count()-100%100%
get_AdditionalProperties()-100%100%
GetEnumerator()-0%100%
System.Collections.IEnumerable.GetEnumerator()-0%100%
TryGetValue(...)-100%100%
ContainsKey(...)-0%100%
get_Keys()-100%100%
get_Values()-0%100%
System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.get_Count()-0%100%
get_Item(...)-100%100%
DeserializeFacetResult(...)-0%0%
get_FacetType()-100%100%
get_Value()-100%100%
get_From()-100%100%
get_To()-100%100%
GetValue(...)-100%100%
AsRangeFacetResult()-50%50%
AsValueFacetResult()-50%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FacetResult.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.Collections;
 9using System.Collections.Generic;
 10using Azure.Core;
 11
 12namespace Azure.Search.Documents.Models
 13{
 14    /// <summary> A single bucket of a facet query result. Reports the number of documents with a field value falling wi
 15    public partial class FacetResult : IReadOnlyDictionary<string, object>
 16    {
 17        /// <summary> Initializes a new instance of FacetResult. </summary>
 018        internal FacetResult()
 19        {
 020            AdditionalProperties = new ChangeTrackingDictionary<string, object>();
 021        }
 22
 23        /// <summary> Initializes a new instance of FacetResult. </summary>
 24        /// <param name="count"> The approximate count of documents falling within the bucket described by this facet. <
 25        /// <param name="additionalProperties"> . </param>
 13226        internal FacetResult(long? count, IReadOnlyDictionary<string, object> additionalProperties)
 27        {
 13228            Count = count;
 13229            AdditionalProperties = additionalProperties;
 13230        }
 31
 32        /// <summary> The approximate count of documents falling within the bucket described by this facet. </summary>
 14233        public long? Count { get; }
 38034        internal IReadOnlyDictionary<string, object> AdditionalProperties { get; }
 35        /// <inheritdoc />
 036        public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => AdditionalProperties.GetEnumerator();
 37        /// <inheritdoc />
 038        IEnumerator IEnumerable.GetEnumerator() => AdditionalProperties.GetEnumerator();
 39        /// <inheritdoc />
 7840        public bool TryGetValue(string key, out object value) => AdditionalProperties.TryGetValue(key, out value);
 41        /// <inheritdoc />
 042        public bool ContainsKey(string key) => AdditionalProperties.ContainsKey(key);
 43        /// <inheritdoc />
 19844        public IEnumerable<string> Keys => AdditionalProperties.Keys;
 45        /// <inheritdoc />
 046        public IEnumerable<object> Values => AdditionalProperties.Values;
 47        /// <inheritdoc />
 048        int IReadOnlyCollection<KeyValuePair<string, object>>.Count => AdditionalProperties.Count;
 49        /// <inheritdoc />
 50        public object this[string key]
 51        {
 7852            get => AdditionalProperties[key];
 53        }
 54    }
 55}

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FacetResult.Serialization.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.Collections.Generic;
 9using System.Text.Json;
 10using Azure.Core;
 11
 12namespace Azure.Search.Documents.Models
 13{
 14    public partial class FacetResult
 15    {
 16        internal static FacetResult DeserializeFacetResult(JsonElement element)
 17        {
 018            Optional<long> count = default;
 019            IReadOnlyDictionary<string, object> additionalProperties = default;
 020            Dictionary<string, object> additionalPropertiesDictionary = default;
 021            foreach (var property in element.EnumerateObject())
 22            {
 023                if (property.NameEquals("count"))
 24                {
 025                    count = property.Value.GetInt64();
 026                    continue;
 27                }
 028                additionalPropertiesDictionary ??= new Dictionary<string, object>();
 029                additionalPropertiesDictionary.Add(property.Name, property.Value.GetObject());
 30            }
 031            additionalProperties = additionalPropertiesDictionary;
 032            return new FacetResult(Optional.ToNullable(count), additionalProperties);
 33        }
 34    }
 35}

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Search.Documents.Models
 7{
 8    public partial class FacetResult
 9    {
 10        /// <summary>
 11        /// Gets the type of this facet.  Value facets count documents with a
 12        /// particular field value and Range facets count documents with a
 13        /// field value in a particular range.
 14        /// </summary>
 1015        public FacetType FacetType => (Value != null) ? FacetType.Value : FacetType.Range;
 16
 17        /// <summary>
 18        /// Gets the value of the facet, or the inclusive lower bound if it's
 19        /// an interval facet.
 20        /// </summary>
 1421        public object Value => GetValue(Constants.ValueKey);
 22
 23        /// <summary>
 24        /// Gets a value indicating the inclusive lower bound of the facet's
 25        /// range, or null to indicate that there is no lower bound (i.e. --
 26        /// for the first bucket).
 27        /// </summary>
 628        public object From => GetValue(Constants.FromKey);
 29
 30        /// <summary>
 31        /// Gets a value indicating the exclusive upper bound of the facet's
 32        /// range, or null to indicate that there is no upper bound (i.e. --
 33        /// for the last bucket).
 34        /// </summary>
 635        public object To => GetValue(Constants.ToKey);
 36
 37        /// <summary>
 38        /// Get the value of a key like "value" or return null if not found.
 39        /// </summary>
 40        /// <param name="key">The name of the key to lookup.</param>
 41        /// <returns>The value of the key or null.</returns>
 42        private object GetValue(string key) =>
 2643            AdditionalProperties.TryGetValue(key, out object value) ? value : null;
 44
 45        /// <summary>
 46        /// Attempts to convert the facet to a range facet of the given type.
 47        /// </summary>
 48        /// <typeparam name="T">
 49        /// A type that matches the type of the field to which the facet was
 50        /// applied. Valid types include <see cref="DateTimeOffset"/>,
 51        /// <see cref="Double"/>, and <see cref="Int64"/>.
 52        /// </typeparam>
 53        /// <returns>A new strongly-typed range facet instance.</returns>
 54        /// <exception cref="InvalidCastException">
 55        /// This instance is not a range facet of the given type.
 56        /// </exception>
 57        public RangeFacetResult<T> AsRangeFacetResult<T>() where T : struct
 58        {
 059            if (FacetType != FacetType.Range) { throw new InvalidCastException(); }
 660            return new RangeFacetResult<T>(Count.GetValueOrDefault(), (T?)From, (T?)To);
 61        }
 62
 63        /// <summary>
 64        /// Attempts to convert the facet to a value facet of the given type.
 65        /// </summary>
 66        /// <typeparam name="T">
 67        /// A type that matches the type of the field to which the facet was
 68        /// applied.
 69        /// </typeparam>
 70        /// <returns>A new strongly-typed value facet instance.</returns>
 71        /// <exception cref="InvalidCastException">
 72        /// This instance is not a value facet of the given type.
 73        /// </exception>
 74        public ValueFacetResult<T> AsValueFacetResult<T>()
 75        {
 076            if (FacetType != FacetType.Value) { throw new InvalidCastException(); }
 477            return new ValueFacetResult<T>(Count.GetValueOrDefault(), (T)Value);
 78        }
 79    }
 80}