예제 #1
0
        public void DataLogBasicUseTest()
        {
            DataLog DUT = new DataLog("TestFile");

            DUT.DeleteAll();
            for (int i = 0; i < 10; i++)
            {
                DUT.Output(new DataUnit("TestDataUnit")
                {
                    { "a", "∫" },
                    { "b", 20 },
                    { "c", i }
                }.SetSystem("TestSystem"));
            }
            DUT.DeleteAll(); // Test deleting all the log files
            DUT.CloseFile(); // Close the file to regain access permission
            Assert.IsTrue(File.Exists(DUT.LogFilePath));
            string[] Lines   = File.ReadAllLines(DUT.LogFilePath);
            int      LineCnt = Lines.Length;

            string[] ExpectedLines = new string[]
            {
                "TestSystem.TestDataUnit.a,TestSystem.TestDataUnit.b,TestSystem.TestDataUnit.c",
                "∫,20,0", "∫,20,1", "∫,20,2", "∫,20,3", "∫,20,4",
                "∫,20,5", "∫,20,6", "∫,20,7", "∫,20,8", "∫,20,9"
            };
            for (int i = 0; i < Lines.Length; i++)
            {
                Assert.AreEqual(Lines[i], ExpectedLines[i]);                        // Test contents are correct
            }
            Assert.ThrowsException <Exception>(delegate { DUT.Output(DataCont); }); // Try to output to the file (which was closed)
            Assert.AreEqual(File.ReadAllLines(DUT.LogFilePath).Length, LineCnt);    // Ensure it didn't write
            DUT.DeleteAll();                                                        // Delete the file
            Assert.IsFalse(File.Exists(DUT.LogFilePath));                           // Make sure it was deleted
        }
예제 #2
0
        public void DataLogTestDeleteDuringUse()
        {
            DataLog DUT = new DataLog("DataLogUnitTest");

            DUT.Output(DataCont);
            Assert.ThrowsException <IOException>(delegate { File.Delete(DUT.LogFilePath); });
            DUT.CloseFile();
            DUT.DeleteAll();
        }