public void ReadWriteFile() { var target = new ConcreteObject("Tom"); var serializer = new DataContractXmlSerializer <ConcreteObject>(Path.GetTempFileName()); serializer.Write(target); var deserialized = serializer.Read(); Assert.AreEqual(target.Name, deserialized.Name); }
public void SerializeToStreamSerializesCorrectly() { var serializer = new DataContractXmlSerializer(); using (var stream = new MemoryStream()) { serializer.SerializeToStream(stream, _expectedItem, typeof(TypeForXmlSerializer)); using (var streamReader = new StreamReader(stream)) { stream.Seek(0, SeekOrigin.Begin); var xml = streamReader.ReadToEnd(); xml.Should().Be(_expectedStreamXml); } } }
public void NoDefaultConstructor() { var shared = new SharedObject(); var target = new Constructorless(shared, new ConcreteObject("John"), "George", "Ringo"); var serializedResult = DataContractXmlSerializer <Constructorless> .ToString(target); Assert.IsNotNull(serializedResult); var deserializedResult = DataContractXmlSerializer <Constructorless> .FromString(serializedResult); deserializedResult.Initialize(shared); Assert.AreEqual("George", deserializedResult.ReadonlyName); Assert.AreEqual("Ringo", deserializedResult.Name); //Assert.AreEqual("John", deserializedResult.AbstractObject.Name); }
public void DeserializeFromStreamDeserializesCorrectly() { var serializer = new DataContractXmlSerializer(); TypeForXmlSerializer item; using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream, new UTF8Encoding(false, true), 1024, true)) { writer.Write(_expectedXmlFormat, _streamHeader); } stream.Seek(0, SeekOrigin.Begin); item = serializer.DeserializeFromStream(stream, typeof(TypeForXmlSerializer)) as TypeForXmlSerializer; } item.Should().NotBeNull(); item.Should().BeEquivalentTo(_expectedItem); }