< Summary

Class:SVETA.Api.Helpers.BadDateFixingConverter
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Helpers/BadDateFixingConverter.cs
Covered lines:0
Uncovered lines:18
Coverable lines:18
Total lines:38
Line coverage:0% (0 of 18)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
WriteJson(...)0%100%
ReadJson(...)0%0%
CanConvert(...)0%0%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Helpers/BadDateFixingConverter.cs

#LineLine coverage
 1using System;
 2using Newtonsoft.Json;
 3
 4namespace SVETA.Api.Helpers
 5{
 6    public class BadDateFixingConverter: JsonConverter
 7    {
 8        private string FormatString;
 09        public BadDateFixingConverter(string formatString)
 010        {
 011            FormatString = formatString;
 012        }
 13        public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
 014        {
 015            throw new NotImplementedException();
 16        }
 17
 18        public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer seria
 019        {
 020            string rawDate = (string) reader.Value;
 21            try
 022            {
 023                return DateTime.ParseExact(rawDate, FormatString, null);
 24            }
 025            catch (Exception e)
 026            {
 027                if (objectType == typeof(DateTime))
 028                {
 029                    return null;
 30                }
 31
 032                return DateTime.MinValue;
 33            }
 034        }
 35
 036        public override bool CanConvert(Type objectType) => (objectType == typeof(DateTime) || objectType == typeof(Date
 37    }
 38}