Skip to content

Commit d83ab6a

Browse files
committed
NH-3807 - Replace Is.IsXmlSerializable usage.
Is.IsXmlSerializable is not available in .netstandard version of NUnit, so perform serialization check manually.
1 parent 18988aa commit d83ab6a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/NHibernate.Test/MappingTest/NonReflectiveBinderFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void XmlSerialization()
191191
using (Stream stream = GetType().Assembly.GetManifestResourceStream("NHibernate.Test.MappingTest.Wicked.hbm.xml"))
192192
{
193193
HbmMapping mapping = mdp.Parse(stream);
194-
Assert.That(mapping, Is.XmlSerializable);
194+
NHAssert.IsXmlSerializable(mapping);
195195
}
196196
}
197197
}

src/NHibernate.Test/NHAssert.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ public static void IsSerializable(object obj, string message, params object[] ar
7272
Assert.That(succeeded, message ?? $"Supplied Type {obj.GetType()} is not serializable", args);
7373
}
7474

75+
public static void IsXmlSerializable(object obj)
76+
{
77+
IsXmlSerializable(obj, null, null);
78+
}
79+
80+
public static void IsXmlSerializable(object obj, string message, params object[] args)
81+
{
82+
if (obj == null) throw new ArgumentNullException(nameof(obj));
83+
84+
bool succeeded = false;
85+
var serializer = new System.Xml.Serialization.XmlSerializer(obj.GetType());
86+
var stream = new System.IO.MemoryStream();
87+
try
88+
{
89+
serializer.Serialize(stream, obj);
90+
91+
stream.Seek(0, System.IO.SeekOrigin.Begin);
92+
93+
succeeded = serializer.Deserialize(stream) != null;
94+
}
95+
catch (System.Runtime.Serialization.SerializationException)
96+
{
97+
// Ignore and return failure
98+
succeeded = false;
99+
}
100+
Assert.That(succeeded, message ?? $"Supplied Type {obj.GetType()} is not serializable", args);
101+
}
102+
75103
#endregion
76104
private static IEnumerable<System.Type> ClassList(Assembly assembly, System.Type type)
77105
{

0 commit comments

Comments
 (0)