Add output to print some prompt
This commit is contained in:
parent
c403278f9f
commit
2bf0341668
@ -6,8 +6,11 @@ using System.Threading;
|
|||||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace TeamHobby.Archiving.xTests
|
namespace TeamHobby.Archiving.xTests
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
public class ArchivingXUnitTest
|
public class ArchivingXUnitTest
|
||||||
{
|
{
|
||||||
@ -18,6 +21,12 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
"PASSWORD=Teamhobby;" +
|
"PASSWORD=Teamhobby;" +
|
||||||
"OPTION=3";
|
"OPTION=3";
|
||||||
|
|
||||||
|
ITestOutputHelper output;
|
||||||
|
public ArchivingXUnitTest(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
this.output = output;
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IsArchiveFolderCreated()
|
public void IsArchiveFolderCreated()
|
||||||
{
|
{
|
||||||
@ -33,8 +42,10 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
bool actualVal = Directory.Exists(folderPath);
|
bool actualVal = Directory.Exists(folderPath);
|
||||||
|
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||||
Assert.Equal(expectedVal, actualVal);
|
Assert.Equal(expectedVal, actualVal);
|
||||||
// Cleaning up directory after test
|
// Cleaning up directory after test
|
||||||
|
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.Delete(folderPath, true);
|
Directory.Delete(folderPath, true);
|
||||||
@ -43,6 +54,7 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
}
|
}
|
||||||
|
output.WriteLine("Cleaning up completed. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -104,8 +116,9 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
bool actualVal = File.Exists(filePath);
|
bool actualVal = File.Exists(filePath);
|
||||||
|
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||||
Assert.Equal(expectedVal, actualVal);
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.Delete(folderPath, true);
|
Directory.Delete(folderPath, true);
|
||||||
@ -114,10 +127,11 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Folder failed to be deleted");
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
}
|
}
|
||||||
|
output.WriteLine("Cleaning up completed. ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveEntriesTest()
|
public void IsEntriesRemoved()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
@ -148,13 +162,14 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
actualVal = odbcObj.HasRows;
|
actualVal = odbcObj.HasRows;
|
||||||
conn.Close();
|
conn.Close();
|
||||||
|
|
||||||
|
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||||
Assert.Equal(expectedVal, actualVal);
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveOutputFileTest()
|
public void IsOutputFileRemoved()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
@ -197,6 +212,7 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
||||||
|
output.WriteLine("Actual value: {0}, Expected value: {1}", actualAttribute, expectedAttribute);
|
||||||
Assert.Equal(expectedAttribute, actualAttribute);
|
Assert.Equal(expectedAttribute, actualAttribute);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -218,7 +234,7 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
"('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-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||||
|
|
||||||
for (int i = 0; i < 11; i++)
|
for (int i = 0; i <= 11; i++)
|
||||||
{
|
{
|
||||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
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;");
|
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
@ -229,95 +245,133 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
archiveManager.Controller();
|
archiveManager.Controller();
|
||||||
timer.Stop();
|
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()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
|
|
||||||
// Act
|
|
||||||
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[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
|
||||||
Assert.True(true);
|
var actualVal = timer.Elapsed.Seconds;
|
||||||
|
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||||
|
Assert.True(actualVal < expectedVal);
|
||||||
|
|
||||||
|
// Clean up resources after testing
|
||||||
|
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
output.WriteLine("Cleaning up completed... ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsArchive_Under_60s_1mRecords()
|
||||||
|
{
|
||||||
|
// 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.Elapsed.Seconds;
|
||||||
|
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||||
|
Assert.True(actualVal < expectedVal);
|
||||||
|
|
||||||
|
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||||
|
//Clean up resources after testing
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
output.WriteLine("Cleaning up completed... ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
// [Test Method]
|
||||||
|
public void IsProcessFlowCompleted()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||||
|
bool expectedVal = true;
|
||||||
|
bool actualVal = false;
|
||||||
|
string folderPath = @"C:/HobbyArchive";
|
||||||
|
|
||||||
|
// Adding 10000 records to database for testing
|
||||||
|
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 j = 0; j <= 11; j++)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
// Testing archive Manager
|
||||||
|
int i = -10;
|
||||||
|
while (i < 20)
|
||||||
|
{
|
||||||
|
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
||||||
|
string currentTime = "00:00:00 AM";
|
||||||
|
string currentDate = i.ToString();
|
||||||
|
|
||||||
|
if (i == 1)
|
||||||
|
{
|
||||||
|
currentDate = date1.ToString("dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
//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");
|
||||||
|
actualVal = archive.Controller();
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||||
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
output.WriteLine("Cleaning up completed... ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user