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; return false;
} }
} }
public bool BulkOperation(string signedUser, IDataSource<string> dbSource) public bool BulkOperation(string signedUser, string path, IDataSource<string> dbSource)
{ {
try try
{ {
// Get the current directory. // Get the current directory.
string path = Directory.GetCurrentDirectory(); //string path = Directory.GetCurrentDirectory();
// Open file reader stream // 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 // Show location of the file being written
Console.WriteLine(path + "\\BulkOps\\Bulk.txt"); //Console.WriteLine(path);
// List choices of operations // List choices of operations
List<string> ops = new List<string> {"Create Account", "Edit Account", List<string> ops = new List<string> {"Create Account", "Edit Account",

View File

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

View File

@ -4,6 +4,7 @@ using Xunit.Abstractions;
using System.Threading; using System.Threading;
using TeamHobby.HobbyProjectGenerator.UserManagement; using TeamHobby.HobbyProjectGenerator.UserManagement;
using TeamHobby.HobbyProjectGenerator.DataAccess; using TeamHobby.HobbyProjectGenerator.DataAccess;
using System.IO;
namespace TeamHobby.UserManagement.xTests namespace TeamHobby.UserManagement.xTests
{ {
@ -15,6 +16,7 @@ namespace TeamHobby.UserManagement.xTests
{ {
this.output = output; 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] [Fact]
public void SingleOperationinFiveSec() public void SingleOperationinFiveSec()
{ {
@ -46,7 +48,7 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 5) if (sec > 5)
{ {
output.WriteLine("Single Operation was unsuccessful"); output.WriteLine("Single Operation was unsuccessful");
Assert.False(true); Assert.True(false);
} }
else else
{ {
@ -55,16 +57,111 @@ namespace TeamHobby.UserManagement.xTests
} }
} }
// Single UM operation takes longer than 5 seconds
[Fact] [Fact]
public void BulkOperationforSixty() public void FailSingleOperationinFiveSec()
{ {
// Arrange // Arrange
DateTime sTime = DateTime.Now; DateTime sTime = DateTime.Now;
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
var serviceTest = new AccountService(); var serviceTest = new AccountService();
string dbType = "sql"; string dbType = "sql";
RDSFactory dbFactory = new RDSFactory(); 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 // Testing Data Access Layer
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" + string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
@ -78,11 +175,73 @@ namespace TeamHobby.UserManagement.xTests
// Act // Act
// Create a file // 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); var message = "Bulk Operation was unsuccessful";
serviceTest.DeleteUserRecord(TestAcc, "Rifat", datasource); 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; DateTime eTime = DateTime.Now;
TimeSpan timeDiff = (eTime - sTime); TimeSpan timeDiff = (eTime - sTime);
@ -93,7 +252,7 @@ namespace TeamHobby.UserManagement.xTests
if (sec > 60) if (sec > 60)
{ {
output.WriteLine("Bulk Operation was unsuccessful"); output.WriteLine("Bulk Operation was unsuccessful");
Assert.False(true); Assert.True(false);
} }
else else
{ {

View File

@ -29,9 +29,14 @@ namespace TeamHobby.HobbyProjectGenerator.Main
// Loop Admin login // Loop Admin login
while (mainMenu is true) 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 // Admin Sign in
GetCredentials credentials = new GetCredentials();
Console.WriteLine("\nPlease Enter Admin Credentials " + Console.WriteLine("\nPlease Enter Admin Credentials " +
"or enter 0 to exit the machine\n"); "or enter 0 to exit the machine\n");
string? username = credentials.GetUserName(); string? username = credentials.GetUserName();
@ -56,8 +61,8 @@ namespace TeamHobby.HobbyProjectGenerator.Main
"TCPIP=1;" + "TCPIP=1;" +
"SERVER=localhost;" + "SERVER=localhost;" +
"DATABASE=hobby;" + "DATABASE=hobby;" +
"UID=root;" + $"UID={dbUserName};" +
"PASSWORD=Teamhobby;" + $"PASSWORD={dbPassword};" +
"OPTION=3"; "OPTION=3";
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo); IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);