Skip to content

Commit

Permalink
Merge pull request #4 from XanatosX/refactor/adding-unit-tests-and-re…
Browse files Browse the repository at this point in the history
…factoring

Refactor/adding unit tests and refactoring
  • Loading branch information
XanatosX authored Aug 31, 2018
2 parents 36a66ac + 33bf774 commit 2e9b4f5
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 69 deletions.
83 changes: 36 additions & 47 deletions ModularToolManger/JSONSettings/JSON/SettingsNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public class SettingsNode
readonly List<KeyValue> _settings;
public List<KeyValue> Settings => _settings;

public SettingsNode()
{
_settings = new List<KeyValue>();
}

public SettingsNode(string name)
{
_settings = new List<KeyValue>();
Expand All @@ -27,87 +22,81 @@ public SettingsNode(string name)

private void AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String)
{
if (KeyContained(key))
{
foreach (KeyValue pair in Settings)
{
if (pair.Key == key)
{
pair.Value = Value.ToString();
pair.ValueType = valueType;
}
}
}
else
KeyValue pair = GetKeyValue(key);
if (pair == null)
{
Settings.Add(new KeyValue
{
Key = key,
Value = Value.ToString(),
ValueType = valueType,
});
return;
}

pair.Value = Value.ToString();
pair.ValueType = valueType;
}

public bool AddOrChangeKeyValue(string key, object Value)
{
SettingsType type;
TypeCode code = Type.GetTypeCode(Value.GetType());
SettingsType type = GetValueType(Value);
if (type != SettingsType.Error)
{
AddKeyValue(key, Value, type);
return true;
}

return false;
}

private SettingsType GetValueType(object valueToCheck)
{
TypeCode code = Type.GetTypeCode(valueToCheck.GetType());
SettingsType returnType;
switch (code)
{
case TypeCode.Boolean:
type = SettingsType.Bool;
returnType = SettingsType.Bool;
break;
case TypeCode.Int32:
type = SettingsType.Int;
returnType = SettingsType.Int;
break;
case TypeCode.Single:
case TypeCode.Decimal:
type = SettingsType.Float;
returnType = SettingsType.Float;
break;
default:
type = SettingsType.String;
returnType = SettingsType.String;
break;
}
if (type != SettingsType.Error)
{
AddKeyValue(key, Value, type);
return true;
}

return false;

return returnType;
}

public string GetKeyValue(string key, out SettingsType type)
{
if (KeyContained(key))
type = SettingsType.Error;
KeyValue pair = GetKeyValue(key);

if (pair == null)
{
foreach (KeyValue pair in Settings)
{
if (pair.Key == key)
{
type = pair.ValueType;
return pair.Value;
}
}

return String.Empty;
}
type = SettingsType.Error;
return String.Empty;

type = pair.ValueType;
return pair.Value;
}

private bool KeyContained(string key)
private KeyValue GetKeyValue(string key)
{

foreach (KeyValue pair in Settings)
{
if (pair.Key == key)
{
return true;
return pair;
}
}
return false;
return null;
}
}
}
7 changes: 7 additions & 0 deletions ModularToolManger/JSONSettings/JSONSettings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ModularToolManger\DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Octokit, Version=0.19.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Octokit.0.19.0\lib\net45\Octokit.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<Compile Include="JSON\KeyValue.cs" />
Expand All @@ -51,5 +55,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="JSON\SettingsNode.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
4 changes: 1 addition & 3 deletions ModularToolManger/JSONSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void AddOrChangeKeyValue(string Key, object Value)

public bool GetBoolValue(string Name, string key)
{
bool returnBool = false; ;
bool returnBool = false;
string value = _settings.GetValue(Name, key, out SettingsType type);
if (type == SettingsType.Bool)
{
Expand Down Expand Up @@ -189,8 +189,6 @@ public void Cleanup()
Load();
}



public void ForceLoad()
{
Load();
Expand Down
4 changes: 4 additions & 0 deletions ModularToolManger/JSONSettings/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Octokit" version="0.19.0" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F3CC052B-A820-4DE9-8131-8D86C04A2F37}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModularToolManagerTest</RootNamespace>
<AssemblyName>ModularToolManagerTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Settings\SettingsTests.cs" />
<Compile Include="Settings\SettingsNodeTest.cs" />
<Compile Include="ToolManager\PasswordCryptTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ToolManager\PasswordHasherTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JSONSettings\JSONSettings.csproj">
<Project>{b33b0063-b387-40b0-b9fb-be918abcb0b4}</Project>
<Name>JSONSettings</Name>
</ProjectReference>
<ProjectReference Include="..\ModularToolManger\ModularToolManager.csproj">
<Project>{42e97a0e-bb73-47a3-8831-80cfe591ff78}</Project>
<Name>ModularToolManager</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.2.1\build\net45\MSTest.TestAdapter.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("ModularToolManagerTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModularToolManagerTest")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("f3cc052b-a820-4de9-8131-8d86c04a2f37")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 2e9b4f5

Please sign in to comment.