From 95f762552f310639555ed00ba2a66b1936b79f6b Mon Sep 17 00:00:00 2001 From: DanBribi <80496947+Dbribs@users.noreply.github.com> Date: Tue, 14 Dec 2021 02:50:12 -0800 Subject: [PATCH 01/10] remove_entries_testing --- .../ArchivingTests.cs | 81 ++++++++++++++++++- .../Implementations/SqlDAO.cs | 18 ++--- 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 7da2223..62d06e3 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.Odbc; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -197,6 +198,75 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests } + public void RemoveEntriesTest(IDataSource sqlDAO) + { + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + sqlDS.GetConnection().Open(); + + // Act + Console.WriteLine("Inserting into archive..."); + sqlDS.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully');"); + + OdbcDataReader odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + + int count = 0; + while (odbcObj.Read()) { ++count; } + Console.WriteLine("Number of entries > 30 days old: " + count); + + Console.WriteLine(""); + Console.WriteLine("Removing entries from archive..."); + sqlDS.RemoveEntries(); + + odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + + count = 0; + while (odbcObj.Read()) { ++count; } + Console.WriteLine("Number of entries > 30 days old: " + count); + + // Assert + bool expectedVal = true; + bool actualVal = !Convert.ToBoolean(count); + + if (actualVal) + { + Console.WriteLine("Expected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal); + } + else + { + Console.WriteLine("Expected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal); + } + + sqlDS.GetConnection().Close(); + } + + return; + } + + public void RemoveOutputFileTest(IDataSource sqlDAO) + { + // Arrange + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Act + + + // Assert + + return; + } + public static void Main(string[] args) { string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + @@ -226,12 +296,21 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests Console.WriteLine(""); - // Testing clean up sequence //test.IsCleaningUpCompleted(sqlDAO); //Console.WriteLine("-----------------"); //Console.WriteLine(""); + // Testing remove entries + test.RemoveEntriesTest(sqlDAO); + Console.WriteLine("-----------------"); + Console.WriteLine(""); + + // Testing remove output file + test.RemoveOutputFileTest(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 e3b7356..6eee8c8 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -42,7 +42,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); OdbcDataReader reader = command.ExecuteReader(); @@ -67,12 +67,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); - + //_conn.Open(); + OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - - _conn.Close(); + + //_conn.Close(); return true; } @@ -84,7 +84,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } @@ -120,12 +120,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - _conn.Close(); + //_conn.Close(); return true; } @@ -137,7 +137,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } From 14dec71367239fb991f5c01d3b740b5f7b582ab8 Mon Sep 17 00:00:00 2001 From: DanBribi <80496947+Dbribs@users.noreply.github.com> Date: Tue, 14 Dec 2021 12:33:06 -0800 Subject: [PATCH 02/10] Testing removeOutputFile --- .../ArchivingTests.cs | 45 +++++++++++++---- .../Implementations/SqlDAO.cs | 6 +-- .../TeamHobby.HobbyProjectGenerator.sln | 50 ++----------------- 3 files changed, 42 insertions(+), 59 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index 62d06e3..d1a7e6b 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -200,6 +200,8 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests public void RemoveEntriesTest(IDataSource sqlDAO) { + Console.WriteLine("TESTING - REMOVE ENTRIES"); + // Arrange ArchiveManager archiveManager = new ArchiveManager(sqlDAO); SqlDAO sqlDS = null; @@ -208,9 +210,9 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests { sqlDS = (SqlDAO)sqlDAO; sqlDS.GetConnection().Open(); - + // Act - Console.WriteLine("Inserting into archive..."); + Console.WriteLine("\nInserting into archive..."); sqlDS.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + @@ -225,8 +227,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests while (odbcObj.Read()) { ++count; } Console.WriteLine("Number of entries > 30 days old: " + count); - Console.WriteLine(""); - Console.WriteLine("Removing entries from archive..."); + Console.WriteLine("\nRemoving entries from archive..."); sqlDS.RemoveEntries(); odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); @@ -238,16 +239,16 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests // Assert bool expectedVal = true; bool actualVal = !Convert.ToBoolean(count); - - if (actualVal) + + if (expectedVal == actualVal) { - Console.WriteLine("Expected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal); + Console.WriteLine("\nExpected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal); } else { - Console.WriteLine("Expected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal); + Console.WriteLine("\nExpected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal); } - + sqlDS.GetConnection().Close(); } @@ -256,13 +257,35 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests public void RemoveOutputFileTest(IDataSource sqlDAO) { + Console.WriteLine("TESTING - REMOVE OUTPUT FILE\n"); + // Arrange ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + SqlDAO sqlDS = null; + + if (sqlDAO.GetType() == typeof(SqlDAO)) + { + sqlDS = (SqlDAO)sqlDAO; + } // Act - - + string filepath = archiveManager.CreateOutFileName(); + Console.WriteLine("\nRemoving file..."); + sqlDS.RemoveOutputFile(filepath); + // Assert + bool expectedVal = false; + bool actualVal = File.Exists(filepath); + Console.WriteLine("Checking if file exists: " + actualVal); + + if (expectedVal == actualVal) + { + Console.WriteLine("\nExpected: {0}, Actual: {0}. Output file removed correctly.", expectedVal, actualVal); + } + else + { + Console.WriteLine("\nExpected: {0}, Actual: {1}. Output file NOT removed.", expectedVal, actualVal); + } return; } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 6eee8c8..6399d75 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -94,12 +94,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - _conn.Open(); + //_conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - _conn.Close(); + //_conn.Close(); return true; } @@ -111,7 +111,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - _conn.Close(); + //_conn.Close(); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index dafe8e1..fc15a13 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -20,93 +20,53 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}" 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}" +EndProject 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 Debug|Any CPU = Debug|Any CPU - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.Build.0 = Release|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C75B6909-FD9E-4382-94B6-7CA2CE371C9A}.Release|Any CPU.Build.0 = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU - {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU {75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU {30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU {CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 1f84ec0a8d9bee90d0898930191d158979514402 Mon Sep 17 00:00:00 2001 From: DanBribi <80496947+Dbribs@users.noreply.github.com> Date: Tue, 14 Dec 2021 14:19:15 -0800 Subject: [PATCH 03/10] updates_12_14_21 --- ...ackup.HobbyProjectGenerator.Archive.csproj | 25 +++++++++++++++++++ ...Hobby.HobbyProjectGenerator.Archive.csproj | 1 - Source Code/main/main.csproj | 7 +----- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj new file mode 100644 index 0000000..65fcde5 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + AnyCPU;x86 + + + + + + + + + + + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj index 65fcde5..09da541 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -4,7 +4,6 @@ net6.0 enable enable - AnyCPU;x86 diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 5dde81b..886baa3 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -1,12 +1,10 @@ - + Exe net6.0 enable enable - AnyCPU - AnyCPU @@ -16,9 +14,6 @@ - - - From 04f5d9856b4393ac56e974c7556a0dee14083d0b Mon Sep 17 00:00:00 2001 From: DanBribi <80496947+Dbribs@users.noreply.github.com> Date: Tue, 14 Dec 2021 14:19:32 -0800 Subject: [PATCH 04/10] update backup --- Source Code/main/main - Backup.csproj | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Source Code/main/main - Backup.csproj diff --git a/Source Code/main/main - Backup.csproj b/Source Code/main/main - Backup.csproj new file mode 100644 index 0000000..73a9e47 --- /dev/null +++ b/Source Code/main/main - Backup.csproj @@ -0,0 +1,23 @@ + + + + Exe + net6.0 + enable + enable + AnyCPU + AnyCPU + + + + + + + + + + + + + + From 68b8439256e63075c4e11f7295009c19335255ad Mon Sep 17 00:00:00 2001 From: DanBribi <80496947+Dbribs@users.noreply.github.com> Date: Tue, 14 Dec 2021 14:41:37 -0800 Subject: [PATCH 05/10] Adjusted open and close connections --- .../ArchivingTests.cs | 7 ++++--- .../Implementations/SqlDAO.cs | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs index d1a7e6b..9775996 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.ArchiveTests/ArchivingTests.cs @@ -209,7 +209,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests if (sqlDAO.GetType() == typeof(SqlDAO)) { sqlDS = (SqlDAO)sqlDAO; - sqlDS.GetConnection().Open(); + //sqlDS.GetConnection().Open(); // Act Console.WriteLine("\nInserting into archive..."); @@ -249,7 +249,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests Console.WriteLine("\nExpected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal); } - sqlDS.GetConnection().Close(); + //sqlDS.GetConnection().Close(); } return; @@ -299,6 +299,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests "PASSWORD=Teamhobby;" + "OPTION=3"; SqlDAO sqlDAO = new SqlDAO(dbInfo); + sqlDAO.GetConnection().Open(); //ArchiveManager archiveManager = new ArchiveManager(sqlDAO); // Testing folder creation @@ -333,7 +334,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests test.RemoveOutputFileTest(sqlDAO); Console.WriteLine("-----------------"); Console.WriteLine(""); - + sqlDAO.GetConnection().Close(); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 6399d75..56c42f7 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -177,7 +177,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess public bool CopyToFile(string filePath){ try { - _conn.Open(); + //_conn.Open(); // Conver backward slash in to forward slash filePath = filePath.Replace("\\", "/"); string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " + @@ -200,19 +200,19 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess Console.WriteLine("Output to a file completed. "); - _conn.Close(); + //_conn.Close(); return true; } catch (Exception ex) { - _conn.Close(); + //_conn.Close(); Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack"); throw; } finally { - _conn.Close(); + //_conn.Close(); } } From 2ef2d3c9191a354f11a7b54fba76b5659fc2d724 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Tue, 14 Dec 2021 19:11:12 -0800 Subject: [PATCH 06/10] some csproj files changes --- ...ackup.HobbyProjectGenerator.Archive.csproj | 24 +++++++++++++++++++ ...Hobby.HobbyProjectGenerator.Archive.csproj | 1 + Source Code/main/main - Backup.csproj | 19 +++++++++++++++ Source Code/main/main.csproj | 5 ++++ 4 files changed, 49 insertions(+) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj create mode 100644 Source Code/main/main - Backup.csproj diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj new file mode 100644 index 0000000..09da541 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby - Backup.HobbyProjectGenerator.Archive.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj index 09da541..65fcde5 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/TeamHobby.HobbyProjectGenerator.Archive.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + AnyCPU;x86 diff --git a/Source Code/main/main - Backup.csproj b/Source Code/main/main - Backup.csproj new file mode 100644 index 0000000..8853c02 --- /dev/null +++ b/Source Code/main/main - Backup.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Source Code/main/main.csproj b/Source Code/main/main.csproj index 8853c02..5dde81b 100644 --- a/Source Code/main/main.csproj +++ b/Source Code/main/main.csproj @@ -5,6 +5,8 @@ net6.0 enable enable + AnyCPU + AnyCPU @@ -14,6 +16,9 @@ + + + From 03cfb10c1042679bea06e5eb4b4e9aa71b4adf3e Mon Sep 17 00:00:00 2001 From: Lunastra Date: Tue, 14 Dec 2021 20:37:43 -0800 Subject: [PATCH 07/10] Translate the test case from main over Revert back to open and close design. Move test cases to unit test. --- .../ArchiveManager.cs | 23 --- .../Implementations/SqlDAO.cs | 28 +-- .../ArchivingXUnitTest.cs | 178 ++++++++++++++++++ .../TeamHobby.Archiving.xTests.csproj | 27 +++ .../TeamHobby.HobbyProjectGenerator.sln | 16 +- 5 files changed, 225 insertions(+), 47 deletions(-) create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs create mode 100644 Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/TeamHobby.Archiving.xTests.csproj diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs index 2eee2fe..051ec59 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveManager.cs @@ -72,29 +72,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive } } - // Method overload to take in a specific path - public string CreateOutFileName(string archivePath) - { - try - { - //string path = archivePath + "\\HobbyArchive"; - Console.WriteLine("The current directory is {0}", archivePath); - //string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss"); - string date = DateTime.Now.ToString("M_d_yyyy"); - string fileName = date + "_archive.csv"; - string filePath = Path.Combine(archivePath, fileName); - - Console.WriteLine("Date: {0}", date); - Console.WriteLine("Filepath: {0}", filePath); - return filePath; - } - catch - { - Console.WriteLine("ArchiveCon: Creating a file name failed. "); - return ""; - } - } - // put everything toget here public bool Controller(){ diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 90f8416..127d03e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -42,7 +42,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - //_conn.Open(); + _conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); OdbcDataReader reader = command.ExecuteReader(); @@ -67,12 +67,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - //_conn.Open(); + _conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - //_conn.Close(); + _conn.Close(); return true; } @@ -84,7 +84,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - //_conn.Close(); + _conn.Close(); } } @@ -94,12 +94,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - //_conn.Open(); + _conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - //_conn.Close(); + _conn.Close(); return true; } @@ -111,7 +111,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - //_conn.Close(); + _conn.Close(); } } @@ -120,12 +120,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess { try { - //_conn.Open(); + _conn.Open(); OdbcCommand command = new OdbcCommand(cmd, _conn); command.ExecuteNonQuery(); - //_conn.Close(); + _conn.Close(); return true; } @@ -137,7 +137,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } finally { - //_conn.Close(); + _conn.Close(); } } @@ -177,7 +177,7 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess public bool CopyToFile(string filePath){ try { - //_conn.Open(); + _conn.Open(); // Conver backward slash in to forward slash filePath = filePath.Replace("\\", "/"); string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " + @@ -200,19 +200,19 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess Console.WriteLine("Output to a file completed. "); - //_conn.Close(); + _conn.Close(); return true; } catch (Exception ex) { - //_conn.Close(); + _conn.Close(); Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack"); throw; } finally { - //_conn.Close(); + _conn.Close(); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs new file mode 100644 index 0000000..71b5de3 --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs @@ -0,0 +1,178 @@ +using System; +using System.Data.Odbc; +using System.IO; +using TeamHobby.HobbyProjectGenerator.Archive; +using TeamHobby.HobbyProjectGenerator.DataAccess; +using Xunit; + +namespace TeamHobby.Archiving.xTests +{ + public class ArchivingXUnitTest + { + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + + "SERVER=localhost;" + + "DATABASE=hobby;" + + "UID=root;" + + "PASSWORD=Teamhobby;" + + "OPTION=3"; + + [Fact] + public void IsArchiveFolderCreated() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + string folderPath = @"C:/HobbyArchive"; + bool expectedVal = true; + + // Act + archiveManager.CreateArchiveFolder(); + + + // Assert + bool actualVal = Directory.Exists(folderPath); + Assert.Equal(expectedVal, actualVal); + // Cleaning up directory after test + try + { + Directory.Delete(folderPath, true); + } + catch + { + Console.WriteLine("Folder failed to be deleted"); + } + } + + [Fact] + public void IsFileNameCreated() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + string foldPath = @"C:\HobbyArchive"; + string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv"; + string expectedFilePath = System.IO.Path.Combine(foldPath, fileName); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Act + string actualFilePath = archiveManager.CreateOutFileName(); + + // Assert + + Assert.Equal(expectedFilePath, actualFilePath); + } + + [Fact] + public void IsCSVFileExist() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + 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 + if (sqlDS != null) + { + try + { + sqlDS.CopyToFile(filePath); + } + catch (Exception ex) + { + Console.WriteLine("Copying to a file failed !!"); + Console.WriteLine(ex.Message); + } + } + + // Assert + bool actualVal = File.Exists(filePath); + Assert.Equal(expectedVal, actualVal); + + try + { + Directory.Delete(folderPath, true); + } + catch + { + Console.WriteLine("Folder failed to be deleted"); + } + } + + [Fact] + public void RemoveEntriesTest() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + OdbcDataReader odbcObj = null; + Object resultData = null; + bool expectedVal = false; + + sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return'),"); + + // Act + sqlDAO.RemoveEntries(); + + // Assert + bool actualVal; + + resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader))) + { + odbcObj = (OdbcDataReader)resultData; + } + OdbcConnection conn = sqlDAO.GetConnection(); + actualVal = odbcObj.HasRows; + conn.Close(); + + Assert.Equal(expectedVal, actualVal); + + } + + + [Fact] + public void RemoveOutputFileTest() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + bool expectedVal = false; + + // Create the folder and the csv file for compressing + archiveManager.CreateArchiveFolder(); + string filepath = archiveManager.CreateOutFileName(); + sqlDAO.CopyToFile(filepath); + + // Act + if (sqlDAO != null) + { + sqlDAO.RemoveOutputFile(filepath); + } + + // Assert + bool actualVal = File.Exists(filepath); + Assert.Equal(expectedVal, actualVal); + } + } +} \ No newline at end of file diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/TeamHobby.Archiving.xTests.csproj b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/TeamHobby.Archiving.xTests.csproj new file mode 100644 index 0000000..308e40a --- /dev/null +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/TeamHobby.Archiving.xTests.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln index 62b8c20..8ab06bf 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.HobbyProjectGenerator.sln @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.Archiving.xTests", "TeamHobby.Archiving.xTests\TeamHobby.Archiving.xTests.csproj", "{8C039F49-13D3-4AEE-A1C3-A880751852BB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,17 +53,10 @@ Global {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU {B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -74,13 +69,14 @@ Global {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU - {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU {6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.Build.0 = Release|Any CPU + {8C039F49-13D3-4AEE-A1C3-A880751852BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C039F49-13D3-4AEE-A1C3-A880751852BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C039F49-13D3-4AEE-A1C3-A880751852BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C039F49-13D3-4AEE-A1C3-A880751852BB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 6689b91e70abd0609d2bd12fdc358a11878c7cb8 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Tue, 14 Dec 2021 22:24:28 -0800 Subject: [PATCH 08/10] Add testing compression method. --- .../Implementations/SqlDAO.cs | 6 +++-- .../ArchivingXUnitTest.cs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 127d03e..487838e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -155,8 +155,10 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Check to see if the file is hidden or already compressed before compressing the file. if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed) { - using FileStream outputFile = File.Create(fileName + ".gz"); - + var compFileName = Path.ChangeExtension(fileName, ".gz"); + //using FileStream outputFile = File.Create(fileName + ".gz"); + using FileStream outputFile = File.Create(compFileName); + using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); origFile.CopyTo(compressor); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs index 71b5de3..196ad55 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs @@ -174,5 +174,29 @@ namespace TeamHobby.Archiving.xTests bool actualVal = File.Exists(filepath); Assert.Equal(expectedVal, actualVal); } + + [Fact] + public void IsFileCompressed() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Create the folder and the csv file to be compressed. + archiveManager.CreateArchiveFolder(); + string filePath = archiveManager.CreateOutFileName(); + sqlDAO.CopyToFile(filePath); + FileAttributes expectedAttribute = FileAttributes.Archive; + string compFilePath = Path.ChangeExtension(filePath, ".gz"); + + // Act + sqlDAO.CompressFile(filePath); + + // Assert + FileAttributes actualAttribute = File.GetAttributes(compFilePath); + Assert.Equal(expectedAttribute, actualAttribute); + + } + } } \ No newline at end of file From 3c4a4139174266005e4a591cc69204d44da1a7e6 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Wed, 15 Dec 2021 00:21:40 -0800 Subject: [PATCH 09/10] Fixed a small syntax in the controller --- Source Code/main/Controller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index 1d74a58..1151c76 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -70,7 +70,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main 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")) + if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM")) { ArchiveManager archive = new ArchiveManager(datasource); archive.Controller(); From cd7f94a5e0737fbe2bcb0b79991aa73bced14b22 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Wed, 15 Dec 2021 14:02:39 -0800 Subject: [PATCH 10/10] Add performance testing for 10k and 1 million records --- .../ArchivingXUnitTest.cs | 130 +++++++++++++++++- 1 file changed, 124 insertions(+), 6 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs index 196ad55..0e53def 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs @@ -1,6 +1,8 @@ using System; using System.Data.Odbc; +using System.Diagnostics; using System.IO; +using System.Threading; using TeamHobby.HobbyProjectGenerator.Archive; using TeamHobby.HobbyProjectGenerator.DataAccess; using Xunit; @@ -124,12 +126,12 @@ namespace TeamHobby.Archiving.xTests Object resultData = null; bool expectedVal = false; - sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values " + - "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + - "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + - "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + - "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + - "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return'),"); + sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');"); // Act sqlDAO.RemoveEntries(); @@ -158,6 +160,7 @@ namespace TeamHobby.Archiving.xTests SqlDAO sqlDAO = new SqlDAO(dbInfo); ArchiveManager archiveManager = new ArchiveManager(sqlDAO); bool expectedVal = false; + //Thread.Sleep(5000); // Create the folder and the csv file for compressing archiveManager.CreateArchiveFolder(); @@ -198,5 +201,120 @@ namespace TeamHobby.Archiving.xTests } + [Fact] + public void IsArchive_Under_60s_10kRecords() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + var timer = new Stopwatch(); + double expectedVal = 60; + string folderPath = @"C:/HobbyArchive"; + + sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');"); + + for (int i = 0; i < 11; i++) + { + sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " + + "SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + } + + // Act + timer.Start(); + archiveManager.Controller(); + timer.Stop(); + + // Arrange + double actualVal = timer.ElapsedMilliseconds; + Assert.True((actualVal / 1000) < expectedVal); + + // Clean up resources after testing + try + { + Directory.Delete(folderPath, true); + } + catch + { + Console.WriteLine("Folder failed to be deleted"); + } + } + + [Fact] + public void IsArchive_Under_60s_10mRecords() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + var timer = new Stopwatch(); + double expectedVal = 60; + string folderPath = @"C:/HobbyArchive"; + + sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');"); + + for (int i = 0; i < 18; i++) + { + sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " + + "SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;"); + } + + // Act + timer.Start(); + archiveManager.Controller(); + timer.Stop(); + + // Arrange + double actualVal = timer.ElapsedMilliseconds; + Assert.True((actualVal / 1000) < expectedVal); + + //Clean up resources after testing + try + { + Directory.Delete(folderPath, true); + } + catch + { + Console.WriteLine("Folder failed to be deleted"); + } + } + + [Fact] + public void IsArchiveOnFirstOfMonth() + { + + } + + + [Fact] + public void IsWriteData() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + var timer = new Stopwatch(); + double expectedVal = 60; + string folderPath = @"C:/HobbyArchive"; + + // Act + sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" + + "('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," + + "('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," + + "('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," + + "('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," + + "('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');"); + + // Assert + Assert.True(true); + } + } } \ No newline at end of file