A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nunit/nunit-console/commit/e5144d5e34beff0e8c8540ef79bff203923223aa below:

Merge pull request #1647 from nunit/issue-1354 · nunit/nunit-console@e5144d5 · GitHub

3 3

using System;

4 4

using System.Collections.Generic;

5 5

using System.IO;

6 +

using System.Xml.Schema;

7 +

using System.Xml;

8 +

using System.Xml.Serialization;

6 9 7 10

namespace NUnit.Engine

8 11

{

@@ -23,7 +26,7 @@ namespace NUnit.Engine

23 26

/// tests in the reloaded assembly to match those originally loaded.

24 27

/// </summary>

25 28

[Serializable]

26 -

public class TestPackage

29 +

public class TestPackage : IXmlSerializable

27 30

{

28 31

/// <summary>

29 32

/// Construct a named TestPackage, specifying a file path for

@@ -37,8 +40,6 @@ public TestPackage(string filePath)

37 40

if (filePath != null)

38 41

{

39 42

FullName = Path.GetFullPath(filePath);

40 -

Settings = new Dictionary<string,object>();

41 -

SubPackages = new List<TestPackage>();

42 43

}

43 44

}

44 45

@@ -49,16 +50,19 @@ public TestPackage(string filePath)

49 50

public TestPackage(IList<string> testFiles)

50 51

{

51 52

ID = GetNextID();

52 -

SubPackages = new List<TestPackage>();

53 -

Settings = new Dictionary<string,object>();

54 53 55 54

foreach (string testFile in testFiles)

56 55

SubPackages.Add(new TestPackage(testFile));

57 56

}

58 57 58 +

/// <summary>

59 +

/// Construct an empty TestPackage.

60 +

/// </summary>

61 +

public TestPackage() { }

62 + 59 63

private static int _nextID = 0;

60 64 61 -

private string GetNextID()

65 +

private static string GetNextID()

62 66

{

63 67

return (_nextID++).ToString();

64 68

}

@@ -75,10 +79,7 @@ private string GetNextID()

75 79

/// <summary>

76 80

/// Gets the name of the package

77 81

/// </summary>

78 -

public string Name

79 -

{

80 -

get { return FullName == null ? null : Path.GetFileName(FullName); }

81 -

}

82 +

public string Name => FullName == null ? null : Path.GetFileName(FullName);

82 83 83 84

/// <summary>

84 85

/// Gets the path to the file containing tests. It may be

@@ -89,12 +90,12 @@ public string Name

89 90

/// <summary>

90 91

/// Gets the list of SubPackages contained in this package

91 92

/// </summary>

92 -

public IList<TestPackage> SubPackages { get; private set; }

93 +

public IList<TestPackage> SubPackages { get; } = new List<TestPackage>();

93 94 94 95

/// <summary>

95 96

/// Gets the settings dictionary for this package.

96 97

/// </summary>

97 -

public IDictionary<string,object> Settings { get; private set; }

98 +

public IDictionary<string,object> Settings { get; } = new Dictionary<string,object>();

98 99 99 100

/// <summary>

100 101

/// Add a subproject to the package.

@@ -139,5 +140,87 @@ public T GetSetting<T>(string name, T defaultSetting)

139 140

? (T)Settings[name]

140 141

: defaultSetting;

141 142

}

143 + 144 +

#region IXmlSerializable Implementation

145 + 146 +

/// <inheritdoc />

147 +

public XmlSchema GetSchema()

148 +

{

149 +

return null;

150 +

}

151 + 152 +

/// <inheritdoc />

153 +

public void ReadXml(XmlReader xmlReader)

154 +

{

155 +

ID = xmlReader.GetAttribute("id");

156 +

FullName = xmlReader.GetAttribute("fullname");

157 +

if (!xmlReader.IsEmptyElement)

158 +

{

159 +

while (xmlReader.Read())

160 +

{

161 +

switch (xmlReader.NodeType)

162 +

{

163 +

case XmlNodeType.Element:

164 +

switch(xmlReader.Name)

165 +

{

166 +

case "Settings":

167 +

// We don't use AddSettings, which copies settings downward.

168 +

// Instead, each package handles it's own settings.

169 +

while (xmlReader.MoveToNextAttribute())

170 +

Settings.Add(xmlReader.Name, xmlReader.Value);

171 +

xmlReader.MoveToElement();

172 +

break;

173 + 174 +

case "TestPackage":

175 +

TestPackage subPackage = new TestPackage();

176 +

subPackage.ReadXml(xmlReader);

177 +

SubPackages.Add(subPackage);

178 +

break;

179 +

}

180 +

break;

181 + 182 +

case XmlNodeType.EndElement:

183 +

if (xmlReader.Name == "TestPackage")

184 +

return;

185 +

break;

186 + 187 +

default:

188 +

throw new Exception("Unexpected EndElement: " + xmlReader.Name);

189 +

}

190 +

}

191 + 192 +

throw new Exception("Invalid XML: TestPackage Element not terminated.");

193 +

}

194 +

}

195 + 196 +

/// <inheritdoc />

197 +

public void WriteXml(XmlWriter xmlWriter)

198 +

{

199 +

// Write ID and FullName

200 +

xmlWriter.WriteAttributeString("id", ID);

201 +

if (FullName != null)

202 +

xmlWriter.WriteAttributeString("fullname", FullName);

203 + 204 +

// Write Settings

205 +

if (Settings.Count != 0)

206 +

{

207 +

xmlWriter.WriteStartElement("Settings");

208 + 209 +

foreach (KeyValuePair<string, object> setting in Settings)

210 +

xmlWriter.WriteAttributeString(setting.Key, setting.Value.ToString());

211 + 212 +

xmlWriter.WriteEndElement();

213 +

}

214 + 215 +

// Write any SubPackages recursively

216 +

foreach (TestPackage subPackage in SubPackages)

217 +

{

218 +

xmlWriter.WriteStartElement("TestPackage");

219 +

subPackage.WriteXml(xmlWriter);

220 +

xmlWriter.WriteEndElement();

221 +

}

222 +

}

142 223

}

224 + 225 +

#endregion

143 226

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4