fixed testing, add archive path to menu

This commit is contained in:
Im_Alpha 2021-12-15 17:13:36 -08:00
parent f11ed7d6ad
commit 27080ce36c
4 changed files with 43 additions and 27 deletions

View File

@ -121,16 +121,16 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
return false;
}
}
public bool BulkOperation(string signedUser, IDataSource<string> dbSource)
public bool BulkOperation(string signedUser, string path, IDataSource<string> dbSource)
{
try
{
// Get the current directory.
string path = Directory.GetCurrentDirectory();
//string path = Directory.GetCurrentDirectory();
// Open file reader stream
using StreamReader fileRead = new(path + "\\BulkOps\\Bulk.txt"); // path + "\\BulkOps\\{input}"
using StreamReader fileRead = new(path); // path + + "\\BulkOps\\Bulk.txt"
// Show location of the file being written
Console.WriteLine(path + "\\BulkOps\\Bulk.txt");
//Console.WriteLine(path);
// List choices of operations
List<string> ops = new List<string> {"Create Account", "Edit Account",

View File

@ -313,7 +313,8 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
// Get name of file and update path to correct folder
Console.WriteLine("Please input the name of the file:(Example.txt)");
string filename = $"{path}\\BulkOps\\{Console.ReadLine()}";
//Console.WriteLine(filename)
// Get filesize
long fileSize = filename.Length;
long fileSizeGB = fileSize / (1024 * 1024);
@ -334,7 +335,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
{
// Begin bulk operation
Console.WriteLine("Running bulk operation...");
bool bulkReq = bulkOP.BulkOperation(user.username, dbSource);
bool bulkReq = bulkOP.BulkOperation(user.username, filename, dbSource);
if (bulkReq is true)
{
Console.WriteLine("\nBulk operation complete");
@ -352,6 +353,7 @@ namespace TeamHobby.HobbyProjectGenerator.UserManagement
break;
// View archive
case 8:
Console.WriteLine("C:/HobbyArchive");
break;
default:
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");

View File

@ -4,6 +4,7 @@ using Xunit.Abstractions;
using System.Threading;
using TeamHobby.HobbyProjectGenerator.UserManagement;
using TeamHobby.HobbyProjectGenerator.DataAccess;
using System.IO;
namespace TeamHobby.UserManagement.xTests
{
@ -47,7 +48,7 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 5)
{
output.WriteLine("Single Operation was unsuccessful");
Assert.False(true);
Assert.True(false);
}
else
{
@ -73,7 +74,7 @@ namespace TeamHobby.UserManagement.xTests
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=hobby;" +
"PASSWORD=Teamhobby;" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
@ -89,11 +90,11 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 5)
{
output.WriteLine("Single Operation was unsuccessful");
Assert.False(true);
Assert.False(false);
}
else
{
Assert.True(true);
Assert.True(false);
output.WriteLine("Single Operation was successful");
}
}
@ -103,7 +104,7 @@ namespace TeamHobby.UserManagement.xTests
{
// Arrange
DateTime sTime = DateTime.Now;
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
@ -126,12 +127,14 @@ namespace TeamHobby.UserManagement.xTests
var sec = timeDiff.TotalSeconds;
// Assert
if (sec > 0)
if (sec > 5)
{
var message = "Single Operation was unsuccessful";
Assert.False(true);
output.WriteLine(message);
if (checkMess)
{
Assert.False(true);
throw new Exception("Message was not printed");
}
}
@ -157,6 +160,7 @@ namespace TeamHobby.UserManagement.xTests
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
string path = Directory.GetCurrentDirectory();
// Testing Data Access Layer
@ -171,11 +175,11 @@ namespace TeamHobby.UserManagement.xTests
// Act
// Create a file
for (int i = 0; i < 10000; i++)
{
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
serviceTest.DeleteUserRecord(TestAcc, "Rifat", datasource);
}
//for (int i = 0; i < 10000; i++)
//{
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
serviceTest.BulkOperation("Rifat", path + "\\BulkOps\\Bulk.txt", datasource);
//}
DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime);
@ -186,9 +190,11 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 60)
{
var message = "Bulk Operation was unsuccessful";
Assert.True(false);
output.WriteLine(message);
if (checkMess)
{
Assert.True(false);
throw new Exception("Message was not printed");
}
}
@ -214,6 +220,9 @@ namespace TeamHobby.UserManagement.xTests
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
string dir = Directory.GetCurrentDirectory();
string path = dir + "\\BulkOps\\Bulk.txt";
output.WriteLine(path);
// Testing Data Access Layer
@ -222,17 +231,17 @@ namespace TeamHobby.UserManagement.xTests
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=hobby;" +
"PASSWORD=Teamhobby;" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
// Act
// Create a file
for (int i = 0; i < 10000; i++) // Change 10000 to how many accounts you want to test
{
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
}
//for (int i = 0; i < 10000; i++)
//{
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
serviceTest.BulkOperation("Rifat", path, datasource);
//}
DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime);
@ -243,7 +252,7 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 60)
{
output.WriteLine("Bulk Operation was unsuccessful");
Assert.False(true);
Assert.True(false);
}
else
{

View File

@ -29,9 +29,14 @@ namespace TeamHobby.HobbyProjectGenerator.Main
// Loop Admin login
while (mainMenu is true)
{
// Create credentials object
GetCredentials credentials = new GetCredentials();
// Get DB credentials ***Both values currently hard coded, will update to user input later on.***
string dbUserName = "root";
string dbPassword = "Teamhobby";
// Admin Sign in
GetCredentials credentials = new GetCredentials();
Console.WriteLine("\nPlease Enter Admin Credentials " +
"or enter 0 to exit the machine\n");
string? username = credentials.GetUserName();
@ -56,8 +61,8 @@ namespace TeamHobby.HobbyProjectGenerator.Main
"TCPIP=1;" +
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=Teamhobby;" +
$"UID={dbUserName};" +
$"PASSWORD={dbPassword};" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);