public void SerialisationTestEmptyBattleReport() { StringWriter stringStream = new StringWriter(); try { // setup a test object BattleReport testData = new BattleReport(); // setup the file name string saveFileName = "BattleReportTest.xml"; // setup the streams MemoryStream memoryStream = new MemoryStream(); // Setup the XML document XmlDocument xmldoc = new XmlDocument(); Global.InitializeXmlDocument(xmldoc); // add the BattleReport to the document xmldoc.ChildNodes.Item(1).AppendChild(testData.ToXml(xmldoc)); xmldoc.Save(memoryStream); xmldoc.Save(stringStream); // Serialize to file if (TestControls.CreateFiles) { using (Stream fileStream = new FileStream(saveFileName, FileMode.Create)) { xmldoc.Save(fileStream); } } // deserialize BattleReport loadedData; xmldoc.RemoveAll(); if (TestControls.CreateFiles) { using (FileStream saveFileStream = new FileStream(saveFileName, FileMode.Open, FileAccess.Read)) { xmldoc.Load(saveFileStream); loadedData = new BattleReport(xmldoc); } } else { // move to start of memory stream memoryStream.Seek(0, SeekOrigin.Begin); xmldoc.Load(memoryStream); loadedData = new BattleReport(xmldoc); } // test if it worked // CheckTestIntel(loadedData); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("BattleReport.cs SerialisationTestEmptyBattleReport() failed:" + Environment.NewLine + e.Message + Environment.NewLine + stringStream.ToString()); throw e; // fail the test } }