public void EmailPackageSerialiser_CanSerialiseAndDeserialiseIntoEqualObject() { EmailPackageSerialiser serialiser = new EmailPackageSerialiser(); var package = serialiser.Deserialize(File.ReadAllText("SampleEmailPackage.xml")); var serialised = serialiser.Serialise(package); var deserialised = serialiser.Deserialize(serialised); foreach (var propertyInfo in typeof(EmailPackage).GetProperties()) { object expected = propertyInfo.GetValue(package, null); object actual = propertyInfo.GetValue(deserialised, null); Assert.AreEqual(expected, actual); } }
public void EmailPackageSerialiser_Serialisation_CanSerialiseAnEmailPackage() { EmailPackageSerialiser serialiser = new EmailPackageSerialiser(); EmailPackage package = Helpers.SamplePackage(); string serialised = serialiser.Serialise(package); string jgnamespace = "http://www.tanash.net/email/package"; XDocument doc = XDocument.Parse(serialised); var serialisedPackage = doc.Element(XName.Get("emailPackage", jgnamespace)); Assert.That(serialisedPackage.Element(XName.Get("from", jgnamespace)).Value, Is.EqualTo(package.From)); Assert.That(serialisedPackage.Element(XName.Get("subject", jgnamespace)).Value, Is.EqualTo(package.Subject)); Assert.That(serialisedPackage.Element(XName.Get("html", jgnamespace)).Value, Is.EqualTo(package.Html)); Assert.That(serialisedPackage.Element(XName.Get("text", jgnamespace)).Value, Is.EqualTo(package.Text)); Assert.That(serialisedPackage .Element(XName.Get("recipients", jgnamespace)) .Elements(XName.Get("address", jgnamespace)).ToList(), Has.Count.EqualTo(1)); Assert.That(serialisedPackage .Element(XName.Get("attachments", jgnamespace)) .Elements(XName.Get("attachment", jgnamespace)).ToList(), Has.Count.EqualTo(1)); }