Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f8d7993
Fool with some NuGet stuff trying to get the tests to run and do a si…
rurbonas-vms Jan 29, 2016
b762a24
Let writeMessage() take multiple messages to display. It's not a grea…
rurbonas-vms Jan 29, 2016
7574300
Another simple refactoring to reduce code size. Nothing fancy.
rurbonas-vms Jan 29, 2016
73915f3
Start abstracting out the UI
rurbonas-vms Jan 29, 2016
df817ca
Refactor more of the UI - start grabbing user input via the UI now
rurbonas-vms Jan 29, 2016
8265001
Refactor more of the UI - prompting the user to exit
rurbonas-vms Jan 29, 2016
d01c9a4
Rename some parameters in preparation to factor out the login code
rurbonas-vms Jan 29, 2016
b2748fb
More preparation for breaking out the login code
rurbonas-vms Jan 29, 2016
52a88fd
Rename some variables to help breaking out the login code
rurbonas-vms Jan 29, 2016
87bfe2b
Remove some superfluous comments
rurbonas-vms Jan 29, 2016
a9027b0
Remove some superfluous comments
rurbonas-vms Jan 29, 2016
1c337ce
Stub out a fake UI for testing purposes
rurbonas-vms Jan 29, 2016
ee8545a
Stub out a fake UI for testing purposes
rurbonas-vms Jan 29, 2016
84dd976
Start moving login logic to LoginManager
rurbonas-vms Jan 29, 2016
ebfb1a2
Move more stuff to LoginManager
rurbonas-vms Jan 29, 2016
a73d4f9
Factor more login stuff out
rurbonas-vms Jan 29, 2016
7b16673
Factor more login stuff out
rurbonas-vms Jan 29, 2016
f29f9f2
Factor more login stuff out
rurbonas-vms Jan 29, 2016
cac8aa5
Factor more login stuff out
rurbonas-vms Jan 29, 2016
8689171
Factor more login stuff out
rurbonas-vms Jan 29, 2016
16affd3
Start improving the LoginManager - return the found user, if any
rurbonas-vms Jan 29, 2016
f8a330b
Fix a bug that prevented more than five users from existing in the sy…
rurbonas-vms Jan 29, 2016
7610351
Add a test for an edge case
rurbonas-vms Jan 29, 2016
124c365
Brute-force the Tusc code to use the LoginManager; there's room for i…
rurbonas-vms Jan 29, 2016
b734943
Nuget Fixes?
rurbonas-vms Jan 29, 2016
db30b27
Use environment-agnostic newlines where necessary and fix some unreac…
rurbonas-vms Jan 29, 2016
c523719
LINQ-ify the LoginManager and address some missed \r\n characters in …
rurbonas-vms Jan 29, 2016
6054508
Cleanups to LoginManager
rurbonas-vms Jan 29, 2016
cc83536
More cleanups to LoginManager
rurbonas-vms Jan 29, 2016
4ffa242
Improve the names of the properties of User
rurbonas-vms Jan 29, 2016
9442283
Improve some variable names in Tusc
rurbonas-vms Jan 29, 2016
a7cd926
Improve the name of the Quantity property in Product
rurbonas-vms Jan 29, 2016
bd18685
Remove the old displayMessages() method from Tusc and rely on the UI
rurbonas-vms Jan 29, 2016
54c339f
More minor tweaks
rurbonas-vms Jan 29, 2016
aa8874f
Extract a method
rurbonas-vms Jan 29, 2016
7c02d77
Minor cleanups
rurbonas-vms Jan 29, 2016
c8f6def
Move the file manipulation out of Tusc so we can clean up a lot of re…
rurbonas-vms Jan 29, 2016
fea2696
Make a skeleton Store to manage our products
rurbonas-vms Jan 29, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Refactoring.sln
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Refactoring", "Refactoring\Refactoring.csproj", "{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "UnitTestProject\UnitTestProject.csproj", "{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Debug|x64.ActiveCfg = Debug|x64
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Debug|x64.Build.0 = Debug|x64
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Release|Any CPU.Build.0 = Release|Any CPU
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Release|x64.ActiveCfg = Release|x64
{2D3F5D0E-4A6B-44C0-8F63-8E95243AC028}.Release|x64.Build.0 = Release|x64
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Debug|x64.ActiveCfg = Debug|x64
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Debug|x64.Build.0 = Debug|x64
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Release|Any CPU.Build.0 = Release|Any CPU
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Release|x64.ActiveCfg = Release|x64
{1FAF99A1-CCBF-435D-B599-4DAE1DAD5105}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
56 changes: 56 additions & 0 deletions Refactoring/ConsoleUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactoring
{
public class ConsoleUserInterface : UserInterface
{
public void displayBanner(string bannerText)
{
Console.WriteLine(bannerText);
Console.WriteLine(new string('-', bannerText.Length));
}

public string getStringInputFromUser(string labelText)
{
Console.WriteLine();
Console.WriteLine(labelText);
return Console.ReadLine();
}

public void promptUserToExit()
{
Console.WriteLine();
Console.WriteLine("Press Enter key to exit");
Console.ReadLine();
}

public void displayErrors(params string[] errorText)
{
displayMessageWithColor(ConsoleColor.Red, errorText);
}

public void displayWarnings(params string[] warningText)
{
displayMessageWithColor(ConsoleColor.Yellow, warningText);
}

public void displayNotices(params string[] noticeText)
{
displayMessageWithColor(ConsoleColor.Green, noticeText);
}

private void displayMessageWithColor(ConsoleColor color, params string[] messages)
{
Console.Clear();
Console.ForegroundColor = color;
Console.WriteLine();
foreach (string message in messages)
Console.WriteLine(message);
Console.ResetColor();
}
}
}
63 changes: 63 additions & 0 deletions Refactoring/LoginManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactoring
{
public class LoginManager
{
private UserInterface ui;
private IEnumerable<User> users;

public LoginManager(IEnumerable<User> users, UserInterface ui)
{
if (users == null)
throw new ArgumentException();

if (ui == null)
throw new ArgumentException();

this.users = users;
this.ui = ui;
}

private bool isUserNameValid(string userName)
{
return users.Any(user => user.Name == userName);
}

private User getUserByUserNameAndPassword(string userName, string password)
{
return users.FirstOrDefault(user => user.Name == userName && user.Password == password);
}

public User login()
{
while (true) // RFUTODO: Temporary!
{
string userName = ui.getStringInputFromUser(Environment.NewLine + "Enter Username:"); // TODO: Deal with the extra line we need to add here

if (string.IsNullOrEmpty(userName))
return null;

if (isUserNameValid(userName))
{
string password = ui.getStringInputFromUser("Enter Password:");

User matchingUser = getUserByUserNameAndPassword(userName, password);

if (matchingUser != null)
return matchingUser;

ui.displayErrors("You entered an invalid password.");
}
else
{
ui.displayErrors("You entered an invalid user.");
}
}
}
}
}
2 changes: 1 addition & 1 deletion Refactoring/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class Product
[JsonProperty("Price")]
public double Price;
[JsonProperty("Quantity")]
public int Qty;
public int Quantity;
}
}
15 changes: 10 additions & 5 deletions Refactoring/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ namespace Refactoring
{
public class Program
{
private static string USERS_FILE = @"Data/Users.json";
private static string PRODUCTS_FILE = @"Data/Products.json";

public static void Main(string[] args)
{
// Load users from data file
List<User> users = JsonConvert.DeserializeObject<List<User>>(File.ReadAllText(@"Data/Users.json"));
List<User> users = JsonConvert.DeserializeObject<List<User>>(File.ReadAllText(USERS_FILE));
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(File.ReadAllText(PRODUCTS_FILE));

UserInterface ui = new ConsoleUserInterface();

// Load products from data file
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(File.ReadAllText(@"Data/Products.json"));
Tusc.Start(users, products, ui);

Tusc.Start(users, products);
File.WriteAllText(USERS_FILE, JsonConvert.SerializeObject(users, Formatting.Indented));
File.WriteAllText(PRODUCTS_FILE, JsonConvert.SerializeObject(products, Formatting.Indented));
}
}
}
26 changes: 26 additions & 0 deletions Refactoring/Refactoring.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<AssemblyName>Refactoring</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -31,6 +33,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand All @@ -45,11 +67,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Store.cs" />
<Compile Include="ConsoleUserInterface.cs" />
<Compile Include="LoginManager.cs" />
<Compile Include="Product.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tusc.cs" />
<Compile Include="User.cs" />
<Compile Include="UserInterface.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
20 changes: 20 additions & 0 deletions Refactoring/Store.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Refactoring
{
public class Store
{
public Store(List<Product> products, UserInterface ui)
{
if (products == null)
throw new ArgumentException();

if (ui == null)
throw new ArgumentException();
}
}
}
Loading