< Summary

Class:Azure.Search.Documents.SearchDateTimeConverter
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Serialization\SearchDateTimeConverter.cs
Covered lines:2
Uncovered lines:5
Coverable lines:7
Total lines:43
Line coverage:28.5% (2 of 7)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Shared()-100%100%
.cctor()-100%100%
Read(...)-0%100%
Write(...)-0%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Diagnostics;
 6using System.Globalization;
 7using System.Text.Json;
 8using System.Text.Json.Serialization;
 9using Azure.Core;
 10
 11namespace Azure.Search.Documents
 12{
 13    /// <summary>
 14    /// Convert dates to and from JSON.  They're expected to be in 8601 UTC.
 15    /// </summary>
 16    internal class SearchDateTimeConverter : JsonConverter<DateTime>
 17    {
 118        public static SearchDateTimeConverter Shared { get; } =
 119            new SearchDateTimeConverter();
 20
 21        public override DateTime Read(
 22            ref Utf8JsonReader reader,
 23            Type typeToConvert,
 24            JsonSerializerOptions options)
 25        {
 26            Debug.Assert(typeToConvert != null);
 27            Debug.Assert(options != null);
 28
 029            string text = reader.GetString();
 030            return DateTime.Parse(text, CultureInfo.InvariantCulture);
 31        }
 32
 33        public override void Write(
 34            Utf8JsonWriter writer,
 35            DateTime value,
 36            JsonSerializerOptions options)
 37        {
 038            Argument.AssertNotNull(writer, nameof(writer));
 39            Debug.Assert(options != null);
 040            writer.WriteStringValue(JsonSerialization.Date(value, CultureInfo.InvariantCulture));
 041        }
 42    }
 43}