public void ToXmlTest() { PFList <string> testList = new PFList <string>(); try { _msg.Length = 0; _msg.Append("ToXmlTest started ...\r\n"); Program._messageLog.WriteLine(_msg.ToString()); testList.Add("First item"); testList.Add("Second item"); testList.Add("Third item"); string xmlString = testList.ToXmlString(); XmlDocument xmlDoc = testList.ToXmlDocument(); PFList <string> testList2 = PFList <string> .LoadFromXmlString(xmlString); _msg.Length = 0; _msg.Append("\r\n\r\n"); _msg.Append(xmlString); _msg.Append("\r\n\r\n"); _msg.Append(xmlDoc.OuterXml); _msg.Append("\r\n\r\n"); _msg.Append(testList2.ToString()); _msg.Append("\r\n\r\n"); Program._messageLog.WriteLine(_msg.ToString()); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { _msg.Length = 0; _msg.Append("\r\n... ToXmlTest finished."); Program._messageLog.WriteLine(_msg.ToString()); } }
//tests public void GenericListTest() { PFList <string> testList = new PFList <string>(); PFList <string> testList2 = new PFList <string>(); PFList <string> testList3 = new PFList <string>(); PFList <string> testList4 = new PFList <string>(); string testListXmlFile = @"c:\temp\testlist.xml"; string connectionString = string.Empty; string configValue = string.Empty; PFDBListProcessor <string> listProcessor = new PFDBListProcessor <string>(); try { _msg.Length = 0; _msg.Append("GenericListTest started ..."); Program._messageLog.WriteLine(_msg.ToString()); configValue = AppConfig.GetStringValueFromConfigFile("ListsDatabaseFile", string.Empty); if (configValue.Length > 0) { connectionString = configValue; } else { connectionString = _listsDatabaseConnectionString; } _msg.Length = 0; _msg.Append("First = "); _msg.Append(testList.FirstItem == null ? "<null>" : testList.FirstItem); Program._messageLog.WriteLine(_msg.ToString()); testList.Add("First item"); testList.Add("Second item"); testList.Add("Third item"); _msg.Length = 0; _msg.Append("Number of items in list: "); Program._messageLog.WriteLine(_msg.ToString()); foreach (string s in testList) { _msg.Length = 0; _msg.Append(s); Program._messageLog.WriteLine(_msg.ToString()); } _msg.Length = 0; _msg.Append("First = "); _msg.Append(testList.FirstItem); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Last = "); _msg.Append(testList.LastItem); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("NextItem loop: "); Program._messageLog.WriteLine(_msg.ToString()); string res = testList.FirstItem; while (!testList.EOF) { _msg.Length = 0; _msg.Append(res); Program._messageLog.WriteLine(_msg.ToString()); res = testList.NextItem; } _msg.Length = 0; _msg.Append("PrevItem loop: "); Program._messageLog.WriteLine(_msg.ToString()); res = testList.LastItem; while (!testList.EOF) { _msg.Length = 0; _msg.Append(res); Program._messageLog.WriteLine(_msg.ToString()); res = testList.PrevItem; } _msg.Length = 0; _msg.Append("ToString Test: "); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append(testList.ToString()); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("SaveToXmlFile Test: "); _msg.Append(testListXmlFile); Program._messageLog.WriteLine(_msg.ToString()); testList.SaveToXmlFile(testListXmlFile); _msg.Length = 0; _msg.Append("LoadFromXmlFile Test: "); _msg.Append(testListXmlFile); Program._messageLog.WriteLine(_msg.ToString()); testList2 = PFList <string> .LoadFromXmlFile(testListXmlFile); _msg.Length = 0; _msg.Append("testList2 ToString Test: "); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append(testList2.ToString()); Program._messageLog.WriteLine(_msg.ToString()); //save and read to database tests next listProcessor.SaveToDatabase(testList, connectionString, "TestprogCollections_testList"); testList3 = listProcessor.LoadFromDatabase(connectionString, "TestprogCollections_testList"); if (testList3 != null) { _msg.Length = 0; _msg.Append("testList3 ToXmlString Test: "); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append(testList3.ToXmlString()); _msg.Append(Environment.NewLine); _msg.Append("+++ testlist3 retrieved. +++"); Program._messageLog.WriteLine(_msg.ToString()); } else { _msg.Length = 0; _msg.Append("testList3 ToXmlString Test: "); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("*** TESTLIST3 IS NULL ***"); Program._messageLog.WriteLine(_msg.ToString()); } } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { listProcessor = null; _msg.Length = 0; _msg.Append("... GenericListTest finished."); Program._messageLog.WriteLine(_msg.ToString()); } }//end GenericListTest