Add method for testing if the file exist or not
This commit is contained in:
parent
65d41e0faa
commit
d8bf615b02
@ -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,63 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -116,6 +158,41 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
||||
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("");
|
||||
|
||||
// Closing the connection
|
||||
sqlDS.getConnection().Close();
|
||||
sqlDS.GetConnection().Close();
|
||||
|
||||
// While loop to keep this running forever with UserManagement
|
||||
// Testing archive Manager
|
||||
//while (true)
|
||||
//{
|
||||
//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, "1") && String.Equals(currentTime, "00:00:00 AM")){
|
||||
if (String.Equals(currentDate, activateDate) && String.Equals(currentTime, activateTime))
|
||||
{
|
||||
ArchiveManager archive = new ArchiveManager(datasource);
|
||||
archive.Controller();
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -111,7 +114,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
//// Remove entries fromt the database
|
||||
//sqlDS.RemoveEntries();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 2.Inserting Data into the database:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user