-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test serialize with inheritance. Fix #15.
- Loading branch information
1 parent
e064b51
commit 699c4bd
Showing
3 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace Gu.Xml.Tests | ||
{ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
public partial class XmlTests | ||
{ | ||
public class SerializeCollections | ||
{ | ||
private static readonly TestCaseData[] Values = | ||
{ | ||
new TestCaseData(new[] { 1, 2, 3 }), | ||
new TestCaseData(new[] { new Foo(1), new Foo(2), new Foo(3) }), | ||
new TestCaseData(new List<int> { 1, 2, 3 }), | ||
new TestCaseData(new List<Foo> { new Foo(1), new Foo(2), new Foo(3) }), | ||
new TestCaseData(new Dictionary<int, string> { { 1, "a" }, { 2, "b" } }), | ||
new TestCaseData(new ArrayList { 1, 2, 3 }), | ||
}; | ||
|
||
[TestCaseSource(nameof(Values))] | ||
public void Serialize(object value) | ||
{ | ||
var expected = Reference.Xml(value); | ||
var actual = Xml.Serialize(value); | ||
if (actual == expected) | ||
{ | ||
return; | ||
} | ||
|
||
Console.WriteLine("Expected:"); | ||
Console.Write(expected); | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
|
||
Console.WriteLine("Actual:"); | ||
Console.Write(actual); | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
public class Foo | ||
{ | ||
// ReSharper disable once UnusedMember.Local for XmlSerializer | ||
private Foo() | ||
{ | ||
} | ||
|
||
public Foo(int value) | ||
{ | ||
this.Value = value; | ||
} | ||
|
||
public int Value { get; } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters