public void TestConnectorSerialization() { var obj = new DestinationFieldList { Id = Guid.NewGuid(), }; obj.Fields.Add(new DestinationField(null)); obj.Fields.Add(new DestinationField(null) { Subfields = { new DestinationField(null) } }); var tw = new StringWriter(); using (var xw = XmlWriter.Create(tw)) { xw.WriteStartElement("Node"); obj.Serialize(xw); xw.WriteEndElement(); } var sr = new StringReader(tw.ToString()); using (var wr = XmlReader.Create(sr)) { wr.ReadToFollowing("Node"); var result = new DestinationFieldList(); result.Deserialize(wr); Assert.AreEqual(obj.Id, result.Id); Assert.AreEqual(obj.Fields.Count, result.Fields.Count); } }
public void DeserilizationShouldExitIfXmlReaderIsOnEmptyElement() { var sr = new StringReader(string.Empty); using (var rd = XmlReader.Create(sr)) { var result = new DestinationFieldList(); Mock.Arrange(() => rd.IsEmptyElement).Returns(true); Mock.Arrange(() => rd.GetAttribute(Arg.AnyString)).Returns("0"); Mock.Arrange(() => rd.GetAttribute("id")).Returns(Guid.Empty.ToString()); result.Deserialize(rd); Mock.Assert(() => rd.Read(), Occurs.Never()); } }