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

zorbathut / dec / 11670896818

04 Nov 2024 07:02PM UTC coverage: 90.556%. Remained the same
11670896818

push

github

zorbathut
Removed redundant namespaces

4564 of 5040 relevant lines covered (90.56%)

191694.1 hits per line

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

95.83
/src/ReaderXmlRecorder.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Xml.Linq;
5

6
namespace Dec
7
{
8
    internal class ReaderFileRecorderXml : ReaderFileRecorder
9
    {
10
        private XElement record;
11
        private string fileIdentifier;
12
        private Recorder.IUserSettings userSettings;
13

14
        public static ReaderFileRecorderXml Create(string input, string identifier, Recorder.IUserSettings userSettings)
15
        {
2,495✔
16
            XDocument doc = UtilXml.ParseSafely(new System.IO.StringReader(input));
2,495✔
17
            if (doc == null)
2,495✔
18
            {
15✔
19
                return null;
15✔
20
            }
21

22
            if (doc.Elements().Count() > 1)
2,480✔
23
            {
×
24
                // This isn't testable, unfortunately; XDocument doesn't even support multiple root elements.
25
                Dbg.Err($"{identifier}: Found {doc.Elements().Count()} root elements instead of the expected 1");
×
26
            }
×
27

28
            var record = doc.Elements().First();
2,480✔
29
            if (record.Name.LocalName != "Record")
2,480✔
30
            {
5✔
31
                Dbg.Wrn($"{new InputContext(identifier, record)}: Found root element with name `{record.Name.LocalName}` when it should be `Record`");
5✔
32
            }
5✔
33

34
            var recordFormatVersion = record.ElementNamed("recordFormatVersion");
2,480✔
35
            if (recordFormatVersion == null)
2,480✔
36
            {
10✔
37
                Dbg.Err($"{new InputContext(identifier, record)}: Missing record format version, assuming the data is up-to-date");
10✔
38
            }
10✔
39
            else if (recordFormatVersion.GetText() != "1")
2,470✔
40
            {
15✔
41
                Dbg.Err($"{new InputContext(identifier, recordFormatVersion)}: Unknown record format version {recordFormatVersion.GetText()}, expected 1 or earlier");
15✔
42

43
                // I would rather not guess about this
44
                return null;
15✔
45
            }
46

47
            var result = new ReaderFileRecorderXml();
2,465✔
48
            result.record = record;
2,465✔
49
            result.fileIdentifier = identifier;
2,465✔
50
            result.userSettings = userSettings;
2,465✔
51

52
            return result;
2,465✔
53
        }
2,495✔
54

55
        public override List<ReaderRef> ParseRefs()
56
        {
2,465✔
57
            var result = new List<ReaderRef>();
2,465✔
58

59
            var refs = record.ElementNamed("refs");
2,465✔
60
            if (refs != null)
2,465✔
61
            {
975✔
62
                foreach (var reference in refs.Elements())
416,225✔
63
                {
206,650✔
64
                    var readerRef = new ReaderRef();
206,650✔
65

66
                    var context = new InputContext(fileIdentifier, reference);
206,650✔
67

68
                    if (reference.Name.LocalName != "Ref")
206,650✔
69
                    {
5✔
70
                        Dbg.Wrn($"{context}: Reference element should be named 'Ref'");
5✔
71
                    }
5✔
72

73
                    readerRef.id = reference.Attribute("id")?.Value;
206,650✔
74
                    if (readerRef.id == null)
206,650✔
75
                    {
5✔
76
                        Dbg.Err($"{context}: Missing reference ID");
5✔
77
                        continue;
5✔
78
                    }
79

80
                    // Further steps don't know how to deal with this, so we just strip it
81
                    reference.Attribute("id").Remove();
206,645✔
82

83
                    var className = reference.Attribute("class")?.Value;
206,645✔
84
                    if (className == null)
206,645✔
85
                    {
5✔
86
                        Dbg.Err($"{context}: Missing reference class name");
5✔
87
                        continue;
5✔
88
                    }
89

90
                    readerRef.type = (Type)Serialization.ParseString(className, typeof(Type), null, context);
206,640✔
91
                    if (readerRef.type.IsValueType)
206,640✔
92
                    {
5✔
93
                        Dbg.Err($"{context}: Reference assigned type {readerRef.type}, which is a value type");
5✔
94
                        continue;
5✔
95
                    }
96

97
                    readerRef.node = new ReaderNodeXml(reference, fileIdentifier, userSettings);
206,635✔
98
                    result.Add(readerRef);
206,635✔
99
                }
206,635✔
100
            }
975✔
101

102
            return result;
2,465✔
103
        }
2,465✔
104

105
        public override ReaderNodeParseable ParseNode()
106
        {
2,465✔
107
            var data = record.ElementNamed("data");
2,465✔
108
            if (data == null)
2,465✔
109
            {
5✔
110
                Dbg.Err($"{new InputContext(fileIdentifier, record)}: No data element provided. This is not very recoverable.");
5✔
111

112
                return null;
5✔
113
            }
114

115
            return new ReaderNodeXml(data, fileIdentifier, userSettings);
2,460✔
116
        }
2,465✔
117
    }
118
}
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

© 2026 Coveralls, Inc