zaaReloaded2/Tests/Formatter/FormatterTest.cs

156 lines
5.2 KiB
C#
Raw Normal View History

2015-07-13 21:57:35 +00:00
/* FormatterTest.cs
2015-07-04 10:09:39 +00:00
* part of zaaReloaded2
*
2017-02-23 15:44:07 +00:00
* Copyright 2015-2017 Daniel Kraus
2015-07-04 10:09:39 +00:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2015-07-13 21:57:35 +00:00
using NUnit.Framework;
using f = zaaReloaded2.Formatter;
2015-07-06 13:48:43 +00:00
using zaaReloaded2.LabModel;
2015-07-13 21:57:35 +00:00
using zaaReloaded2.Importer.ZaaImporter;
using zaaReloaded2.Controller.Elements;
2015-07-13 21:57:35 +00:00
using Microsoft.Office.Interop.Word;
using System.IO;
2015-07-04 10:09:39 +00:00
2015-07-13 21:57:35 +00:00
namespace Tests.Formatter
2015-07-04 10:09:39 +00:00
{
2015-07-13 21:57:35 +00:00
[TestFixture]
class FormatterTest
2015-07-04 10:09:39 +00:00
{
Document _document;
f.Formatter _formatter;
[SetUp]
public void SetUp()
{
_document = new Document();
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
_formatter = new f.Formatter(_document);
_formatter.Laboratory = importer.Laboratory;
}
[TearDown]
public void TearDown()
{
((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges);
}
2015-07-13 21:57:35 +00:00
[Test]
public void FormatLaboratory()
2015-07-04 10:09:39 +00:00
{
_formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl"));
_formatter.Run();
Assert.AreEqual(
GetResourceText("Tests.Formatter.FormatterTest-all.txt"),
_document.Range().Text);
}
[Test]
public void SelectEachDay()
{
_formatter.Settings.Elements.Add(
new SelectEachDay(
new Items("Klinische Chemie: Na, K, Cl"))
);
_formatter.Run();
Assert.AreEqual(
GetResourceText("Tests.Formatter.FormatterTest-eachday.txt"),
_document.Range().Text);
}
[Test]
public void SelectFirstDay()
{
_formatter.Settings.Elements.Add(
new SelectFirstDay(
new Items("Klinische Chemie: Na, K, Cl"))
);
_formatter.Run();
Assert.AreEqual(
GetResourceText("Tests.Formatter.FormatterTest-firstday.txt"),
_document.Range().Text);
}
[Test]
public void SelectLastDay()
{
_formatter.Settings.Elements.Add(
new SelectLastDay(
new Items("Klinische Chemie: Na, K, Cl"))
);
_formatter.Run();
Assert.AreEqual(
GetResourceText("Tests.Formatter.FormatterTest-lastday.txt"),
_document.Range().Text);
}
[Test]
public void FormatSpecialItems()
{
ZaaImporter importer = new ZaaImporter();
importer.Import(
"Klinische Chemie: glomerul. Filtrationsr. CKD-EP: 36 ml/min /1,73qm; " +
"Sammelmenge (U): 12300 ml; "
);
Document document = new Document();
f.Formatter formatter = new f.Formatter(document);
formatter.Laboratory = importer.Laboratory;
formatter.Settings = new zaaReloaded2.Controller.Settings(
new List<ElementBase>() { new Items("*") } );
formatter.Run();
Assert.AreEqual(
"eGFR (CKD-EPI) 36 ml/min/1,73 m², SU-Volumen 12300 ml\r\r",
document.Range().Text);
}
[Test]
public void FormatCyclosporine()
{
ZaaImporter importer = new ZaaImporter();
importer.Import(
2017-02-23 15:44:07 +00:00
"(17.09.2015-201710:44:00) Cyclosporin-A vor Gabe: 130 µg/l; CK gesamt: 123 [<= 170] U/l; Cholesterin: 211");
Document document = new Document();
f.Formatter formatter = new f.Formatter(document);
formatter.Laboratory = importer.Laboratory;
formatter.Settings = new zaaReloaded2.Controller.Settings(
new List<ElementBase>() { new Items("CsA (C0) \"(Ziel-Talspiegel: <> µg/l)\"") });
formatter.Run();
Assert.AreEqual(
2017-02-23 15:44:07 +00:00
"Laborwerte vom 17.09.2015-201710:44:00:\rCsA (C0) 130 µg/l\r\r",
document.Range().Text);
}
string GetResourceText(string resource)
{
try
{
Stream s = this.GetType().Assembly
.GetManifestResourceStream(resource);
StreamReader sr = new StreamReader(s);
// Need to replace \r\n with \r because this is the newline character
// that Word uses.
return sr.ReadToEnd().Replace("\r\n", "\r");
}
catch (Exception e)
{
throw new IOException("Unable to read " + resource, e);
}
2015-07-04 10:09:39 +00:00
}
}
}