Skip to content

Commit 818e0a9

Browse files
Simplify ReadXml and update test to proof settings are only added to appropriate package
1 parent a08196a commit 818e0a9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/NUnitEngine/nunit.engine.api/TestPackage.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ public XmlSchema GetSchema()
152152
/// <inheritdoc />
153153
public void ReadXml(XmlReader xmlReader)
154154
{
155-
var currentPackage = this;
156-
currentPackage.ID = xmlReader.GetAttribute("id");
157-
currentPackage.FullName = xmlReader.GetAttribute("fullname");
155+
ID = xmlReader.GetAttribute("id");
156+
FullName = xmlReader.GetAttribute("fullname");
158157
if (!xmlReader.IsEmptyElement)
159158
{
160159
while (xmlReader.Read())
@@ -168,14 +167,14 @@ public void ReadXml(XmlReader xmlReader)
168167
// We don't use AddSettings, which copies settings downward.
169168
// Instead, each package handles it's own settings.
170169
while (xmlReader.MoveToNextAttribute())
171-
currentPackage.Settings.Add(xmlReader.Name, xmlReader.Value);
170+
Settings.Add(xmlReader.Name, xmlReader.Value);
172171
xmlReader.MoveToElement();
173172
break;
174173

175174
case "TestPackage":
176175
TestPackage subPackage = new TestPackage();
177176
subPackage.ReadXml(xmlReader);
178-
currentPackage.SubPackages.Add(subPackage);
177+
SubPackages.Add(subPackage);
179178
break;
180179
}
181180
break;

src/NUnitEngine/nunit.engine.core.tests/Internal/TestPackageSerializationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ public class TestPackageSerializationTests
1717

1818
static TestPackageSerializationTests()
1919
{
20-
TEST_PACKAGE = new TestPackage(new string[] { "mock-assembly.dll", "notest-assembly.dll" });
20+
TEST_PACKAGE = new TestPackage(new string[] { ASSEMBLY_1, ASSEMBLY_2 });
2121
TEST_PACKAGE.AddSetting("foo", "bar");
22+
TEST_PACKAGE.SubPackages[0].AddSetting("cpu", "x86");
2223

2324
TEST_PACKAGE_XML =
2425
$"<TestPackage id=\"{TEST_PACKAGE.ID}\"><Settings foo=\"bar\" />" +
25-
$"<TestPackage id=\"{TEST_PACKAGE.SubPackages[0].ID}\" fullname=\"{Path.GetFullPath(ASSEMBLY_1)}\"><Settings foo=\"bar\" /></TestPackage>" +
26+
$"<TestPackage id=\"{TEST_PACKAGE.SubPackages[0].ID}\" fullname=\"{Path.GetFullPath(ASSEMBLY_1)}\"><Settings foo=\"bar\" cpu=\"x86\" /></TestPackage>" +
2627
$"<TestPackage id=\"{TEST_PACKAGE.SubPackages[1].ID}\" fullname=\"{Path.GetFullPath(ASSEMBLY_2)}\"><Settings foo=\"bar\" /></TestPackage>" +
2728
"</TestPackage>";
2829

0 commit comments

Comments
 (0)