Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e6512ad

Browse files
sepidehkhstephentoub
authored andcommitted
Fix Xml.Linq test failures on ILC (#19860)
* Fix Xml.Linq.XNodeBuilder.Tests failures on ILC * Fix Xml.Linq tests that need metadata
1 parent 8a197f8 commit e6512ad

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
2+
<Library>
3+
<!-- Needed because of XCData instance in [Theory] data which causes xunit to reflect on its ToString() -->
4+
<Type Name="System.Xml.Linq.XCData" Dynamic="Required Public" />
5+
</Library>
6+
</Directives>

src/System.Private.Xml.Linq/tests/events/System.Xml.Linq.Events.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
</ProjectReference>
2222
<ProjectReference Include="..\XDocument.Test.ModuleCore\XDocument.Test.ModuleCore.csproj" />
2323
</ItemGroup>
24+
25+
<ItemGroup>
26+
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
27+
</ItemGroup>
2428
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
2529
</Project>

src/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,12 +3413,14 @@ public void WriteCDataWithTwoClosingBrackets_5()
34133413
w.WriteEndElement();
34143414
}
34153415

3416-
string expectedMsg = "Cannot have ']]>' inside an XML CDATA block.";
3417-
34183416
using (XmlReader reader = doc.CreateReader())
34193417
{
34203418
Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml());
3421-
Assert.Equal(expectedMsg, exception.Message);
3419+
if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages
3420+
{
3421+
string expectedMsg = "Cannot have ']]>' inside an XML CDATA block.";
3422+
Assert.Equal(expectedMsg, exception.Message);
3423+
}
34223424
}
34233425
}
34243426

@@ -3605,12 +3607,14 @@ public void WriteCommentWithDoubleHyphensInValue()
36053607
w.WriteEndElement();
36063608
}
36073609

3608-
string expectedMsg = "An XML comment cannot contain '--', and '-' cannot be the last character.";
3609-
36103610
using (XmlReader reader = doc.CreateReader())
36113611
{
36123612
Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml());
3613-
Assert.Equal(expectedMsg, exception.Message);
3613+
if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages
3614+
{
3615+
string expectedMsg = "An XML comment cannot contain '--', and '-' cannot be the last character.";
3616+
Assert.Equal(expectedMsg, exception.Message);
3617+
}
36143618
}
36153619
}
36163620
}
@@ -4206,12 +4210,14 @@ public void IncludePIEndTagAsPartOfTextValue()
42064210
w.WriteEndElement();
42074211
}
42084212

4209-
string expectedMsg = "Cannot have '?>' inside an XML processing instruction.";
4210-
42114213
using (XmlReader reader = doc.CreateReader())
42124214
{
42134215
Exception exception = Assert.Throws<ArgumentException>(() => MoveToFirstElement(reader).ReadOuterXml());
4214-
Assert.Equal(expectedMsg, exception.Message);
4216+
if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages
4217+
{
4218+
string expectedMsg = "Cannot have '?>' inside an XML processing instruction.";
4219+
Assert.Equal(expectedMsg, exception.Message);
4220+
}
42154221
}
42164222
}
42174223

src/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<Compile Include="$(CommonTestPath)\System\Collections\DictionaryExtensions.cs">
1414
<Link>Common\System\Collections\DictionaryExtensions.cs</Link>
1515
</Compile>
16+
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
17+
<Link>Common\System\PlatformDetection.cs</Link>
18+
</Compile>
1619
<Compile Include="CommonTests.cs" />
1720
<Compile Include="EndOfLineHandlingTests.cs" />
1821
<Compile Include="ErrorConditions.cs" />

0 commit comments

Comments
 (0)