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

@ -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<string> sqlDAO)
// [Test Method]
public void IsCSVFileExist(IDataSource<string> 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<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
//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("");
}
}

View File

@ -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){

View File

@ -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

View File

@ -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();
//}
//}