• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentRest / 7318593291

25 Dec 2023 02:55AM UTC coverage: 52.206%. Remained the same
7318593291

Pull #158

github

web-flow
Merge 38e3e6116 into 7b58509ff
Pull Request #158: Bump xunit.runner.visualstudio from 2.5.4 to 2.5.6

182 of 438 branches covered (0.0%)

Branch coverage included in aggregate %.

516 of 899 relevant lines covered (57.4%)

86.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/FluentRest/ProblemDetailsConverter.cs
1
using System;
2
using System.Text.Json;
3
using System.Text.Json.Serialization;
4

5
namespace FluentRest;
6

7
internal sealed class ProblemDetailsConverter : JsonConverter<ProblemDetails>
8
{
9
    private static readonly JsonEncodedText Type = JsonEncodedText.Encode("type");
×
10
    private static readonly JsonEncodedText Title = JsonEncodedText.Encode("title");
×
11
    private static readonly JsonEncodedText Status = JsonEncodedText.Encode("status");
×
12
    private static readonly JsonEncodedText Detail = JsonEncodedText.Encode("detail");
×
13
    private static readonly JsonEncodedText Instance = JsonEncodedText.Encode("instance");
×
14

15
    public override ProblemDetails Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
16
    {
17
        var problemDetails = new ProblemDetails();
×
18

19
        if (reader.TokenType != JsonTokenType.StartObject)
×
20
            throw new JsonException("Unexcepted end when reading JSON.");
×
21

22
        while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
×
23
            ReadValue(ref reader, problemDetails, options);
×
24

25
        if (reader.TokenType != JsonTokenType.EndObject)
×
26
            throw new JsonException("Unexcepted end when reading JSON.");
×
27

28
        return problemDetails;
×
29
    }
30

31
    public override void Write(Utf8JsonWriter writer, ProblemDetails value, JsonSerializerOptions options)
32
    {
33
        writer.WriteStartObject();
×
34
        WriteProblemDetails(writer, value, options);
×
35
        writer.WriteEndObject();
×
36
    }
×
37

38
    internal static void ReadValue(ref Utf8JsonReader reader, ProblemDetails value, JsonSerializerOptions options)
39
    {
40
        if (TryReadStringProperty(ref reader, Type, out var propertyValue))
×
41
        {
42
            value.Type = propertyValue;
×
43
        }
44
        else if (TryReadStringProperty(ref reader, Title, out propertyValue))
×
45
        {
46
            value.Title = propertyValue;
×
47
        }
48
        else if (TryReadStringProperty(ref reader, Detail, out propertyValue))
×
49
        {
50
            value.Detail = propertyValue;
×
51
        }
52
        else if (TryReadStringProperty(ref reader, Instance, out propertyValue))
×
53
        {
54
            value.Instance = propertyValue;
×
55
        }
56
        else if (reader.ValueTextEquals(Status.EncodedUtf8Bytes))
×
57
        {
58
            reader.Read();
×
59
            if (reader.TokenType != JsonTokenType.Null)
×
60
                value.Status = reader.GetInt32();
×
61
        }
62
        else
63
        {
64
            var key = reader.GetString()!;
×
65
            reader.Read();
×
66
            value.Extensions[key] = JsonSerializer.Deserialize(ref reader, typeof(object), options);
×
67
        }
68
    }
×
69

70
    internal static bool TryReadStringProperty(ref Utf8JsonReader reader, JsonEncodedText propertyName, out string value)
71
    {
72
        if (!reader.ValueTextEquals(propertyName.EncodedUtf8Bytes))
×
73
        {
74
            value = default;
×
75
            return false;
×
76
        }
77

78
        reader.Read();
×
79
        value = reader.GetString()!;
×
80
        return true;
×
81
    }
82

83
    internal static void WriteProblemDetails(Utf8JsonWriter writer, ProblemDetails value, JsonSerializerOptions options)
84
    {
85
        if (value.Type != null)
×
86
            writer.WriteString(Type, value.Type);
×
87

88
        if (value.Title != null)
×
89
            writer.WriteString(Title, value.Title);
×
90

91
        if (value.Status != null)
×
92
            writer.WriteNumber(Status, value.Status.Value);
×
93

94
        if (value.Detail != null)
×
95
            writer.WriteString(Detail, value.Detail);
×
96

97
        if (value.Instance != null)
×
98
            writer.WriteString(Instance, value.Instance);
×
99

100
        foreach (var kvp in value.Extensions)
×
101
        {
102
            writer.WritePropertyName(kvp.Key);
×
103
            JsonSerializer.Serialize(writer, kvp.Value, kvp.Value?.GetType() ?? typeof(object), options);
×
104
        }
105
    }
×
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc