diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 88e7b50..7da2223 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -40,8 +40,8 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests { Directory.Delete(folderPath, true); } - catch { - Console.WriteLine("Folder failed to be deleted"); + catch { + Console.WriteLine("Folder failed to be deleted"); } } else @@ -75,21 +75,125 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests } - public void CopyingToAFileTest(IDataSource sqlDAO) + // [Test Method] + public void IsCSVFileExist(IDataSource sqlDAO) { // Arrange ArchiveManager archiveManager = new ArchiveManager(sqlDAO); SqlDAO sqlDS = null; - + string folderPath = @"C:/HobbyArchive"; + + try + { + bool folderRes = archiveManager.CreateArchiveFolder(); + } + catch (Exception ex) + { + Console.WriteLine("Folder creation for copying failed"); + } + string filePath = archiveManager.CreateOutFileName(); + bool expectedVal = true; + if (sqlDAO.GetType() == typeof(SqlDAO)) { sqlDS = (SqlDAO)sqlDAO; } // Act - - + bool actualVal = false; + if (sqlDS != null) + { + try + { + actualVal = sqlDS.CopyToFile(filePath); + } + catch (Exception ex) + { + Console.WriteLine("Copying to a file failed !!"); + Console.WriteLine(ex.Message); + } + } // Assert + bool result = File.Exists(filePath); + if (result) + { + Console.WriteLine("Expected: {0}, Actual: {1}. CSV file created correctly", expectedVal, actualVal); + // Clean up the folder use to test. + try + { + Directory.Delete(folderPath, true); + } + catch + { + Console.WriteLine("Folder failed to be deleted"); + } + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. CSV file created incorrectly", expectedVal, actualVal); + } + + } + + // [Test Method] + public void IsProcessFlowCompleted(IDataSource sqlDAO) + { + // Arrange + ArchiveManager archive = new ArchiveManager(sqlDAO); + + // Act + // Testing archive Manager + int i = -10; + while (i < 20) + { + DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0); + //Console.WriteLine("Testing first of month: {0}", date1.ToString("dd")); + //string currentDate = DateTime.Now.ToString("dd"); + //string currentTime = DateTime.Now.ToString("T"); + string currentTime = "00:00:00 AM"; + string currentDate = i.ToString(); + + if (i == 1) + { + currentDate = date1.ToString("dd"); + //ArchiveManager archive = new ArchiveManager(sqlDAO); + //archive.Controller(); + } + + //Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM")) + { + Console.WriteLine("Archiving process Start"); + //ArchiveManager archive = new ArchiveManager(sqlDAO); + archive.Controller(); + } + + i++; + } + + } + + public void IsCleaningUpCompleted(IDataSource sqlDAO) + { + //Arrange + ArchiveManager archive = new ArchiveManager(sqlDAO); + bool actualVal = false; + bool expectedVal = false; + + // Act + actualVal = archive.Controller(); + + // Assert + //bool result = !(actualVal && expectedVal); + if (expectedVal == actualVal) + { + Console.WriteLine("Expected: {0}, Actual: {1}. Error handle correctly", expectedVal, actualVal); + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. Error handle incorrectly", expectedVal, actualVal); + } } @@ -116,6 +220,18 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests Console.WriteLine(""); + // Testing file creation + test.IsCSVFileExist(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + + + // Testing clean up sequence + //test.IsCleaningUpCompleted(sqlDAO); + //Console.WriteLine("-----------------"); + //Console.WriteLine(""); + } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 7a14a05..e3b7356 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -238,14 +238,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30"; - try{ - DeleteData(sqlCmd); - return true; - } - catch { - Console.WriteLine("Eeep! an error in Remove Entries, not to worry, will be handled higher up the call stack"); - throw; - } + if (DeleteData(sqlCmd) == false) + { + throw new Exception("Error in removing entries,not to worry, will be handled higher up the call stack"); + }; + + return true; } //public Object ReadPreparedStmt(string table){ diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index bf07f2e..dafe8e1 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -21,6 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Logging.Tests", "..\TeamHobby.HobbyProjectGenerator.Logging.Tests\TeamHobby.HobbyProjectGenerator.Logging.Tests.csproj", "{CA8D11CF-807C-4C90-A529-0371F73518F6}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 057d4a5..5ef6620 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -103,6 +103,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main reader = (OdbcDataReader)result; } + // [Logname, loglevel, date, time, ...] Console.WriteLine("Reading from the database"); while (reader.Read()) @@ -113,21 +114,23 @@ namespace TeamHobby.HobbyProjectGenerator.Main Console.WriteLine(""); // Closing the connection - sqlDS.getConnection().Close();*/ + sqlDS.GetConnection().Close(); - /* // While loop to keep this running forever with UserManagement - // Testing archive Manager - //while (true) - //{ - string currentDate = DateTime.Now.ToString("dd"); - string currentTime = DateTime.Now.ToString("T"); - Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); - if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")) - { - ArchiveManager archive = new ArchiveManager(datasource); - archive.Controller(); - } - //}*/ + // While loop to keep this running forever with UserManagement + //Testing archive Manager + //while (true) + //{ + //string currentDate = DateTime.Now.ToString("dd"); + //string currentTime = DateTime.Now.ToString("T"); + //string activateDate = "01"; + //string activateTime = "00:00:00 AM"; + //Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); + //if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime)) + //{ + //ArchiveManager archive = new ArchiveManager(datasource); + //archive.Controller(); + //} + //}