< Summary

Class:Microsoft.Azure.Search.Models.ScoringParameter
Assembly:Microsoft.Azure.Search.Data
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Documents\Models\ScoringParameter.cs
Covered lines:16
Uncovered lines:1
Coverable lines:17
Total lines:75
Line coverage:94.1% (16 of 17)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Name()-100%100%
get_Values()-100%100%
ToString()-100%100%
EscapeValue(...)-100%50%
ToLonLatStrings()-80%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Documents\Models\ScoringParameter.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.Search.Models
 6{
 7    using System.Collections.Generic;
 8    using System.Globalization;
 9    using System.Linq;
 10    using Common;
 11    using Spatial;
 12
 13    /// <summary>
 14    /// Represents a parameter value to be used in scoring functions (for example, referencePointParameter).
 15    /// </summary>
 16    public class ScoringParameter
 17    {
 18        /// <summary>
 19        /// Initializes a new instance of the ScoringParameter class with the given name and string values.
 20        /// </summary>
 21        /// <param name="name">Name of the scoring parameter.</param>
 22        /// <param name="values">Values of the scoring parameter.</param>
 2223        public ScoringParameter(string name, IEnumerable<string> values)
 24        {
 2225            Throw.IfArgumentNull(name, "name");
 2226            Throw.IfArgumentNull(values, "values");
 27
 2228            Name = name;
 2229            Values = values.ToList();   // Deep copy.
 2230        }
 31
 32        /// <summary>
 33        /// Initializes a new instance of the ScoringParameter class with the given name and GeographyPoint value.
 34        /// </summary>
 35        /// <param name="name">Name of the scoring parameter.</param>
 36        /// <param name="value">Value of the scoring parameter.</param>
 837        public ScoringParameter(string name, GeographyPoint value) : this(name, ToLonLatStrings(value)) { }
 38
 39        /// <summary>
 40        /// Gets the name of the scoring parameter.
 41        /// </summary>
 2242        public string Name { get; }
 43
 44        /// <summary>
 45        /// Gets the values of the scoring parameter.
 46        /// </summary>
 2247        public IEnumerable<string> Values{ get; }
 48
 49        /// <summary>
 50        /// Returns the scoring parameter in a format that can be used in a Search API request.
 51        /// </summary>
 52        /// <returns>
 53        /// The scoring parameter as a colon-separated name-value pair (for example, mylocation:-122.2,44.8)
 54        /// </returns>
 55        public override string ToString() =>
 7056            $"{Name}-{Values.Select(v => EscapeValue(v)).ToCommaSeparatedString()}";
 57
 58        private static string EscapeValue(string value)
 59        {
 4860            value = value?.Replace("'", "''");
 4861            return $"'{value}'";
 62        }
 63
 64        private static IEnumerable<string> ToLonLatStrings(GeographyPoint point)
 65        {
 466            if (point == null)
 67            {
 068                yield break;
 69            }
 70
 471            yield return point.Longitude.ToString(CultureInfo.InvariantCulture);
 472            yield return point.Latitude.ToString(CultureInfo.InvariantCulture);
 473        }
 74    }
 75}