Merge branch 'Long_archivePos'
This commit is contained in:
commit
6e8e2f9756
@ -72,29 +72,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method overload to take in a specific path
|
|
||||||
public string CreateOutFileName(string archivePath)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//string path = archivePath + "\\HobbyArchive";
|
|
||||||
Console.WriteLine("The current directory is {0}", archivePath);
|
|
||||||
//string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss");
|
|
||||||
string date = DateTime.Now.ToString("M_d_yyyy");
|
|
||||||
string fileName = date + "_archive.csv";
|
|
||||||
string filePath = Path.Combine(archivePath, fileName);
|
|
||||||
|
|
||||||
Console.WriteLine("Date: {0}", date);
|
|
||||||
Console.WriteLine("Filepath: {0}", filePath);
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("ArchiveCon: Creating a file name failed. ");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// put everything toget here
|
// put everything toget here
|
||||||
public bool Controller(){
|
public bool Controller(){
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Platforms>AnyCPU;x86</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="8.0.27" />
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Implementations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Odbc;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -197,6 +198,98 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RemoveEntriesTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
Console.WriteLine("TESTING - REMOVE ENTRIES");
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
SqlDAO sqlDS = null;
|
||||||
|
|
||||||
|
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||||
|
{
|
||||||
|
sqlDS = (SqlDAO)sqlDAO;
|
||||||
|
//sqlDS.GetConnection().Open();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Console.WriteLine("\nInserting into archive...");
|
||||||
|
sqlDS.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')," +
|
||||||
|
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully');");
|
||||||
|
|
||||||
|
OdbcDataReader odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (odbcObj.Read()) { ++count; }
|
||||||
|
Console.WriteLine("Number of entries > 30 days old: " + count);
|
||||||
|
|
||||||
|
Console.WriteLine("\nRemoving entries from archive...");
|
||||||
|
sqlDS.RemoveEntries();
|
||||||
|
|
||||||
|
odbcObj = (OdbcDataReader)sqlDS.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
while (odbcObj.Read()) { ++count; }
|
||||||
|
Console.WriteLine("Number of entries > 30 days old: " + count);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool expectedVal = true;
|
||||||
|
bool actualVal = !Convert.ToBoolean(count);
|
||||||
|
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {0}. Entries removed correctly.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {1}. Entries not removed.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sqlDS.GetConnection().Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveOutputFileTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
Console.WriteLine("TESTING - REMOVE OUTPUT FILE\n");
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
SqlDAO sqlDS = null;
|
||||||
|
|
||||||
|
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||||
|
{
|
||||||
|
sqlDS = (SqlDAO)sqlDAO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string filepath = archiveManager.CreateOutFileName();
|
||||||
|
Console.WriteLine("\nRemoving file...");
|
||||||
|
sqlDS.RemoveOutputFile(filepath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool expectedVal = false;
|
||||||
|
bool actualVal = File.Exists(filepath);
|
||||||
|
Console.WriteLine("Checking if file exists: " + actualVal);
|
||||||
|
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {0}. Output file removed correctly.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("\nExpected: {0}, Actual: {1}. Output file NOT removed.", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
@ -206,6 +299,7 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
|||||||
"PASSWORD=Teamhobby;" +
|
"PASSWORD=Teamhobby;" +
|
||||||
"OPTION=3";
|
"OPTION=3";
|
||||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
sqlDAO.GetConnection().Open();
|
||||||
//ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
//ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
// Testing folder creation
|
// Testing folder creation
|
||||||
@ -226,12 +320,21 @@ namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
|||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Testing clean up sequence
|
// Testing clean up sequence
|
||||||
//test.IsCleaningUpCompleted(sqlDAO);
|
//test.IsCleaningUpCompleted(sqlDAO);
|
||||||
//Console.WriteLine("-----------------");
|
//Console.WriteLine("-----------------");
|
||||||
//Console.WriteLine("");
|
//Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing remove entries
|
||||||
|
test.RemoveEntriesTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing remove output file
|
||||||
|
test.RemoveOutputFileTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
sqlDAO.GetConnection().Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,7 +155,9 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
|||||||
// Check to see if the file is hidden or already compressed before compressing the file.
|
// Check to see if the file is hidden or already compressed before compressing the file.
|
||||||
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
||||||
{
|
{
|
||||||
using FileStream outputFile = File.Create(fileName + ".gz");
|
var compFileName = Path.ChangeExtension(fileName, ".gz");
|
||||||
|
//using FileStream outputFile = File.Create(fileName + ".gz");
|
||||||
|
using FileStream outputFile = File.Create(compFileName);
|
||||||
|
|
||||||
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
||||||
origFile.CopyTo(compressor);
|
origFile.CopyTo(compressor);
|
||||||
|
|||||||
@ -0,0 +1,320 @@
|
|||||||
|
using System;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace TeamHobby.Archiving.xTests
|
||||||
|
{
|
||||||
|
public class ArchivingXUnitTest
|
||||||
|
{
|
||||||
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsArchiveFolderCreated()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
string folderPath = @"C:/HobbyArchive";
|
||||||
|
bool expectedVal = true;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
archiveManager.CreateArchiveFolder();
|
||||||
|
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool actualVal = Directory.Exists(folderPath);
|
||||||
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
// Cleaning up directory after test
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsFileNameCreated()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
string foldPath = @"C:\HobbyArchive";
|
||||||
|
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
||||||
|
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
string actualFilePath = archiveManager.CreateOutFileName();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
|
||||||
|
Assert.Equal(expectedFilePath, actualFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsCSVFileExist()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
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
|
||||||
|
if (sqlDS != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlDS.CopyToFile(filePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Copying to a file failed !!");
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool actualVal = File.Exists(filePath);
|
||||||
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RemoveEntriesTest()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
OdbcDataReader odbcObj = null;
|
||||||
|
Object resultData = null;
|
||||||
|
bool expectedVal = false;
|
||||||
|
|
||||||
|
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');");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
sqlDAO.RemoveEntries();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool actualVal;
|
||||||
|
|
||||||
|
resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||||
|
if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader)))
|
||||||
|
{
|
||||||
|
odbcObj = (OdbcDataReader)resultData;
|
||||||
|
}
|
||||||
|
OdbcConnection conn = sqlDAO.GetConnection();
|
||||||
|
actualVal = odbcObj.HasRows;
|
||||||
|
conn.Close();
|
||||||
|
|
||||||
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RemoveOutputFileTest()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
bool expectedVal = false;
|
||||||
|
//Thread.Sleep(5000);
|
||||||
|
|
||||||
|
// Create the folder and the csv file for compressing
|
||||||
|
archiveManager.CreateArchiveFolder();
|
||||||
|
string filepath = archiveManager.CreateOutFileName();
|
||||||
|
sqlDAO.CopyToFile(filepath);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
if (sqlDAO != null)
|
||||||
|
{
|
||||||
|
sqlDAO.RemoveOutputFile(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
bool actualVal = File.Exists(filepath);
|
||||||
|
Assert.Equal(expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsFileCompressed()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Create the folder and the csv file to be compressed.
|
||||||
|
archiveManager.CreateArchiveFolder();
|
||||||
|
string filePath = archiveManager.CreateOutFileName();
|
||||||
|
sqlDAO.CopyToFile(filePath);
|
||||||
|
FileAttributes expectedAttribute = FileAttributes.Archive;
|
||||||
|
string compFilePath = Path.ChangeExtension(filePath, ".gz");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
sqlDAO.CompressFile(filePath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
||||||
|
Assert.Equal(expectedAttribute, actualAttribute);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsArchive_Under_60s_10kRecords()
|
||||||
|
{
|
||||||
|
// 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 < 11; 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 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[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.True(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.UserManagement", "..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj", "{2E7193B8-86B6-48DA-9671-CD84615A5F5D}"
|
||||||
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}"
|
||||||
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.xTests", "TeamHobby.UserManagement.xTests\TeamHobby.UserManagement.xTests.csproj", "{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.xTests", "TeamHobby.UserManagement.xTests\TeamHobby.UserManagement.xTests.csproj", "{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}"
|
||||||
@ -28,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj
|
TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.Archiving.xTests", "TeamHobby.Archiving.xTests\TeamHobby.Archiving.xTests.csproj", "{8C039F49-13D3-4AEE-A1C3-A880751852BB}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -38,6 +42,7 @@ Global
|
|||||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
@ -52,21 +57,26 @@ Global
|
|||||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{C0494115-838E-43A3-8896-133E5D1E874A}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2E7193B8-86B6-48DA-9671-CD84615A5F5D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{CA8D11CF-807C-4C90-A529-0371F73518F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6D575AF1-C138-44C5-B701-5AEC4ACEAA7A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8C039F49-13D3-4AEE-A1C3-A880751852BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8C039F49-13D3-4AEE-A1C3-A880751852BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8C039F49-13D3-4AEE-A1C3-A880751852BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8C039F49-13D3-4AEE-A1C3-A880751852BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -68,7 +68,7 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
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);
|
//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, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
||||||
{
|
{
|
||||||
ArchiveManager archive = new ArchiveManager(datasource);
|
ArchiveManager archive = new ArchiveManager(datasource);
|
||||||
archive.Controller();
|
archive.Controller();
|
||||||
|
|||||||
23
Source Code/main/main - Backup.csproj
Normal file
23
Source Code/main/main - Backup.csproj
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj" />
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user