diff --git a/src/Common/tests/System/Runtime/Serialization/Formatters/BinaryFormatterHelpers.cs b/src/Common/tests/System/Runtime/Serialization/Formatters/BinaryFormatterHelpers.cs index e7d0bb1433f2..95d382c7c1d0 100644 --- a/src/Common/tests/System/Runtime/Serialization/Formatters/BinaryFormatterHelpers.cs +++ b/src/Common/tests/System/Runtime/Serialization/Formatters/BinaryFormatterHelpers.cs @@ -71,5 +71,42 @@ public static void AssertRoundtrips(T expected, params Func[] addi } } } + + public static byte[] ToByteArray(object obj, + FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Full) + { + BinaryFormatter bf = new BinaryFormatter(); + bf.AssemblyFormat = assemblyStyle; + using (MemoryStream ms = new MemoryStream()) + { + bf.Serialize(ms, obj); + return ms.ToArray(); + } + } + + public static string ToBase64String(object obj, + FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Full) + { + byte[] raw = ToByteArray(obj, assemblyStyle); + return Convert.ToBase64String(raw); + } + + public static object FromByteArray(byte[] raw, + FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Full) + { + var binaryFormatter = new BinaryFormatter(); + binaryFormatter.AssemblyFormat = assemblyStyle; + using (var serializedStream = new MemoryStream(raw)) + { + return binaryFormatter.Deserialize(serializedStream); + } + } + + public static object FromBase64String(string base64Str, + FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Full) + { + byte[] raw = Convert.FromBase64String(base64Str); + return FromByteArray(raw, assemblyStyle); + } } } diff --git a/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs b/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs index 001ba69dc2e9..89d34a692afc 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs +++ b/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Text; +using System.Text.RegularExpressions; using Xunit; namespace System.Runtime.Serialization.Formatters.Tests @@ -21,8 +22,9 @@ public partial class BinaryFormatterTests : RemoteExecutorTestBase [MemberData(nameof(BasicObjectsRoundtrip_MemberData))] public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat) { - object clone = FormatterClone(obj, null, assemblyFormat, filterLevel, typeFormat); - if (!ReferenceEquals(obj, string.Empty) && !(obj is DBNull)) // "" is interned and will roundtrip as the same object + object clone = BinaryFormatterHelpers.Clone(obj, null, assemblyFormat, filterLevel, typeFormat); + // string.Empty and DBNull are both singletons + if (!ReferenceEquals(obj, string.Empty) && !(obj is DBNull)) { Assert.NotSame(obj, clone); } @@ -35,8 +37,10 @@ public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle ass public void UpdateBlobs() { string testDataFilePath = GetTestDataFilePath(); - IEnumerable coreTypeRecords = GetCoreTypeRecords(); - string[] coreTypeBlobs = GetCoreTypeBlobs(coreTypeRecords, FormatterAssemblyStyle.Full).ToArray(); + string[] coreTypeBlobs = SerializableEqualityComparers_MemberData() + .Concat(SerializableObjects_MemberData()) + .Select(record => BinaryFormatterHelpers.ToBase64String(record[0])) + .ToArray(); var (numberOfBlobs, numberOfFoundBlobs, numberOfUpdatedBlobs) = UpdateCoreTypeBlobs(testDataFilePath, coreTypeBlobs); Console.WriteLine($"{numberOfBlobs} existing blobs" + @@ -46,7 +50,15 @@ public void UpdateBlobs() [Theory] [MemberData(nameof(SerializableObjects_MemberData))] - public void ValidateAgainstBlobs(object obj, string[] blobs) + public void ValidateAgainstBlobs(object obj, string[] blobs) + => ValidateAndRoundtrip(obj, blobs, false); + + [Theory] + [MemberData(nameof(SerializableEqualityComparers_MemberData))] + public void ValidateEqualityComparersAgainstBlobs(object obj, string[] blobs) + => ValidateAndRoundtrip(obj, blobs, true); + + private static void ValidateAndRoundtrip(object obj, string[] blobs, bool isEqualityComparer) { if (obj == null) { @@ -56,7 +68,7 @@ public void ValidateAgainstBlobs(object obj, string[] blobs) if (blobs == null || blobs.Length == 0) { throw new ArgumentOutOfRangeException($"Type {obj} has no blobs to deserialize and test equality against. Blob: " + - SerializeObjectToBlob(obj, FormatterAssemblyStyle.Full)); + BinaryFormatterHelpers.ToBase64String(obj, FormatterAssemblyStyle.Full)); } SanityCheckBlob(obj, blobs); @@ -72,20 +84,19 @@ public void ValidateAgainstBlobs(object obj, string[] blobs) foreach (string blob in blobs) { - CheckForAnyEquals(obj, DeserializeBlobToObject(blob, FormatterAssemblyStyle.Simple)); - CheckForAnyEquals(obj, DeserializeBlobToObject(blob, FormatterAssemblyStyle.Full)); + if (isEqualityComparer) + { + ValidateEqualityComparer(BinaryFormatterHelpers.FromBase64String(blob, FormatterAssemblyStyle.Simple)); + ValidateEqualityComparer(BinaryFormatterHelpers.FromBase64String(blob, FormatterAssemblyStyle.Full)); + } + else + { + CheckForAnyEquals(obj, BinaryFormatterHelpers.FromBase64String(blob, FormatterAssemblyStyle.Simple)); + CheckForAnyEquals(obj, BinaryFormatterHelpers.FromBase64String(blob, FormatterAssemblyStyle.Full)); + } } } - [Fact] - [SkipOnTargetFramework(TargetFrameworkMonikers.Uap | TargetFrameworkMonikers.UapAot)] - public void UnitySerializationHolderWithAssemblySingleton() - { - const string UnitySerializationHolderAssemblyBase64String = "AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uVW5pdHlTZXJpYWxpemF0aW9uSG9sZGVyAwAAAAREYXRhCVVuaXR5VHlwZQxBc3NlbWJseU5hbWUBAAEIBgIAAABLbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BgAAAAkCAAAACw=="; - AssertExtensions.ThrowsIf(!PlatformDetection.IsFullFramework, - () => DeserializeBlobToObject(UnitySerializationHolderAssemblyBase64String, FormatterAssemblyStyle.Full)); - } - [Fact] public void ArraySegmentDefaultCtor() { @@ -94,8 +105,8 @@ public void ArraySegmentDefaultCtor() object obj = new ArraySegment(); string corefxBlob = "AAEAAAD/////AQAAAAAAAAAEAQAAAHJTeXN0ZW0uQXJyYXlTZWdtZW50YDFbW1N5c3RlbS5JbnQzMiwgbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5XV0DAAAABl9hcnJheQdfb2Zmc2V0Bl9jb3VudAcAAAgICAoAAAAAAAAAAAs="; string netfxBlob = "AAEAAAD/////AQAAAAAAAAAEAQAAAHJTeXN0ZW0uQXJyYXlTZWdtZW50YDFbW1N5c3RlbS5JbnQzMiwgbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5XV0DAAAABl9hcnJheQdfb2Zmc2V0Bl9jb3VudAcAAAgICAoAAAAAAAAAAAs="; - CheckForAnyEquals(obj, DeserializeBlobToObject(corefxBlob, FormatterAssemblyStyle.Full)); - CheckForAnyEquals(obj, DeserializeBlobToObject(netfxBlob, FormatterAssemblyStyle.Full)); + CheckForAnyEquals(obj, BinaryFormatterHelpers.FromBase64String(corefxBlob, FormatterAssemblyStyle.Full)); + CheckForAnyEquals(obj, BinaryFormatterHelpers.FromBase64String(netfxBlob, FormatterAssemblyStyle.Full)); } [Fact] @@ -106,7 +117,7 @@ public void ValidateDeserializationOfObjectWithDifferentAssemblyVersion() var obj = new SomeType() { SomeField = 7 }; string serializedObj = @"AAEAAAD/////AQAAAAAAAAAMAgAAAHNTeXN0ZW0uUnVudGltZS5TZXJpYWxpemF0aW9uLkZvcm1hdHRlcnMuVGVzdHMsIFZlcnNpb249OS45OC43Ljk4NywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj05ZDc3Y2M3YWQzOWI2OGViBQEAAAA2U3lzdGVtLlJ1bnRpbWUuU2VyaWFsaXphdGlvbi5Gb3JtYXR0ZXJzLlRlc3RzLlNvbWVUeXBlAQAAAAlTb21lRmllbGQACAIAAAAHAAAACw=="; - var deserialized = (SomeType)DeserializeBlobToObject(serializedObj, FormatterAssemblyStyle.Simple); + var deserialized = (SomeType)BinaryFormatterHelpers.FromBase64String(serializedObj, FormatterAssemblyStyle.Simple); Assert.Equal(obj, deserialized); } @@ -118,34 +129,10 @@ public void ValidateDeserializationOfObjectWithGenericTypeWhichGenericArgumentHa var obj = new GenericTypeWithArg() { Test = new SomeType() { SomeField = 9 } }; string serializedObj = @"AAEAAAD/////AQAAAAAAAAAMAgAAAHNTeXN0ZW0uUnVudGltZS5TZXJpYWxpemF0aW9uLkZvcm1hdHRlcnMuVGVzdHMsIFZlcnNpb249OS45OC43Ljk4NywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj05ZDc3Y2M3YWQzOWI2OGViBQEAAADxAVN5c3RlbS5SdW50aW1lLlNlcmlhbGl6YXRpb24uRm9ybWF0dGVycy5UZXN0cy5HZW5lcmljVHlwZVdpdGhBcmdgMVtbU3lzdGVtLlJ1bnRpbWUuU2VyaWFsaXphdGlvbi5Gb3JtYXR0ZXJzLlRlc3RzLlNvbWVUeXBlLCBTeXN0ZW0uUnVudGltZS5TZXJpYWxpemF0aW9uLkZvcm1hdHRlcnMuVGVzdHMsIFZlcnNpb249OS45OC43Ljk4NywgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj05ZDc3Y2M3YWQzOWI2OGViXV0BAAAABFRlc3QENlN5c3RlbS5SdW50aW1lLlNlcmlhbGl6YXRpb24uRm9ybWF0dGVycy5UZXN0cy5Tb21lVHlwZQIAAAACAAAACQMAAAAFAwAAADZTeXN0ZW0uUnVudGltZS5TZXJpYWxpemF0aW9uLkZvcm1hdHRlcnMuVGVzdHMuU29tZVR5cGUBAAAACVNvbWVGaWVsZAAIAgAAAAkAAAAL"; - var deserialized = (GenericTypeWithArg)DeserializeBlobToObject(serializedObj, FormatterAssemblyStyle.Simple); + var deserialized = (GenericTypeWithArg)BinaryFormatterHelpers.FromBase64String(serializedObj, FormatterAssemblyStyle.Simple); Assert.Equal(obj, deserialized); } - [Theory] - [MemberData(nameof(SerializableEqualityComparers_MemberData))] - public void ValidateEqualityComparersAgainstBlobs(object obj, string[] blobs) - { - if (obj == null) - { - throw new ArgumentNullException("The serializable object must not be null", nameof(obj)); - } - - if (blobs == null || blobs.Length == 0) - { - throw new ArgumentOutOfRangeException($"Type {obj} has no blobs to deserialize and test equality against. Blob: " + - SerializeObjectToBlob(obj, FormatterAssemblyStyle.Full)); - } - - SanityCheckBlob(obj, blobs); - - foreach (string blob in blobs) - { - ValidateEqualityComparer(DeserializeBlobToObject(blob, FormatterAssemblyStyle.Simple)); - ValidateEqualityComparer(DeserializeBlobToObject(blob, FormatterAssemblyStyle.Full)); - } - } - [Fact] public void RoundtripManyObjectsInOneStream() { @@ -406,7 +393,7 @@ public void ObjectReference_RealObjectSerialized() public void Deserialize_FuzzInput(object obj, Random rand) { // Get the serialized data for the object - byte[] data = SerializeObjectToRaw(obj, FormatterAssemblyStyle.Simple); + byte[] data = BinaryFormatterHelpers.ToByteArray(obj, FormatterAssemblyStyle.Simple); // Make some "random" changes to it for (int i = 1; i < rand.Next(1, 100); i++) @@ -417,7 +404,7 @@ public void Deserialize_FuzzInput(object obj, Random rand) // Try to deserialize that. try { - DeserializeRawToObject(data, FormatterAssemblyStyle.Simple); + BinaryFormatterHelpers.FromByteArray(data, FormatterAssemblyStyle.Simple); // Since there's no checksum, it's possible we changed data that didn't corrupt the instance } catch (ArgumentOutOfRangeException) { } diff --git a/src/System.Runtime.Serialization.Formatters/tests/EqualityExtensions.cs b/src/System.Runtime.Serialization.Formatters/tests/EqualityExtensions.cs index 1ca7e99e36c9..cd66be9bc8b8 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/EqualityExtensions.cs +++ b/src/System.Runtime.Serialization.Formatters/tests/EqualityExtensions.cs @@ -204,7 +204,7 @@ public static bool IsEqual(this DataSet @this, DataSet other) @this.Locale.LCID == other.Locale.LCID && @this.EnforceConstraints == other.EnforceConstraints && @this.ExtendedProperties?.Count == other.ExtendedProperties?.Count && - BinaryFormatterTests.CheckEquals(@this.ExtendedProperties, other.ExtendedProperties); + CheckEquals(@this.ExtendedProperties, other.ExtendedProperties); } public static bool IsEqual(this DataTable @this, DataTable other) @@ -267,7 +267,7 @@ public static bool IsEqual(this ArrayList @this, ArrayList other) for (int i = 0; i < @this.Count; i++) { - if (!BinaryFormatterTests.CheckEquals(@this[i], other[i])) + if (!CheckEquals(@this[i], other[i])) return false; } @@ -284,17 +284,17 @@ public static bool IsEqual(this BitArray @this, BitArray other) @this.IsSynchronized == other.IsSynchronized)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return CheckSequenceEquals(@this, other); } public static bool IsEqual(this Dictionary @this, Dictionary other) { if (!(@this != null && other != null && - BinaryFormatterTests.CheckEquals(@this.Comparer, other.Comparer) && + CheckEquals(@this.Comparer, other.Comparer) && @this.Count == other.Count && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values))) + @this.Keys.CheckSequenceEquals(other.Keys) && + @this.Values.CheckSequenceEquals(other.Values))) return false; foreach (var kv in @this) @@ -317,10 +317,10 @@ public static bool IsEqual(this HashSet @this, HashSet other) if (!(@this != null && other != null && @this.Count == other.Count && - BinaryFormatterTests.CheckEquals(@this.Comparer, other.Comparer))) + CheckEquals(@this.Comparer, other.Comparer))) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this LinkedListNode @this, LinkedListNode other) @@ -330,7 +330,7 @@ public static bool IsEqual(this LinkedListNode @this, LinkedListNode @this, LinkedList other) @@ -342,7 +342,7 @@ public static bool IsEqual(this LinkedList @this, LinkedList other IsEqual(@this.Last, other.Last))) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this List @this, List other) @@ -353,7 +353,7 @@ public static bool IsEqual(this List @this, List other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Queue @this, Queue other) @@ -363,7 +363,7 @@ public static bool IsEqual(this Queue @this, Queue other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this SortedList @this, SortedList other) @@ -371,13 +371,13 @@ public static bool IsEqual(this SortedList @this, SortedList @this, SortedSet other) @@ -385,12 +385,12 @@ public static bool IsEqual(this SortedSet @this, SortedSet other) if (!(@this != null && other != null && @this.Count == other.Count && - BinaryFormatterTests.CheckEquals(@this.Comparer, other.Comparer) && - BinaryFormatterTests.CheckEquals(@this.Min, other.Min) && - BinaryFormatterTests.CheckEquals(@this.Max, other.Max))) + CheckEquals(@this.Comparer, other.Comparer) && + CheckEquals(@this.Min, other.Min) && + CheckEquals(@this.Max, other.Max))) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Stack @this, Stack other) @@ -400,7 +400,7 @@ public static bool IsEqual(this Stack @this, Stack other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Hashtable @this, Hashtable other) @@ -410,14 +410,14 @@ public static bool IsEqual(this Hashtable @this, Hashtable other) @this.IsReadOnly == other.IsReadOnly && @this.IsFixedSize == other.IsFixedSize && @this.IsSynchronized == other.IsSynchronized && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values) && + @this.Keys.CheckSequenceEquals(other.Keys) && + @this.Values.CheckSequenceEquals(other.Values) && @this.Count == other.Count)) return false; foreach (var key in @this.Keys) { - if (!BinaryFormatterTests.CheckEquals(@this[key], other[key])) + if (!CheckEquals(@this[key], other[key])) return false; } @@ -431,7 +431,7 @@ public static bool IsEqual(this Collection @this, Collection other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this ObservableCollection @this, ObservableCollection other) @@ -441,7 +441,7 @@ public static bool IsEqual(this ObservableCollection @this, ObservableColle @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this ReadOnlyCollection @this, ReadOnlyCollection other) @@ -451,15 +451,15 @@ public static bool IsEqual(this ReadOnlyCollection @this, ReadOnlyCollectio @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this ReadOnlyDictionary @this, ReadOnlyDictionary other) { if (!(@this != null && other != null && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values) && + @this.Keys.CheckSequenceEquals(other.Keys) && + @this.Values.CheckSequenceEquals(other.Values) && @this.Count == other.Count)) return false; @@ -479,7 +479,7 @@ public static bool IsEqual(this ReadOnlyObservableCollection @this, ReadOnl @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Queue @this, Queue other) @@ -490,7 +490,7 @@ public static bool IsEqual(this Queue @this, Queue other) @this.IsSynchronized == other.IsSynchronized)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this SortedList @this, SortedList other) @@ -499,14 +499,14 @@ public static bool IsEqual(this SortedList @this, SortedList other) other != null && @this.Capacity == other.Capacity && @this.Count == other.Count && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values) && + @this.Keys.CheckSequenceEquals(other.Keys) && + @this.Values.CheckSequenceEquals(other.Values) && @this.IsReadOnly == other.IsReadOnly && @this.IsFixedSize == other.IsFixedSize && @this.IsSynchronized == other.IsSynchronized)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this HybridDictionary @this, HybridDictionary other) @@ -514,16 +514,16 @@ public static bool IsEqual(this HybridDictionary @this, HybridDictionary other) if (!(@this != null && other != null && @this.Count == other.Count && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && + @this.Keys.CheckSequenceEquals(other.Keys) && @this.IsReadOnly == other.IsReadOnly && @this.IsFixedSize == other.IsFixedSize && @this.IsSynchronized == other.IsSynchronized && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values))) + @this.Values.CheckSequenceEquals(other.Values))) return false; foreach (var key in @this.Keys) { - if (!BinaryFormatterTests.CheckEquals(@this[key], other[key])) + if (!CheckEquals(@this[key], other[key])) return false; } @@ -535,16 +535,16 @@ public static bool IsEqual(this ListDictionary @this, ListDictionary other) if (!(@this != null && other != null && @this.Count == other.Count && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && + @this.Keys.CheckSequenceEquals(other.Keys) && @this.IsReadOnly == other.IsReadOnly && @this.IsFixedSize == other.IsFixedSize && @this.IsSynchronized == other.IsSynchronized && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values))) + @this.Values.CheckSequenceEquals(other.Values))) return false; foreach (var key in @this.Keys) { - if (!BinaryFormatterTests.CheckEquals(@this[key], other[key])) + if (!CheckEquals(@this[key], other[key])) return false; } @@ -555,14 +555,14 @@ public static bool IsEqual(this NameValueCollection @this, NameValueCollection o { if (!(@this != null && other != null && - BinaryFormatterTests.CheckSequenceEquals(@this.AllKeys, other.AllKeys) && + @this.AllKeys.CheckSequenceEquals(other.AllKeys) && @this.Count == other.Count && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys))) + @this.Keys.CheckSequenceEquals(other.Keys))) return false; foreach (var key in @this.AllKeys) { - if (!BinaryFormatterTests.CheckEquals(@this[key], other[key])) + if (!CheckEquals(@this[key], other[key])) return false; } @@ -575,13 +575,13 @@ public static bool IsEqual(this OrderedDictionary @this, OrderedDictionary other other != null && @this.Count == other.Count && @this.IsReadOnly == other.IsReadOnly && - BinaryFormatterTests.CheckEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckEquals(@this.Values, other.Values))) + CheckEquals(@this.Keys, other.Keys) && + CheckEquals(@this.Values, other.Values))) return false; foreach (var key in @this.Keys) { - if (!BinaryFormatterTests.CheckEquals(@this[key], other[key])) + if (!CheckEquals(@this[key], other[key])) return false; } @@ -597,7 +597,7 @@ public static bool IsEqual(this StringCollection @this, StringCollection other) @this.IsSynchronized == other.IsSynchronized)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Stack @this, Stack other) @@ -608,7 +608,7 @@ public static bool IsEqual(this Stack @this, Stack other) @this.IsSynchronized == other.IsSynchronized)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this BindingList @this, BindingList other) @@ -622,7 +622,7 @@ public static bool IsEqual(this BindingList @this, BindingList other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this BindingList @this, BindingList other) @@ -636,7 +636,7 @@ public static bool IsEqual(this BindingList @this, BindingList oth @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this PropertyCollection @this, PropertyCollection other) @@ -646,12 +646,12 @@ public static bool IsEqual(this PropertyCollection @this, PropertyCollection oth @this.IsReadOnly == other.IsReadOnly && @this.IsFixedSize == other.IsFixedSize && @this.IsSynchronized == other.IsSynchronized && - BinaryFormatterTests.CheckSequenceEquals(@this.Keys, other.Keys) && - BinaryFormatterTests.CheckSequenceEquals(@this.Values, other.Values) && + @this.Keys.CheckSequenceEquals(other.Keys) && + @this.Values.CheckSequenceEquals(other.Values) && @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this CompareInfo @this, CompareInfo other) @@ -683,14 +683,14 @@ public static bool IsEqual(this Cookie @this, Cookie other) @this.Discard == other.Discard && @this.Domain == other.Domain && @this.Expired == other.Expired && - BinaryFormatterTests.CheckEquals(@this.Expires, other.Expires) && + CheckEquals(@this.Expires, other.Expires) && @this.Name == other.Name && @this.Path == other.Path && @this.Port == other.Port && @this.Secure == other.Secure && // This needs to have m_Timestamp set by reflection in order to roundtrip correctly // otherwise this field will change each time you create an object and cause this to fail - BinaryFormatterTests.CheckEquals(@this.TimeStamp, other.TimeStamp) && + CheckEquals(@this.TimeStamp, other.TimeStamp) && @this.Value == other.Value && @this.Version == other.Version; } @@ -702,7 +702,7 @@ public static bool IsEqual(this CookieCollection @this, CookieCollection other) @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this BasicISerializableObject @this, BasicISerializableObject other) @@ -786,7 +786,7 @@ public static bool IsEqual(this Graph @this, Graph other) return false; } - return BinaryFormatterTests.CheckEquals(thisFlattened.Item2, otherFlattened.Item2); + return CheckEquals(thisFlattened.Item2, otherFlattened.Item2); } public static bool IsEqual(this ArraySegment @this, ArraySegment other) @@ -796,19 +796,19 @@ public static bool IsEqual(this ArraySegment @this, ArraySegment other @this.Offset == other.Offset)) return false; - return @this.Array == null || BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.Array == null || @this.CheckSequenceEquals(other); } public static bool IsEqual(this ObjectWithArrays @this, ObjectWithArrays other) { return @this != null && other != null && - BinaryFormatterTests.CheckEquals(@this.IntArray, other.IntArray) && - BinaryFormatterTests.CheckEquals(@this.StringArray, other.StringArray) && - BinaryFormatterTests.CheckEquals(@this.TreeArray, other.TreeArray) && - BinaryFormatterTests.CheckEquals(@this.ByteArray, other.ByteArray) && - BinaryFormatterTests.CheckEquals(@this.JaggedArray, other.JaggedArray) && - BinaryFormatterTests.CheckEquals(@this.MultiDimensionalArray, other.MultiDimensionalArray); + CheckEquals(@this.IntArray, other.IntArray) && + CheckEquals(@this.StringArray, other.StringArray) && + CheckEquals(@this.TreeArray, other.TreeArray) && + CheckEquals(@this.ByteArray, other.ByteArray) && + CheckEquals(@this.JaggedArray, other.JaggedArray) && + CheckEquals(@this.MultiDimensionalArray, other.MultiDimensionalArray); } public static bool IsEqual(this ObjectWithIntStringUShortUIntULongAndCustomObjectFields @this, ObjectWithIntStringUShortUIntULongAndCustomObjectFields other) @@ -864,7 +864,7 @@ public static bool IsEqual(this SimpleKeyedCollection @this, SimpleKeyedCollecti @this.Count == other.Count)) return false; - return BinaryFormatterTests.CheckSequenceEquals(@this, other); + return @this.CheckSequenceEquals(other); } public static bool IsEqual(this Tree @this, Tree other) diff --git a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index 04e9000c168e..e834afe98abb 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -10,7 +10,6 @@ - diff --git a/src/System.Runtime/tests/System.Runtime.Tests.csproj b/src/System.Runtime/tests/System.Runtime.Tests.csproj index ef9c84bd3efa..36f7e279cb49 100644 --- a/src/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/System.Runtime/tests/System.Runtime.Tests.csproj @@ -110,6 +110,7 @@ + @@ -246,4 +247,4 @@ - + \ No newline at end of file diff --git a/src/System.Runtime/tests/System/UnitySerializationHolderTests.cs b/src/System.Runtime/tests/System/UnitySerializationHolderTests.cs new file mode 100644 index 000000000000..ab28b42bad17 --- /dev/null +++ b/src/System.Runtime/tests/System/UnitySerializationHolderTests.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.Serialization.Formatters.Tests; +using Xunit; + +namespace System.Tests +{ + public class UnitySerializationHolderTests + { + [Fact] + public void UnitySerializationHolderWithAssemblySingleton() + { + const string UnitySerializationHolderAssemblyBase64String = "AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uVW5pdHlTZXJpYWxpemF0aW9uSG9sZGVyAwAAAAREYXRhCVVuaXR5VHlwZQxBc3NlbWJseU5hbWUBAAEIBgIAAABLbXNjb3JsaWIsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BgAAAAkCAAAACw=="; + AssertExtensions.ThrowsIf(!PlatformDetection.IsFullFramework, + () => BinaryFormatterHelpers.FromBase64String(UnitySerializationHolderAssemblyBase64String)); + } + } +}