< Summary

Class:Azure.Search.Documents.Indexes.Models.FieldMapping
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FieldMapping.cs
C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FieldMapping.Serialization.cs
Covered lines:36
Uncovered lines:6
Coverable lines:42
Total lines:117
Line coverage:85.7% (36 of 42)
Covered branches:13
Total branches:18
Branch coverage:72.2% (13 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
.ctor(...)-100%100%
get_SourceFieldName()-100%100%
get_TargetFieldName()-100%100%
get_MappingFunction()-100%100%
Azure.Core.IUtf8JsonSerializable.Write(...)-69.23%50%
DeserializeFieldMapping(...)-93.75%90%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FieldMapping.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;
 9
 10namespace Azure.Search.Documents.Indexes.Models
 11{
 12    /// <summary> Defines a mapping between a field in a data source and a target field in an index. </summary>
 13    public partial class FieldMapping
 14    {
 15        /// <summary> Initializes a new instance of FieldMapping. </summary>
 16        /// <param name="sourceFieldName"> The name of the field in the data source. </param>
 17        /// <exception cref="ArgumentNullException"> <paramref name="sourceFieldName"/> is null. </exception>
 618        public FieldMapping(string sourceFieldName)
 19        {
 620            if (sourceFieldName == null)
 21            {
 022                throw new ArgumentNullException(nameof(sourceFieldName));
 23            }
 24
 625            SourceFieldName = sourceFieldName;
 626        }
 27
 28        /// <summary> Initializes a new instance of FieldMapping. </summary>
 29        /// <param name="sourceFieldName"> The name of the field in the data source. </param>
 30        /// <param name="targetFieldName"> The name of the target field in the index. Same as the source field name by d
 31        /// <param name="mappingFunction"> A function to apply to each source field value before indexing. </param>
 632        internal FieldMapping(string sourceFieldName, string targetFieldName, FieldMappingFunction mappingFunction)
 33        {
 634            SourceFieldName = sourceFieldName;
 635            TargetFieldName = targetFieldName;
 636            MappingFunction = mappingFunction;
 637        }
 38
 39        /// <summary> The name of the field in the data source. </summary>
 1840        public string SourceFieldName { get; set; }
 41        /// <summary> The name of the target field in the index. Same as the source field name by default. </summary>
 1442        public string TargetFieldName { get; set; }
 43        /// <summary> A function to apply to each source field value before indexing. </summary>
 1244        public FieldMappingFunction MappingFunction { get; set; }
 45    }
 46}

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\Models\FieldMapping.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.Text.Json;
 9using Azure.Core;
 10
 11namespace Azure.Search.Documents.Indexes.Models
 12{
 13    public partial class FieldMapping : IUtf8JsonSerializable
 14    {
 15        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 16        {
 617            writer.WriteStartObject();
 618            writer.WritePropertyName("sourceFieldName");
 619            writer.WriteStringValue(SourceFieldName);
 620            if (Optional.IsDefined(TargetFieldName))
 21            {
 122                writer.WritePropertyName("targetFieldName");
 123                writer.WriteStringValue(TargetFieldName);
 24            }
 625            if (Optional.IsDefined(MappingFunction))
 26            {
 027                if (MappingFunction != null)
 28                {
 029                    writer.WritePropertyName("mappingFunction");
 030                    writer.WriteObjectValue(MappingFunction);
 31                }
 32                else
 33                {
 034                    writer.WriteNull("mappingFunction");
 35                }
 36            }
 637            writer.WriteEndObject();
 638        }
 39
 40        internal static FieldMapping DeserializeFieldMapping(JsonElement element)
 41        {
 642            string sourceFieldName = default;
 643            Optional<string> targetFieldName = default;
 644            Optional<FieldMappingFunction> mappingFunction = default;
 4845            foreach (var property in element.EnumerateObject())
 46            {
 1847                if (property.NameEquals("sourceFieldName"))
 48                {
 649                    sourceFieldName = property.Value.GetString();
 650                    continue;
 51                }
 1252                if (property.NameEquals("targetFieldName"))
 53                {
 654                    targetFieldName = property.Value.GetString();
 655                    continue;
 56                }
 657                if (property.NameEquals("mappingFunction"))
 58                {
 659                    if (property.Value.ValueKind == JsonValueKind.Null)
 60                    {
 661                        mappingFunction = null;
 662                        continue;
 63                    }
 064                    mappingFunction = FieldMappingFunction.DeserializeFieldMappingFunction(property.Value);
 65                    continue;
 66                }
 67            }
 668            return new FieldMapping(sourceFieldName, targetFieldName.Value, mappingFunction.Value);
 69        }
 70    }
 71}