public void EntityBaseSaveToFile_XmlWriterSettings() { // Arrange var author = new MockAuthor() { Firstname = "John", Lastname = "Smith", Books = { new MockBook { ISBN = "0123456788", Title = "Hello World!" }, new MockBook { ISBN = "0123456789", Title = "Hello World: Part 2" } } }; var outputFile = Path.Combine(Path.GetTempPath(), string.Format("{0}.xml", MethodBase.GetCurrentMethod().Name)); // Act author.SaveToFile(outputFile, new System.Xml.XmlWriterSettings { Encoding = Encoding.ASCII }); // Assert var xmlString = File.ReadAllText(outputFile); Assert.NotNull(xmlString); Assert.Contains("us-ascii", xmlString); Assert.Contains("<MockAuthor", xmlString); Assert.Contains("<ISBN>0123456789</ISBN>", xmlString); }
public void Serialize_Test1() { // Arrange var author = new MockAuthor() { Firstname = "John", Lastname = "Smith", Books = { new MockBook { ISBN = "0123456788", Title = "Hello World!" }, new MockBook { ISBN = "0123456789", Title = "Hello World: Part 2" } } }; // Act string xmlString; author.Serialize(out xmlString); // Assert Assert.NotNull(xmlString); Assert.Contains("utf-8", xmlString); Assert.Contains("<MockAuthor", xmlString); Assert.Contains("<ISBN>0123456789</ISBN>", xmlString); }
public void Deserialize_XmlReaderSettings() { var xml = XML_STRING; var author = MockAuthor.Deserialize(xml, new XmlReaderSettings()); Assert.NotNull(author); Assert.Equal("John", author.Firstname); Assert.Equal(2, author.Books.Count); }
public void Deserialize_Test1() { var xml = XML_STRING; var author = MockAuthor.Deserialize(xml); Assert.NotNull(author); Assert.Equal("John", author.Firstname); Assert.Equal(2, author.Books.Count); }
public void EntityBaseLoadFromFile_XmlReaderSettings() { // Arrange var outputFile = Path.Combine(Path.GetTempPath(), string.Format("{0}.xml", MethodBase.GetCurrentMethod().Name)); File.WriteAllText(outputFile, XML_TEST_STRING); // Act var author = MockAuthor.LoadFromFile(outputFile, new System.Xml.XmlReaderSettings()); // Assert Assert.NotNull(author); Assert.Equal("Alice", author.Firstname); Assert.Equal(2, author.Books.Count); }
public void EntityBaseClone_Test1() { var author = new MockAuthor { Firstname = "Fred", Lastname = "Smith", Books = new System.Collections.Generic.List <MockBook> { new MockBook { ISBN = "0123456789", Title = "Foo Bar" } } }; var clonedAuthor = author.Clone(); Assert.NotSame(author, clonedAuthor); Assert.Equal(author.Firstname, clonedAuthor.Firstname); Assert.Single(clonedAuthor.Books); }
public void Serialize_XmlWriterSettings() { // Arrange var author = new MockAuthor { Firstname = "Bill" }; // Act string xmlString; author.Serialize(new XmlWriterSettings { Encoding = Encoding.ASCII }, out xmlString); // Assert Assert.NotNull(xmlString); Assert.Contains("us-ascii", xmlString); Assert.Contains("<Firstname>Bill</Firstname>", xmlString); }