Implement DocumentWriter, control elements, and tests.
This commit is contained in:
@ -25,23 +25,95 @@ using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using System.IO;
|
||||
|
||||
namespace Tests.Formatter
|
||||
{
|
||||
[TestFixture]
|
||||
class FormatterTest
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormatLaboratory()
|
||||
{
|
||||
Document document = new Document();
|
||||
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
|
||||
f.Formatter formatter = new f.Formatter(document);
|
||||
formatter.Laboratory = importer.Laboratory;
|
||||
formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl"));
|
||||
formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 144 mM, K 4,3 mM\r", document.Range().Text);
|
||||
((_Document)document).Close(WdSaveOptions.wdDoNotSaveChanges);
|
||||
_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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user