public void VerifyAssemblyNameExSerializationWithRemappedFrom()
        {
            AssemblyNameExtension assemblyNameOriginal = new AssemblyNameExtension("System.Xml, Version=10.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");
            AssemblyNameExtension assemblyRemappedFrom = new AssemblyNameExtension("System.Xml, Version=9.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");

            assemblyRemappedFrom.MarkImmutable();
            assemblyNameOriginal.AddRemappedAssemblyName(assemblyRemappedFrom);
            assemblyNameOriginal.RemappedFromEnumerator.Count().ShouldBe(1);

            AssemblyNameExtension assemblyNameDeserialized;

            byte[] bytes;

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(ms, assemblyNameOriginal);

                bytes = ms.ToArray();
            }

            using (MemoryStream ms = new MemoryStream(bytes))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                assemblyNameDeserialized = (AssemblyNameExtension)formatter.Deserialize(ms);
            }

            assemblyNameDeserialized.Equals(assemblyNameOriginal).ShouldBeTrue();
            assemblyNameDeserialized.RemappedFromEnumerator.Count().ShouldBe(1);
            assemblyNameDeserialized.RemappedFromEnumerator.First().ShouldBe(assemblyRemappedFrom);
        }
Пример #2
0
        public void VerifyAssemblyNameExSerializationWithRemappedFromByTranslator()
        {
            AssemblyNameExtension assemblyNameOriginal = new AssemblyNameExtension("System.Xml, Version=10.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");
            AssemblyNameExtension assemblyRemappedFrom = new AssemblyNameExtension("System.Xml, Version=9.0.0.0, Culture=en, PublicKeyToken=b03f5f7f11d50a3a");

            assemblyRemappedFrom.MarkImmutable();
            assemblyNameOriginal.AddRemappedAssemblyName(assemblyRemappedFrom);
            assemblyNameOriginal.RemappedFromEnumerator.Count().ShouldBe(1);

            AssemblyNameExtension assemblyNameDeserialized = null;

            MemoryStream serializationStream = new MemoryStream();
            ITranslator  writeTranslator     = BinaryTranslator.GetWriteTranslator(serializationStream);

            writeTranslator.Translate(ref assemblyNameOriginal, (ITranslator t) => new AssemblyNameExtension(t));

            serializationStream.Seek(0, SeekOrigin.Begin);
            ITranslator readTranslator = BinaryTranslator.GetReadTranslator(serializationStream, null);

            readTranslator.Translate(ref assemblyNameDeserialized, (ITranslator t) => new AssemblyNameExtension(t));

            assemblyNameDeserialized.Equals(assemblyNameOriginal).ShouldBeTrue();
            assemblyNameDeserialized.RemappedFromEnumerator.Count().ShouldBe(1);
            assemblyNameDeserialized.RemappedFromEnumerator.First().ShouldBe(assemblyRemappedFrom);
        }