diff --git a/Refactoring/Refactoring.csproj b/Refactoring/Refactoring.csproj
index 6696ba9..4ec237a 100644
--- a/Refactoring/Refactoring.csproj
+++ b/Refactoring/Refactoring.csproj
@@ -36,6 +36,25 @@
..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
True
+
+ ..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.dll
+ False
+
+
+ ..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.interfaces.dll
+ False
+
+
+ ..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.framework.dll
+
+
+ ..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.util.dll
+ False
+
+
+ ..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll
+ False
+
diff --git a/Refactoring/Tusc.cs b/Refactoring/Tusc.cs
index bd07dce..3cc0159 100644
--- a/Refactoring/Tusc.cs
+++ b/Refactoring/Tusc.cs
@@ -5,33 +5,31 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Collections;
namespace Refactoring
{
public class Tusc
{
+
public static void Start(List usrs, List prods)
{
- // Write welcome message
- Console.WriteLine("Welcome to TUSC");
- Console.WriteLine("---------------");
+
+ DisplayWelcomeMessage();
// Login
Login:
bool loggedIn = false; // Is logged in?
-
- // Prompt for user input
- Console.WriteLine();
- Console.WriteLine("Enter Username:");
- string name = Console.ReadLine();
+
+ string name = GetUserName();
// Validate Username
bool valUsr = false; // Is valid user?
+
if (!string.IsNullOrEmpty(name))
{
- for (int i = 0; i < 5; i++)
+ foreach (User user in usrs)
{
- User user = usrs[i];
// Check that name matches
if (user.Name == name)
{
@@ -42,16 +40,12 @@ public static void Start(List usrs, List prods)
// if valid user
if (valUsr)
{
- // Prompt for user input
- Console.WriteLine("Enter Password:");
- string pwd = Console.ReadLine();
+ string pwd = GetCredentials();
// Validate Password
bool valPwd = false; // Is valid password?
- for (int i = 0; i < 5; i++)
+ foreach (User user in usrs)
{
- User user = usrs[i];
-
// Check that name and password match
if (user.Name == name && user.Pwd == pwd)
{
@@ -64,46 +58,25 @@ public static void Start(List usrs, List prods)
{
loggedIn = true;
- // Show welcome message
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine();
- Console.WriteLine("Login successful! Welcome " + name + "!");
- Console.ResetColor();
+ DisplayLoginMessage(name);
// Show remaining balance
- double bal = 0;
- for (int i = 0; i < 5; i++)
- {
- User usr = usrs[i];
-
+ double bal = 0;
+ foreach (User user in usrs)
+ {
// Check that name and password match
- if (usr.Name == name && usr.Pwd == pwd)
+ if (user.Name == name && user.Pwd == pwd)
{
- bal = usr.Bal;
+ bal = user.Bal;
- // Show balance
- Console.WriteLine();
- Console.WriteLine("Your balance is " + usr.Bal.ToString("C"));
+ ShowBalanceMessaege();
}
}
// Show product list
while (true)
{
- // Prompt for user input
- Console.WriteLine();
- Console.WriteLine("What would you like to buy?");
- for (int i = 0; i < 7; i++)
- {
- Product prod = prods[i];
- Console.WriteLine(i + 1 + ": " + prod.Name + " (" + prod.Price.ToString("C") + ")");
- }
- Console.WriteLine(prods.Count + 1 + ": Exit");
-
- // Prompt for user input
- Console.WriteLine("Enter a number:");
- string answer = Console.ReadLine();
+ string answer = GetUserInput(prods);
int num = Convert.ToInt32(answer);
num = num - 1; /* Subtract 1 from number
num = num + 1 // Add 1 to number */
@@ -226,5 +199,61 @@ public static void Start(List usrs, List prods)
Console.WriteLine("Press Enter key to exit");
Console.ReadLine();
}
+
+private static string GetUserInput(List prods)
+{
+ // Prompt for user input
+ Console.WriteLine();
+ Console.WriteLine("What would you like to buy?");
+ foreach (Product prod in prods)
+ {
+ Console.WriteLine( (prods.FindIndex(prod.Equals) + ": " + prod.Name + " (" + prod.Price.ToString("C") + ")");
+ }
+ Console.WriteLine(prods.Count + 1 + ": Exit");
+
+ // Prompt for user input
+ Console.WriteLine("Enter a number:");
+ string answer = Console.ReadLine();
+return answer;
+}
+
+ private static void ShowBalanceMessaege()
+ {
+ // Show balance
+ Console.WriteLine();
+ Console.WriteLine("Your balance is " + usr.Bal.ToString("C"));
+ }
+
+ private static void DisplayLoginMessage(string name)
+ {
+ // Show welcome message
+ Console.Clear();
+ Console.ForegroundColor = ConsoleColor.Green;
+ Console.WriteLine();
+ Console.WriteLine("Login successful! Welcome " + name + "!");
+ Console.ResetColor();
+ }
+
+ private static string GetCredentials()
+ {
+ // Prompt for user input
+ Console.WriteLine("Enter Password:");
+ string pwd = Console.ReadLine();
+ return pwd;
+ }
+
+ private static string GetUserName()
+ {
+ Console.WriteLine();
+ Console.WriteLine("Enter Username:");
+ string name = Console.ReadLine();
+ return name;
+ }
+
+ private static void DisplayWelcomeMessage()
+ {
+ Console.WriteLine("Welcome to TUSC");
+ Console.WriteLine("---------------");
+ }
}
}
diff --git a/Refactoring/packages.config b/Refactoring/packages.config
index 2abc396..21b1784 100644
--- a/Refactoring/packages.config
+++ b/Refactoring/packages.config
@@ -1,4 +1,5 @@
+
\ No newline at end of file