Esempio n. 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
        }
Esempio n. 2
0
 public static void Start(string[] args)
 {
     if (args.Length < 2)
     {
         TestMain.ErrorExit("utils command requires functionality to test.");
     }
     switch (args[1].ToLower())
     {
     case "datalog":
     {
         for (int i = 0; i < 10; i++)
         {
             Random  Random = new Random();
             DataLog Logger = new DataLog("ScarletTestSuite");
             Logger.Output(new DataUnit("TestData")
                 {
                     { "Index", i },
                     { "RandomNumber", Random.Next(100) }
                 }.SetSystem("Test"));
             Thread.Sleep(50);
         }
         break;
     }
     }
 }
Esempio n. 3
0
        public void DataLogTestDeleteDuringUse()
        {
            DataLog DUT = new DataLog("DataLogUnitTest");

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