-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
WithUnknownContent().Continue
to account for complex content
- Loading branch information
1 parent
a5b42a0
commit dace883
Showing
2 changed files
with
108 additions
and
0 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
95 changes: 95 additions & 0 deletions
95
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue521Tests.cs
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,95 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue521Tests | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
const string document = | ||
@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<Issue521Tests-Test> | ||
<Value1>11</Value1> | ||
<Item1> | ||
<Value>1</Value> | ||
</Item1> | ||
<Value2>22</Value2> | ||
</Issue521Tests-Test>"; | ||
|
||
var serializer = new ConfigurationContainer().EnableImplicitTyping(typeof(Test)) | ||
.WithUnknownContent() | ||
.Continue() | ||
//.Call(_ => Console.WriteLine("Unknown content: " + _.Name)) | ||
.Create(); | ||
var instance = serializer.Deserialize<Test>(document); | ||
instance.Value2.Should().Be(22); | ||
} | ||
|
||
[Fact] | ||
public void VerifyComprehensive() | ||
{ | ||
const string document = | ||
@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<Issue521Tests-Test> | ||
<Value1>11</Value1> | ||
<Item1> | ||
<Value>1</Value> | ||
</Item1> | ||
<Value2>22</Value2> | ||
<Items2> | ||
<Capacity>4</Capacity> | ||
<int xmlns=""https://extendedxmlserializer.github.io/system"">1</int> | ||
<int xmlns=""https://extendedxmlserializer.github.io/system"">2</int> | ||
<int xmlns=""https://extendedxmlserializer.github.io/system"">3</int> | ||
</Items2> | ||
<Value3>33</Value3> | ||
<Items3> | ||
<Capacity>4</Capacity> | ||
<Item> | ||
<Value>1</Value> | ||
</Item> | ||
<Item> | ||
<Value>2</Value> | ||
</Item> | ||
<Item> | ||
<Value>3</Value> | ||
</Item> | ||
</Items3> | ||
<Value4>44</Value4> | ||
</Issue521Tests-Test>"; | ||
|
||
var serializer = new ConfigurationContainer().EnableImplicitTyping(typeof(Test), typeof(Item)) | ||
.WithUnknownContent() | ||
.Continue() | ||
//.Call(_ => Console.WriteLine("Unknown content: " + _.Name)) | ||
.Create(); | ||
var instance = serializer.Deserialize<Test>(document); | ||
instance.Value2.Should().Be(22); | ||
instance.Value3.Should().Be(33); | ||
instance.Value4.Should().Be(44); | ||
} | ||
|
||
public class Test | ||
{ | ||
public int Value1 { get; set; } | ||
|
||
//public Item Item1 { get; set; } | ||
public int Value2 { get; set; } | ||
|
||
//public List<int> Items2 { get; set; } | ||
public int Value3 { get; set; } | ||
|
||
//public List<Item> Items3 { get; set; } | ||
public int Value4 { get; set; } | ||
} | ||
|
||
public class Item | ||
{ | ||
public int Value { get; set; } | ||
} | ||
} | ||
} |