public void Test_AddThreadToIndex()
        {
            //string testLogFile = ApplicationPath + @"\App_Data\Testing\Log.xml";
            //string testIndexFile = ApplicationPath + @"\App_Data\Testing\Detail\Index.xml";
            string rootDir = Path.Combine(ApplicationPath, @"App_Data\Testing");

            Guid   threadID = Guid.NewGuid();
            string title    = "Test Title";
            //string threadTitle = "Test Thread";

            XmlDocument indexDoc = new XmlDocument();

            indexDoc.AppendChild(indexDoc.CreateElement("Index"));

            LogThreader threader = new LogThreader(rootDir, DateTime.Now.ToShortDateString());

            threader.AddThreadToIndex(indexDoc, threadID, title);

            Assert.AreEqual(1, indexDoc.DocumentElement.ChildNodes.Count, "Invalid number of threads found.");

            XmlNode node = indexDoc.DocumentElement.ChildNodes[0];

            Assert.AreEqual(threadID.ToString(), node.Attributes["ID"].Value, "The thread doesn't have the expected ID.");
            Assert.AreEqual(title, node.Attributes["Title"].Value, "The thread doesn't have the expected title.");
        }
        public void Test_CreateNewThread()
        {
            Guid threadID = Guid.NewGuid();

            LogThreader threader = new LogThreader(TestUtilities.GetTestingPath(this), DateTime.Now.ToShortDateString());

            XmlDocument doc = threader.CreateNewThread();

            Assert.IsNotNull(doc, "The thread document is null.");
        }
        public void Test_SaveThread()
        {
            //string testLogFile = ApplicationPath + @"\App_Data\Testing\Log.xml";
            //string testIndexFile = ApplicationPath + @"\App_Data\Testing\Detail\Index.xml";
            string rootDir = ApplicationPath + @"\App_Data\Testing\";

            Guid threadID = Guid.NewGuid();
            //string threadTitle = "Test Thread";

            XmlDocument threadDoc = new XmlDocument();

            threadDoc.AppendChild(threadDoc.CreateElement("Test"));

            string dateStamp = DateTime.Now.ToShortDateString().Replace("/", "-");

            LogThreader threader = new LogThreader(rootDir, dateStamp);

            threader.SaveThread(threadDoc, threadID);

            string threadFile = threader.ThreadsDirectoryPath + Path.DirectorySeparatorChar + threadID + ".xml";

            Assert.IsTrue(File.Exists(threadFile), "The thread document wasn't saved.");
        }
        public void Test_SplitThreads()
        {
            string applicationName = "MockApplication";

            string testLogDir = TestUtilities.GetTestDataPath(this, applicationName);


            string dateStamp = DateTime.Now.ToShortDateString().Replace("/", "-");

            LogThreader threader = new LogThreader(testLogDir, dateStamp);

            string testThreadsDirectoryPath = threader.ThreadsDirectoryPath;

            // Create a test log file
            string testLogFile   = threader.LogFilePath;
            string testIndexFile = testLogDir + Path.DirectorySeparatorChar + dateStamp + Path.DirectorySeparatorChar + threader.ThreadsDirectoryName + Path.DirectorySeparatorChar + threader.ThreadsIndexFileName;

            if (!Directory.Exists(testThreadsDirectoryPath))
            {
                Directory.CreateDirectory(testThreadsDirectoryPath);
            }


            if (!Directory.Exists(Path.GetDirectoryName(testLogFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(testLogFile));
            }

            // Ensure the old files are cleared
            // TODO: Remove: This should no longer be necessary
            foreach (string file in Directory.GetFiles(testThreadsDirectoryPath))
            {
                File.Delete(file);
            }

            using (StreamWriter writer = new StreamWriter(File.Create(testLogFile)))
            {
                writer.Write(CreateExampleLog());

                writer.Close();
            }

            // Analyze the test log file
            threader.SplitThreads();



            // Check that the index file was created
            Assert.AreEqual(true, File.Exists(testIndexFile), "The index file wasn't found.");

            XmlDocument indexDoc = new XmlDocument();

            indexDoc.Load(testIndexFile);

            foreach (XmlNode node in indexDoc.DocumentElement.ChildNodes)
            {
                Assert.IsTrue(node.Attributes["ID"] != null, "The ID attribute of the thread node is null.");

                Guid id = new Guid(node.Attributes["ID"].Value);
                Assert.AreNotEqual(Guid.Empty, id, "The thread ID is Guid.Empty.");


                //Assert.IsTrue(node.Attributes["Title"] != null, "The title attribute of the thread node is null.");

                //string title = node.Attributes["Title"].Value;
                //Assert.AreNotEqual(String.Empty, title, "The thread title is String.Empty.");
            }



            /*string[] fileNames = Directory.GetFiles(testLogDir + @"\Detail");
             *
             * // Now read the creation time for each file
             * DateTime[] creationTimes = new DateTime[fileNames.Length];
             * for (int i=0; i < fileNames.Length; i++)
             *      creationTimes[i] = new FileInfo(fileNames[i]).CreationTime;
             *
             * // sort it
             * Array.Sort(creationTimes,fileNames);
             *
             * Assert.AreEqual(5, fileNames.Length, "Incorrect number of thread files created.");
             *
             * string fileName0 = Path.GetFileName(fileNames[0]);
             * string fileName1 = Path.GetFileName(fileNames[1]);
             * string fileName2 = Path.GetFileName(fileNames[2]);
             * string fileName3 = Path.GetFileName(fileNames[3]);
             *
             * Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName0, "The sub log file in position 0 has an invalid name.");
             * Assert.AreEqual("SoftwareMonkeys.SiteStarter.Configuration.Config.Initialize.xml", fileName1, "The sub log file in position 1 has an invalid name.");
             * Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName2, "The sub log file in position 2 has an invalid name.");
             * Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName3, "The sub log file in position 3 has an invalid name.");*/
        }
		public void Test_SplitThreads()
		{
			string applicationName = "MockApplication";
			
			string testLogDir = TestUtilities.GetTestDataPath(this, applicationName);

			
			string dateStamp = DateTime.Now.ToShortDateString().Replace("/", "-");
			
			LogThreader threader = new LogThreader(testLogDir, dateStamp);

			string testThreadsDirectoryPath = threader.ThreadsDirectoryPath;
			
			// Create a test log file
			string testLogFile = threader.LogFilePath;
			string testIndexFile = testLogDir + Path.DirectorySeparatorChar + dateStamp + Path.DirectorySeparatorChar + threader.ThreadsDirectoryName + Path.DirectorySeparatorChar + threader.ThreadsIndexFileName;
			
			if (!Directory.Exists(testThreadsDirectoryPath))
				Directory.CreateDirectory(testThreadsDirectoryPath);
			
			
			if (!Directory.Exists(Path.GetDirectoryName(testLogFile)))
				Directory.CreateDirectory(Path.GetDirectoryName(testLogFile));
			
			// Ensure the old files are cleared
			// TODO: Remove: This should no longer be necessary
			foreach (string file in Directory.GetFiles(testThreadsDirectoryPath))
				File.Delete(file);
			
			using (StreamWriter writer = new StreamWriter(File.Create(testLogFile)))
			{
				writer.Write(CreateExampleLog());
				
				writer.Close();
			}
			
			// Analyze the test log file
			threader.SplitThreads();
			
			
			
			// Check that the index file was created
			Assert.AreEqual(true, File.Exists(testIndexFile), "The index file wasn't found.");
			
			XmlDocument indexDoc = new XmlDocument();
			indexDoc.Load(testIndexFile);
			
			foreach (XmlNode node in indexDoc.DocumentElement.ChildNodes)
			{
				Assert.IsTrue(node.Attributes["ID"] != null, "The ID attribute of the thread node is null.");
				
				Guid id = new Guid(node.Attributes["ID"].Value);
				Assert.AreNotEqual(Guid.Empty, id, "The thread ID is Guid.Empty.");
				
				
				//Assert.IsTrue(node.Attributes["Title"] != null, "The title attribute of the thread node is null.");
				
				//string title = node.Attributes["Title"].Value;
				//Assert.AreNotEqual(String.Empty, title, "The thread title is String.Empty.");
				
				
			}
			
			
			
			
			/*string[] fileNames = Directory.GetFiles(testLogDir + @"\Detail");
			
			// Now read the creation time for each file
			DateTime[] creationTimes = new DateTime[fileNames.Length];
			for (int i=0; i < fileNames.Length; i++)
				creationTimes[i] = new FileInfo(fileNames[i]).CreationTime;
			
			// sort it
			Array.Sort(creationTimes,fileNames);
			
			Assert.AreEqual(5, fileNames.Length, "Incorrect number of thread files created.");
			
			string fileName0 = Path.GetFileName(fileNames[0]);
			string fileName1 = Path.GetFileName(fileNames[1]);
			string fileName2 = Path.GetFileName(fileNames[2]);
			string fileName3 = Path.GetFileName(fileNames[3]);
			
			Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName0, "The sub log file in position 0 has an invalid name.");
			Assert.AreEqual("SoftwareMonkeys.SiteStarter.Configuration.Config.Initialize.xml", fileName1, "The sub log file in position 1 has an invalid name.");
			Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName2, "The sub log file in position 2 has an invalid name.");
			Assert.AreEqual("ASP.global_asax.Application_Start.xml", fileName3, "The sub log file in position 3 has an invalid name.");*/
			
		}
		public void Test_AddThreadToIndex()
		{
			
			//string testLogFile = ApplicationPath + @"\App_Data\Testing\Log.xml";
			//string testIndexFile = ApplicationPath + @"\App_Data\Testing\Detail\Index.xml";
			string rootDir = Path.Combine(ApplicationPath, @"App_Data\Testing");
			
			Guid threadID = Guid.NewGuid();
			string title = "Test Title";
			//string threadTitle = "Test Thread";
			
			XmlDocument indexDoc = new XmlDocument();
			indexDoc.AppendChild(indexDoc.CreateElement("Index"));
			
			LogThreader threader = new LogThreader(rootDir, DateTime.Now.ToShortDateString());
			
			threader.AddThreadToIndex(indexDoc, threadID, title);
			
			Assert.AreEqual(1, indexDoc.DocumentElement.ChildNodes.Count, "Invalid number of threads found.");
			
			XmlNode node = indexDoc.DocumentElement.ChildNodes[0];
			
			Assert.AreEqual(threadID.ToString(), node.Attributes["ID"].Value, "The thread doesn't have the expected ID.");
			Assert.AreEqual(title, node.Attributes["Title"].Value, "The thread doesn't have the expected title.");
		}
		public void Test_SaveThread()
		{
			
			//string testLogFile = ApplicationPath + @"\App_Data\Testing\Log.xml";
			//string testIndexFile = ApplicationPath + @"\App_Data\Testing\Detail\Index.xml";
			string rootDir = ApplicationPath + @"\App_Data\Testing\";
			
			Guid threadID = Guid.NewGuid();
			//string threadTitle = "Test Thread";
			
			XmlDocument threadDoc = new XmlDocument();
			threadDoc.AppendChild(threadDoc.CreateElement("Test"));
			
			string dateStamp = DateTime.Now.ToShortDateString().Replace("/", "-");
			
			LogThreader threader = new LogThreader(rootDir, dateStamp);
			
			threader.SaveThread(threadDoc, threadID);
			
			string threadFile = threader.ThreadsDirectoryPath + Path.DirectorySeparatorChar + threadID + ".xml";
			
			Assert.IsTrue(File.Exists(threadFile), "The thread document wasn't saved.");
		}
		public void Test_CreateNewThread()
		{
			Guid threadID = Guid.NewGuid();
			
			LogThreader threader = new LogThreader(TestUtilities.GetTestingPath(this), DateTime.Now.ToShortDateString());
			
			XmlDocument doc = threader.CreateNewThread();
			
			Assert.IsNotNull(doc, "The thread document is null.");
		}