public void CanDeserializeAtomFeedFromXml() { var testfeed = TestFileLoader.GetSingleAtomTestFilePath(TestFileLoader.TestFileType.FileSys); var feed = Factory.CreateFeed(new Uri(testfeed)); var serializer = new XmlSerializer(feed.GetType()); using (var filestream = new FileStream(AtomXmlFile, FileMode.Create)) { serializer.Serialize(filestream, feed); } using (var readstream = new FileStream(AtomXmlFile, FileMode.Open)) { using (var reader = XmlReader.Create(readstream)) { Assert.IsTrue(serializer.CanDeserialize(reader)); var resultantObject = serializer.Deserialize(reader); //Assert that the result object is of the expected type (some derivative of IFeed) Assert.IsInstanceOf(feed.GetType(), resultantObject); //Assert that the two objects are distinct instances Assert.AreNotSame(feed, resultantObject); //Cast the object back into an IFeed and perform some specific assertions var resultantFeed = resultantObject as IFeed; Assert.AreEqual(feed.Title, resultantFeed.Title); Assert.AreEqual(feed.LastUpdated, resultantFeed.LastUpdated); Assert.AreEqual(feed.FeedUri, resultantFeed.FeedUri); Assert.AreEqual(feed.FeedType, resultantFeed.FeedType); Assert.AreEqual(feed.Items.Count, resultantFeed.Items.Count); Assert.Pass("THE FEED CAN BE DESERIALIZED SUCCESSFULLY"); } } }
public void CanSerializeAtomFeedToXml() { var testfeed = TestFileLoader.GetSingleAtomTestFilePath(TestFileLoader.TestFileType.FileSys); var feed = Factory.CreateFeed(new Uri(testfeed)); var serializer = new XmlSerializer(feed.GetType()); using (var filestream = new FileStream(AtomXmlFile, FileMode.Create)) { serializer.Serialize(filestream, feed); } Assert.IsTrue(File.Exists(AtomXmlFile)); Assert.IsTrue(File.ReadAllText(AtomXmlFile).Length > 0); }