Merge branch 'Jacobs-Branch'

This commit is contained in:
Im_Alpha 2021-12-15 17:13:51 -08:00
commit 5dacebdffd
4 changed files with 184 additions and 18 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
{
@ -15,6 +16,7 @@ namespace TeamHobby.UserManagement.xTests
{
this.output = output;
}
// User is able to perform any single UM operation within 5 seconds upon invocation.A system message displays “UM operation was successful”
[Fact]
public void SingleOperationinFiveSec()
{
@ -46,7 +48,7 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 5)
{
output.WriteLine("Single Operation was unsuccessful");
Assert.False(true);
Assert.True(false);
}
else
{
@ -54,17 +56,112 @@ namespace TeamHobby.UserManagement.xTests
output.WriteLine("Single Operation was successful");
}
}
// Single UM operation takes longer than 5 seconds
[Fact]
public void BulkOperationforSixty()
public void FailSingleOperationinFiveSec()
{
// Arrange
DateTime sTime = DateTime.Now;
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
// Testing Data Access Layer
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
"TCPIP=1;" +
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=Teamhobby;" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
// Act
// Create a file
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
Thread.Sleep(6000);
DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime);
var sec = timeDiff.TotalSeconds;
// Assert
if (sec > 5)
{
output.WriteLine("Single Operation was unsuccessful");
Assert.False(false);
}
else
{
Assert.True(false);
output.WriteLine("Single Operation was successful");
}
}
// Single UM operation completes within 5 seconds, but no system message is shown or inaccurate system message is shown
[Fact]
public void SingleOperationwithMessage()
{
// Arrange
DateTime sTime = DateTime.Now;
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
var checkMess = false;
// Testing Data Access Layer
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
"TCPIP=1;" +
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=Teamhobby;" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
// Act
// Create a file
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime);
var sec = timeDiff.TotalSeconds;
// Assert
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");
}
}
else
{
Assert.True(true);
var message2 = "Single Operation was successful";
output.WriteLine(message2);
if (!checkMess)
{
output.WriteLine("Message was printed");
Assert.True(true);
}
}
}
// Bulk UM operations completes within 60 seconds, but no system message is shown or inaccurate system message is shown
[Fact]
public void BulkOperationwithMessage()
{
// Arrange
DateTime sTime = DateTime.Now;
var checkMess = false;
var serviceTest = new AccountService();
string dbType = "sql";
RDSFactory dbFactory = new RDSFactory();
string path = Directory.GetCurrentDirectory();
// Testing Data Access Layer
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
@ -78,12 +175,74 @@ namespace TeamHobby.UserManagement.xTests
// Act
// Create a file
for (int i = 0; i < 10000; i++)
//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);
var sec = timeDiff.TotalSeconds;
// Assert
if (sec > 60)
{
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
serviceTest.DeleteUserRecord(TestAcc, "Rifat", datasource);
var message = "Bulk Operation was unsuccessful";
Assert.True(false);
output.WriteLine(message);
if (checkMess)
{
Assert.True(false);
throw new Exception("Message was not printed");
}
}
else
{
Assert.True(true);
var message2 = "Bulk Operation was successful";
output.WriteLine(message2);
if (!checkMess)
{
output.WriteLine("Message was printed");
Assert.True(true);
}
}
}
// User is able to perform less than 10K UM operations in bulk within 60 seconds. A system message displays “Bulk UM operation was successful”
[Fact]
public void BulkOperationforSixty()
{
// Arrange
DateTime sTime = DateTime.Now;
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
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
"TCPIP=1;" +
"SERVER=localhost;" +
"DATABASE=hobby;" +
"UID=root;" +
"PASSWORD=Teamhobby;" +
"OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
// 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.BulkOperation("Rifat", path, datasource);
//}
DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime);
var sec = timeDiff.TotalSeconds;
@ -93,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);