Merge branch 'Long_archivePos'

This commit is contained in:
Lunastra 2021-12-13 20:56:16 -08:00
commit 9b2b38620b
4 changed files with 146 additions and 28 deletions

View File

@ -75,11 +75,24 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
} }
public void CopyingToAFileTest(IDataSource<string> sqlDAO) // [Test Method]
public void IsCSVFileExist(IDataSource<string> sqlDAO)
{ {
// Arrange // Arrange
ArchiveManager archiveManager = new ArchiveManager(sqlDAO); ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
SqlDAO sqlDS = null; 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)) if (sqlDAO.GetType() == typeof(SqlDAO))
{ {
@ -87,9 +100,100 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
} }
// Act // 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<string> 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<string> sqlDAO)
{
//Arrange
ArchiveManager archive = new ArchiveManager(sqlDAO);
bool actualVal = false;
bool expectedVal = false;
// Act
actualVal = archive.Controller();
// Assert // 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(""); Console.WriteLine("");
// Testing file creation
test.IsCSVFileExist(sqlDAO);
Console.WriteLine("-----------------");
Console.WriteLine("");
// Testing clean up sequence
//test.IsCleaningUpCompleted(sqlDAO);
//Console.WriteLine("-----------------");
//Console.WriteLine("");
} }
} }

View File

@ -238,14 +238,12 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30"; string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30";
try{ if (DeleteData(sqlCmd) == false)
DeleteData(sqlCmd); {
return true; throw new Exception("Error in removing entries,not to worry, will be handled higher up the call stack");
} };
catch {
Console.WriteLine("Eeep! an error in Remove Entries, not to worry, will be handled higher up the call stack"); return true;
throw;
}
} }
//public Object ReadPreparedStmt(string table){ //public Object ReadPreparedStmt(string table){

View File

@ -21,6 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
EndProject 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("{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("{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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -103,6 +103,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main
reader = (OdbcDataReader)result; reader = (OdbcDataReader)result;
} }
// [Logname, loglevel, date, time, ...]
Console.WriteLine("Reading from the database"); Console.WriteLine("Reading from the database");
while (reader.Read()) while (reader.Read())
@ -113,21 +114,23 @@ namespace TeamHobby.HobbyProjectGenerator.Main
Console.WriteLine(""); Console.WriteLine("");
// Closing the connection // Closing the connection
sqlDS.getConnection().Close();*/ sqlDS.GetConnection().Close();
/* // While loop to keep this running forever with UserManagement // While loop to keep this running forever with UserManagement
// Testing archive Manager //Testing archive Manager
//while (true) //while (true)
//{ //{
string currentDate = DateTime.Now.ToString("dd"); //string currentDate = DateTime.Now.ToString("dd");
string currentTime = DateTime.Now.ToString("T"); //string currentTime = DateTime.Now.ToString("T");
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime); //string activateDate = "01";
if (String.Equals(currentDate, "1") && String.Equals(currentTime, "00:00:00 AM")) //string activateTime = "00:00:00 AM";
{ //Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
ArchiveManager archive = new ArchiveManager(datasource); //if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime))
archive.Controller(); //{
} //ArchiveManager archive = new ArchiveManager(datasource);
//}*/ //archive.Controller();
//}
//}