Make tests pass with refactored ZaaImporter.

This commit is contained in:
Daniel Kraus 2015-08-05 06:15:07 +02:00
parent 285c6a2555
commit 06a74992ef
4 changed files with 48 additions and 6 deletions

View File

@ -55,6 +55,7 @@ namespace Tests.Formatter
{ {
_formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl")); _formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl"));
_formatter.Run(); _formatter.Run();
Console.WriteLine(_document.Range().Text);
Assert.AreEqual( Assert.AreEqual(
GetResourceText("Tests.Formatter.FormatterTest-all.txt"), GetResourceText("Tests.Formatter.FormatterTest-all.txt"),
_document.Range().Text); _document.Range().Text);

View File

@ -135,10 +135,8 @@ namespace zaaReloaded2.Importer.ZaaImporter
IList<String> paragraphs, IList<String> paragraphs,
Parameters parameterDictionary, Parameters parameterDictionary,
Units unitDictionary) Units unitDictionary)
: this() : this(parameterDictionary, unitDictionary)
{ {
_parameterDictionary = parameterDictionary;
_unitDictionary = unitDictionary;
Paragraphs = paragraphs; Paragraphs = paragraphs;
} }
@ -147,6 +145,15 @@ namespace zaaReloaded2.Importer.ZaaImporter
{ {
} }
public LaurisTimePoint(
Parameters parameterDictionary,
Units unitDictionary)
: this()
{
_parameterDictionary = parameterDictionary;
_unitDictionary = unitDictionary;
}
#endregion #endregion
#region Public methods #region Public methods

View File

@ -78,8 +78,18 @@ namespace zaaReloaded2.Importer.ZaaImporter
// create a new time point. // create a new time point.
if (LaurisTimePoint.IsTimeStampLine(paragraph)) if (LaurisTimePoint.IsTimeStampLine(paragraph))
{ {
timePoint = new LaurisTimePoint(paragraph); timePoint = new LaurisTimePoint(paragraph, _parameters, _units);
Laboratory.AddTimePoint(timePoint); // Add the time point to the laboratory only if none
// with the same time stamp exists yet.
TimePoint existing = null;
if (Laboratory.TryGetTimePoint(timePoint.TimeStamp, ref existing))
{
timePoint = existing as LaurisTimePoint;
}
else
{
Laboratory.AddTimePoint(timePoint);
}
} }
// If the current paragraph looks like a paragraph with // If the current paragraph looks like a paragraph with
// laboratory items, add it to the current time point; // laboratory items, add it to the current time point;
@ -88,7 +98,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
{ {
if (timePoint == null) if (timePoint == null)
{ {
timePoint = new LaurisTimePoint(); timePoint = new LaurisTimePoint(_parameters, _units);
Laboratory.AddTimePoint(timePoint); Laboratory.AddTimePoint(timePoint);
} }
timePoint.AddParagraph(paragraph); timePoint.AddParagraph(paragraph);

View File

@ -66,6 +66,30 @@ namespace zaaReloaded2.LabModel
} }
} }
/// <summary>
/// Checks if the Laboratory contains a TimePoint with an identical
/// time stamp to the one being queried.
/// </summary>
/// <param name="timePoint">TimePoint whose time stamp to look for.</param>
/// <returns>True if a TimePoint with identical time stamp exists.</returns>
public bool HasTimePoint(TimePoint timePoint)
{
return TimePoints.ContainsKey(timePoint.TimeStamp);
}
/// <summary>
/// Looks for a TimePoint with a given timeStamp and returns
/// it as a reference parameter.
/// </summary>
/// <param name="timeStamp">Time stamp to look for.</param>
/// <param name="timePoint">Resulting TimePoint (if any).</param>
/// <returns>True if TimePoints contains a TimePoint with
/// the requested timeStamp.</returns>
public bool TryGetTimePoint(DateTime timeStamp, ref TimePoint timePoint)
{
return TimePoints.TryGetValue(timeStamp, out timePoint);
}
#endregion #endregion
} }
} }