Creating test methods for archiving
This commit is contained in:
parent
4a2bd5b38f
commit
e8d42bf98f
@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.ArchiveTests
|
||||||
|
{
|
||||||
|
public class ArchivingTests
|
||||||
|
{
|
||||||
|
//private string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
// "SERVER=localhost;" +
|
||||||
|
// "DATABASE=hobby;" +
|
||||||
|
// "UID=root;" +
|
||||||
|
// "PASSWORD=Teamhobby;" +
|
||||||
|
// "OPTION=3";
|
||||||
|
|
||||||
|
|
||||||
|
// [TestMethod]
|
||||||
|
public void CreateFolderTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
if (expectedVal == actualVal)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Folder created correctly", expectedVal, actualVal);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(folderPath, true);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Console.WriteLine("Folder failed to be deleted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. Folder created incorrectly", expectedVal, actualVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// [TestMethod]
|
||||||
|
public void CreateFileNameTest(IDataSource<string> sqlDAO)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
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
|
||||||
|
bool result = String.Equals(actualFilePath, expectedFilePath);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. File name created correctly", expectedFilePath, actualFilePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Expected: {0}, Actual: {1}. File name created incorrectly", expectedFilePath, actualFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FolderCreationFailed()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||||
|
//ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||||
|
|
||||||
|
// Testing folder creation
|
||||||
|
ArchivingTests test = new ArchivingTests();
|
||||||
|
test.CreateFolderTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
// Testing file creation
|
||||||
|
test.CreateFileNameTest(sqlDAO);
|
||||||
|
Console.WriteLine("-----------------");
|
||||||
|
Console.WriteLine("");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ArchiveTests", "..\TeamHobby.HobbyProjectGenerator.ArchiveTests\TeamHobby.HobbyProjectGenerator.ArchiveTests.csproj", "{C5EBD1F8-C806-4BF9-B2D7-8876072630FD}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -48,6 +50,10 @@ 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
|
||||||
|
{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.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user