Skip to content

Commit 18988aa

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

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/NHibernate.Test/DynamicProxyTests/LazyFieldInterceptorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void LazyFieldInterceptorIsBinarySerializable()
3535
var fieldInterceptionProxy = (IFieldInterceptorAccessor)pf.GetFieldInterceptionProxy(new MyClass());
3636
fieldInterceptionProxy.FieldInterceptor = new DefaultFieldInterceptor(null, null, null, "MyClass", typeof(MyClass));
3737

38-
Assert.That(fieldInterceptionProxy, Is.BinarySerializable);
38+
NHAssert.IsSerializable(fieldInterceptionProxy);
3939
}
4040

4141

src/NHibernate.Test/NHAssert.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ public static void IsSerializable(object obj)
5353

5454
public static void IsSerializable(object obj, string message, params object[] args)
5555
{
56-
Assert.That(obj, Is.BinarySerializable, message, args);
56+
bool succeeded = false;
57+
var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
58+
var stream = new System.IO.MemoryStream();
59+
try
60+
{
61+
serializer.Serialize(stream, obj);
62+
63+
stream.Seek(0, System.IO.SeekOrigin.Begin);
64+
65+
succeeded = serializer.Deserialize(stream) != null;
66+
}
67+
catch (System.Runtime.Serialization.SerializationException)
68+
{
69+
// Ignore and return failure
70+
succeeded = false;
71+
}
72+
Assert.That(succeeded, message ?? $"Supplied Type {obj.GetType()} is not serializable", args);
5773
}
5874

5975
#endregion
@@ -72,4 +88,4 @@ public static void IsSerializable(object obj, string message, params object[] ar
7288
return result;
7389
}
7490
}
75-
}
91+
}

0 commit comments

Comments
 (0)