Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 1cdce77

Browse files
committed
Added tests for new class
1 parent db30db5 commit 1cdce77

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

Pass4Win/ConfigHandling.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Pass4Win
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.IO;
56
using Newtonsoft.Json;
@@ -70,7 +71,13 @@ private void Load()
7071
json = reader.ReadToEnd();
7172
}
7273
}
73-
this.values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
74+
try
75+
{
76+
this.values = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
77+
}
78+
catch (Exception)
79+
{
80+
}
7481
}
7582
}
7683
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
namespace Pass4WinTests
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using NUnit.Framework;
6+
using Pass4Win;
7+
8+
[TestFixture]
9+
public class ConfigHandlingTests
10+
{
11+
[SetUp]
12+
public void BeforeTest()
13+
{
14+
Setup.InitializeContainer();
15+
}
16+
17+
[Test]
18+
public void ValueTypes()
19+
{
20+
var standardConfig = new ConfigHandling();
21+
22+
int valueInteger = 5000;
23+
standardConfig["testInteger"] = valueInteger;
24+
25+
DateTime valueDate = DateTime.Now;
26+
standardConfig["testDate"] = valueDate;
27+
28+
char valueChar = 'x';
29+
standardConfig["testChar"] = valueChar;
30+
31+
Assert.AreEqual(valueDate, standardConfig["testDate"]);
32+
Assert.AreEqual(valueInteger, standardConfig["testInteger"]);
33+
Assert.AreEqual(valueChar, standardConfig["testChar"]);
34+
}
35+
36+
[Test]
37+
public void ReferenceTypes()
38+
{
39+
ConfigHandling standardConfig = new ConfigHandling();
40+
41+
string referenceString = "referenced string";
42+
string[] referenceArray = { "referenced", "string"};
43+
44+
standardConfig["testString"] = referenceString;
45+
standardConfig["testArray"] = referenceArray;
46+
47+
Assert.AreEqual(referenceString, standardConfig["testString"]);
48+
Assert.AreEqual(referenceArray, standardConfig["testArray"]);
49+
}
50+
51+
[Test]
52+
public void SavingLoading()
53+
{
54+
int value = 1024;
55+
{
56+
var standardConfig = new ConfigHandling();
57+
58+
standardConfig["test"] = value;
59+
60+
standardConfig.Save();
61+
}
62+
63+
{
64+
var standardConfig = new ConfigHandling();
65+
66+
Assert.AreEqual(value, standardConfig["test"]);
67+
}
68+
}
69+
70+
[Test]
71+
[ExpectedException(typeof(KeyNotFoundException))]
72+
public void Delete()
73+
{
74+
var standardConfig = new ConfigHandling();
75+
standardConfig["test"] = 1024;
76+
77+
78+
standardConfig.Delete("test");
79+
80+
if (standardConfig["test"] == 1024)
81+
{
82+
Assert.Fail("Deleted key still exists.");
83+
}
84+
85+
}
86+
}
87+
}

Pass4WinTests/Pass4WinTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
4242
<Private>True</Private>
4343
</Reference>
44+
<Reference Include="Microsoft.CSharp" />
4445
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
4546
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
4647
<Private>True</Private>
@@ -65,6 +66,7 @@
6566
<Otherwise />
6667
</Choose>
6768
<ItemGroup>
69+
<Compile Include="ConfigHandlingTests.cs" />
6870
<Compile Include="FileSystemInterfaceTests.cs" />
6971
<Compile Include="Properties\AssemblyInfo.cs" />
7072
<Compile Include="PwgenTests.cs" />

0 commit comments

Comments
 (0)