< Summary

Class:Microsoft.Azure.Search.Serialization.IndexActionConverter`1
Assembly:Microsoft.Azure.Search.Data
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Serialization\IndexActionConverter.cs
Covered lines:10
Uncovered lines:2
Coverable lines:12
Total lines:51
Line coverage:83.3% (10 of 12)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_CanRead()-0%100%
get_CanWrite()-100%100%
CanConvert(...)-100%100%
ReadJson(...)-0%100%
WriteJson(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Customizations\Serialization\IndexActionConverter.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.Serialization
 6{
 7    using System;
 8    using System.Reflection;
 9    using Microsoft.Azure.Search.Models;
 10    using Newtonsoft.Json;
 11    using Newtonsoft.Json.Converters;
 12
 13    /// <summary>
 14    /// Serializes IndexAction instances so that the JSON is OData-compliant.
 15    /// </summary>
 16    /// <typeparam name="T">
 17    /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index.
 18    /// </typeparam>
 19    internal class IndexActionConverter<T> : JsonConverter
 20    {
 021        public override bool CanRead => false;
 22
 2750823        public override bool CanWrite => true;
 24
 25        public override bool CanConvert(Type objectType)
 26        {
 12498827            return typeof(IndexAction<T>).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
 28        }
 29
 30        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer seriali
 31        {
 032            throw new NotImplementedException();
 33        }
 34
 35        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 36        {
 2750837            var action = (IndexAction<T>)value;
 38
 39            void WriteActionAnnotation(JsonWriter innerWriter)
 40            {
 2750841                innerWriter.WritePropertyName("@search.action");
 42
 2750843                var converter = new StringEnumConverter();
 2750844                converter.WriteJson(innerWriter, action.ActionType, serializer);
 2750845            }
 46
 2750847            var injectingWriter = new InjectingJsonWriter(writer) { OnStart = WriteActionAnnotation };
 2750848            serializer.Serialize(injectingWriter, action.Document);
 2750849        }
 50    }
 51}