Add method for testing if the file exist or not
This commit is contained in:
parent
65d41e0faa
commit
d8bf615b02
@ -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,38 @@ 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
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +158,41 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
|||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
|
||||||
|
// Testing file creation
|
||||||
|
test.IsCSVFileExist(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// 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++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,20 +66,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");
|
||||||
|
string activateDate = "01";
|
||||||
|
string activateTime = "00:00:00 AM";
|
||||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
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, activateDate) && String.Equals(currentTime, activateTime))
|
||||||
|
{
|
||||||
ArchiveManager archive = new ArchiveManager(datasource);
|
ArchiveManager archive = new ArchiveManager(datasource);
|
||||||
archive.Controller();
|
archive.Controller();
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user