Skip to content

Commit

Permalink
WIP #20.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Sep 10, 2018
1 parent 2b8c330 commit b4e9b3e
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions Gu.Xml.Tests/XmlTests.SerializeWithDataContractAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
namespace Gu.Xml.Tests
{
using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using NUnit.Framework;

public partial class XmlTests
{
public class SerializeWithDataContractAttributes
{
private static readonly TestCaseData[] Values =
{
new TestCaseData(new WithDataContractAttribute { Value = 1 }),
new TestCaseData(new WithDataContractAttributeExplicitName { Value = 1 }),
new TestCaseData(new PropertyWithIgnoreDataMemberAttribute { Value = 1 }),
new TestCaseData(new PropertyWithDataMemberAttribute { Value = 1 }),
new TestCaseData(new PropertyWithDataMemberAttributeExplicitName { Value = 1 }),
new TestCaseData(new ExplicitInterfaceWithDataMemberAttribute()),
new TestCaseData(new FieldWithIgnoreDataMemberAttribute { Value = 1 }),
new TestCaseData(new FieldWithDataMemberAttribute { Value = 1 }),
new TestCaseData(new FieldWithDataMemberAttributeExplicitName { Value = 1 }),
};

[TestCaseSource(nameof(Values))]
public void Serialize(object value)
{
var expected = Reference.DataContractSerializer(value);
var actual = Xml.Serialize(value);
if (actual == expected)
{
if (Debugger.IsAttached)
{
Console.WriteLine(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);
}

[DataContract]
public class WithDataContractAttribute
{
public int Value { get; set; } = 1;
}

[DataContract(Name = "Name")]
public class WithDataContractAttributeExplicitName
{
public int Value { get; set; } = 1;
}

public class PropertyWithDataMemberAttribute
{
[DataMember]
public int Value { get; set; }
}

public class PropertyWithDataMemberAttributeExplicitName
{
[DataMember(Name = "Name")]
public int Value { get; set; }
}

public class FieldWithDataMemberAttribute
{
[DataMember]
public int Value = 1;
}

public class FieldWithDataMemberAttributeExplicitName
{
[DataMember(Name = "Name")]
public int Value = 1;
}

public interface IValue
{
// ReSharper disable once UnusedMember.Global
int Value { get; set; }
}

public class ExplicitInterfaceWithDataMemberAttribute : IValue
{
[DataMember]
int IValue.Value { get; set; }
}

public class PropertyWithIgnoreDataMemberAttribute
{
[IgnoreDataMember]
public int Value { get; set; }
}

public class FieldWithIgnoreDataMemberAttribute
{
[IgnoreDataMember]
public int Value { get; set; }
}
}
}
}

0 comments on commit b4e9b3e

Please sign in to comment.