Skip to content

Commit

Permalink
We can run XML, Serilog, and NLog tests on .NET Core 2+
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed May 13, 2020
1 parent 4004b32 commit a2b1bc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/Castle.Core.Tests/Castle.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
<StartupObject>Program</StartupObject>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp2.1' or '$(TargetFramework)'=='netcoreapp3.1'">
<Compile Remove="Components.DictionaryAdapter.Tests\Xml\**" />
<Compile Remove="Services.Logging.Tests\log4netIntegration\**" />
<Compile Remove="Services.Logging.Tests\NLogIntegration\**" />
</ItemGroup>

<ItemGroup>
<None Update="Services.Logging.Tests\log4netIntegration\log4net.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,22 @@ public void Single_Roundtrip()
[Test]
public void Double_Roundtrip()
{
TestSimpleSerializer(3.1337E+16D, "3.1337E+16");
TestSimpleSerializer(3.1337E+16D, "3.1337E+16", "31337000000000000");
// NOTE: This test will allow 2 different roundtrip results due to
// some roundtripping changes introduced in .NET Core 3.0. See:
//
// https://devblogs.microsoft.com/dotnet/floating-point-parsing-and-formatting-improvements-in-net-core-3-0/
//
// This test will cause a `double.ToString("R")` to be executed
// inside `XmlConvert`; the above article says the following:
//
// "For ToString("R"), there is no mechanism to fallback
// to the old behavior. The previous behavior would first try
// 'G15' and then using the internal buffer would see if it
// roundtrips; if that failed, it would instead return 'G17'."
//
// So there is no straightforward way to get roundtripping to work
// the same way on .NET Framework / .NET Core 2.x, and .NET Core 3.x.
}

[Test]
Expand Down Expand Up @@ -152,21 +167,21 @@ public void Uri_Roundtrip()
[Test]
public void Dynamic_Roundtrip()
{
TestSimpleSerializer(42, "42", typeof(object));
TestSimpleSerializer(42, new[] { "42" }, typeof(object));
}

private void TestSimpleSerializer(object value, string text)
private void TestSimpleSerializer(object value, params string[] texts)
{
TestSimpleSerializer(value, text, value.GetType());
TestSimpleSerializer(value, texts, value.GetType());
}

private void TestSimpleSerializer(object value, string text, Type serializerType)
private void TestSimpleSerializer(object value, string[] texts, Type serializerType)
{
var serializer = XmlTypeSerializerCache.Instance[serializerType];
var node = new DummyXmlNode(value.GetType());

serializer.SetValue(node, null, null, null, ref value);
Assert.AreEqual(text, node.Value);
Assert.Contains(node.Value, texts);

var actual = serializer.GetValue(node, null, null);
Assert.AreEqual(value, actual);
Expand Down

0 comments on commit a2b1bc2

Please sign in to comment.