-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathBasicObjectTests.cs
42 lines (34 loc) · 1.6 KB
/
BasicObjectTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.Serialization.Formatters.Binary;
using BinaryFormatTests;
namespace System.Resources.Extensions.Tests.FormattedObject;
public class BasicObjectTests : Common.BasicObjectTests<FormattedObjectSerializer>
{
private protected override bool SkipOffsetArrays => true;
[Theory]
[MemberData(nameof(SerializableObjects))]
public void BasicObjectsRoundTripAndMatch(object value, TypeSerializableValue[] _)
{
// We need to round trip through the BinaryFormatter as a few objects in tests remove
// serialized data on deserialization.
BinaryFormatter formatter = new();
MemoryStream serialized = new();
formatter.Serialize(serialized, value);
serialized.Position = 0;
object bfdeserialized = formatter.Deserialize(serialized);
serialized.Position = 0;
serialized.SetLength(0);
formatter.Serialize(serialized, bfdeserialized);
serialized.Position = 0;
// Now deserialize with BinaryFormattedObject
object deserialized = Deserialize(serialized);
// And reserialize what we serialized with the BinaryFormatter
MemoryStream deserializedSerialized = new();
formatter.Serialize(deserializedSerialized, deserialized);
deserializedSerialized.Position = 0;
serialized.Position = 0;
// Now compare the two streams to ensure they are identical
Assert.Equal(serialized.Length, deserializedSerialized.Length);
}
}