Refactor: Separate concerns.

This commit is contained in:
Daniel Kraus
2015-07-06 15:48:43 +02:00
parent 2bd9c0e696
commit 2cf31914dd
19 changed files with 492 additions and 259 deletions

View File

@ -1,4 +1,4 @@
/* LabItemTest.cs
/* LaurisItemTest.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
@ -20,12 +20,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using zaaReloaded2.Models;
using zaaReloaded2.LabModel;
using zaaReloaded2.Importer.ZaaImporter;
namespace Tests
namespace Tests.Importer.ZaaImporter
{
[TestFixture]
class LabItemTest
class LaurisItemTest
{
[Test]
[TestCase("Natrium: 139 [135 - 145] mmol/l", "Natrium", 139, "mmol/l", 135, 145, true)]
@ -34,7 +35,7 @@ namespace Tests
string laurisString, string name, double value,
string unit, double lowerLimit, double upperLimit, bool isNormal)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsTrue(i.IsNumerical, "IsNumerical");
@ -52,7 +53,7 @@ namespace Tests
string laurisString, string name, double value,
string unit, double lowerLimit, bool isNormal)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsTrue(i.IsNumerical, "IsNumerical");
@ -69,7 +70,7 @@ namespace Tests
string laurisString, string name, double value,
string unit, double upperLimit, bool isNormal)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsTrue(i.IsNumerical, "IsNumerical");
@ -87,7 +88,7 @@ namespace Tests
string laurisString, string name, double value,
string unit)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsTrue(i.IsNumerical, "IsNumerical");
@ -101,14 +102,14 @@ namespace Tests
public void ParseLaurisNonNumericNoNormal(
string laurisString, string name, string value)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(value, i.Value, "Value");
Assert.IsTrue(String.IsNullOrEmpty(i.Unit), "Unit should be a null string");
Assert.IsFalse(i.HasLimits, "HasLimits");
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
// TODO: Define the behavior of LabItem.IsNormal if no normal value known
// TODO: Define the behavior of LaurisItem.IsNormal if no normal value known
}
[TestCase("Erythrozyten (U): + [negativ]", "Erythrozyten (U)", "+", "negativ", false)]
@ -116,7 +117,7 @@ namespace Tests
public void ParseLaurisNonNumericWithNormal(
string laurisString, string name, string value, string normal, bool isNormal)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(value, i.Value, "Value");
Assert.AreEqual(normal, i.Normal, "Normal");
@ -124,7 +125,7 @@ namespace Tests
Assert.IsFalse(i.HasLimits, "HasLimits");
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
// TODO: Define the behavior of LabItem.IsNormal if no normal value known
// TODO: Define the behavior of LaurisItem.IsNormal if no normal value known
}
[TestCase("Albumin (SU)/die: 149.9 [<= 30] mg/d; ", Material.SU)]
@ -132,7 +133,7 @@ namespace Tests
[TestCase("Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; ", Material.B)]
public void ParseLaurisMaterial(string laurisString, Material expectedMaterial)
{
LabItem i = new LabItem(laurisString);
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(expectedMaterial, i.Material);
}
}

View File

@ -16,9 +16,10 @@
* limitations under the License.
*/
using NUnit.Framework;
using zaaReloaded2.Models;
using zaaReloaded2.LabModel;
using zaaReloaded2.Importer.ZaaImporter;
namespace Tests
namespace Tests.Importer.ZaaImporter
{
[TestFixture]
class LaurisParagraphTest

View File

@ -1,4 +1,4 @@
/* TimePointTest.cs
/* LaurisTimePointTest.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
@ -20,47 +20,48 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using zaaReloaded2.Models;
using zaaReloaded2.LabModel;
using zaaReloaded2.Importer.ZaaImporter;
namespace Tests
namespace Tests.Importer.ZaaImporter
{
[TestFixture]
class TimePointTest
class LaurisTimePointTest
{
[Test]
public void ParseValidTimePoint()
public void ParseValidLaurisTimePoint()
{
TimePoint tp = new TimePoint(
LaurisTimePoint tp = new LaurisTimePoint(
"[22.10.2013 12:30:00]" + Environment.NewLine +
"Klinische Chemie: Natrium: 139 [135 - 145] mmol/l;  Kalium: 5.2 [3.5 - 5] mmol/l;");
Assert.IsTrue(tp.IsValidTimePoint);
}
[Test]
public void ParseInvalidTimePoints()
public void ParseInvalidLaurisTimePoints()
{
TimePoint tp = new TimePoint("Aerobe Kultur: Enterokokken ;  Wachstum: 10 ;");
LaurisTimePoint tp = new LaurisTimePoint("Aerobe Kultur: Enterokokken ;  Wachstum: 10 ;");
Assert.IsFalse(tp.IsValidTimePoint,
"Bogus paragraph should be invalid TimePoint");
"Bogus paragraph should be invalid LaurisTimePoint");
tp.LaurisText = "[22.10.2013 12:30:00]";
Assert.IsFalse(tp.IsValidTimePoint,
"TimePoint should be invalid if it consists of time stamp only.");
"LaurisTimePoint should be invalid if it consists of time stamp only.");
}
[Test]
public void ParseTimePointWithDuplicateItems()
public void ParseLaurisTimePointWithDuplicateItems()
{
TimePoint tp = new TimePoint(
LaurisTimePoint tp = new LaurisTimePoint(
"[22.10.2013 12:30:00]" + Environment.NewLine +
"Klinische Chemie: Natrium: 139 [135 - 145] mmol/l;  Kalium: 5.2 [3.5 - 5] mmol/l;" + Environment.NewLine +
"Klinische Chemie: Natrium: 142 [135 - 145] mmol/l;  Kalium: 3.7 [3.5 - 5] mmol/l;"
);
Assert.IsTrue(tp.Items.ContainsKey("Kalium"),
"TimePoint should contain 'Kalium' item.");
"LaurisTimePoint should contain 'Kalium' item.");
Assert.AreEqual(3.7, tp.Items["Kalium"].NumericalValue,
"TimePoint does not use last occurrence of 'Kalium'.");
"LaurisTimePoint does not use last occurrence of 'Kalium'.");
}
}
}

View File

@ -34,6 +34,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>zaaReloaded2.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -58,16 +64,17 @@
</Choose>
<ItemGroup>
<Compile Include="Dictionaries\DictionaryTest.cs" />
<Compile Include="LabItemTest.cs" />
<Compile Include="LaurisParagraphTest.cs" />
<Compile Include="Importer\ZaaImporter\LaurisItemTest.cs" />
<Compile Include="Importer\ZaaImporter\LaurisParagraphTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LineParserTest.cs" />
<Compile Include="Dictionaries\TestDictionary.cs" />
<Compile Include="TimePointTest.cs" />
<Compile Include="Importer\ZaaImporter\TimePointTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Tests.licenseheader" />
<None Include="zaaReloaded2.pfx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\zaaReloaded2\zaaReloaded2.csproj">

BIN
Tests/zaaReloaded2.pfx Executable file

Binary file not shown.