Implement DocumentWriter, control elements, and tests.
This commit is contained in:
@ -30,19 +30,21 @@ namespace Tests.Controller.Elements
|
||||
[TestFixture]
|
||||
class ItemsTest
|
||||
{
|
||||
Document _document;
|
||||
zaaReloaded2.Formatter.Formatter _formatter;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_formatter = new zaaReloaded2.Formatter.Formatter(new Document());
|
||||
_document = new Document();
|
||||
_formatter = new zaaReloaded2.Formatter.Formatter(_document);
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
((_Document)_formatter.Document).Close(WdSaveOptions.wdDoNotSaveChanges);
|
||||
((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -57,10 +59,9 @@ namespace Tests.Controller.Elements
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
|
||||
Assert.AreEqual("Na 133, K 6 (5)\r", _document.Range().Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -75,10 +76,9 @@ namespace Tests.Controller.Elements
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", _document.Range().Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -93,10 +93,9 @@ namespace Tests.Controller.Elements
|
||||
lab.AddTimePoint(tp);
|
||||
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("\r", _formatter.Document.Range().Text);
|
||||
Assert.AreEqual("\r", _document.Range().Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -112,11 +111,10 @@ namespace Tests.Controller.Elements
|
||||
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, *"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, Cl 110, K 6\r",
|
||||
_formatter.Document.Range().Text);
|
||||
_document.Range().Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -133,11 +131,10 @@ namespace Tests.Controller.Elements
|
||||
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, SU-Protein 2,8\r",
|
||||
_formatter.Document.Range().Text);
|
||||
_document.Range().Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -154,11 +151,10 @@ namespace Tests.Controller.Elements
|
||||
|
||||
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
|
||||
_formatter.Laboratory = lab;
|
||||
_formatter.SelectFirstDay();
|
||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*, *"));
|
||||
_formatter.Run();
|
||||
Assert.AreEqual("Klinische Chemie: Na 133, SU-Protein 2,8, Cl 110, U-Na 99\r",
|
||||
_formatter.Document.Range().Text);
|
||||
_document.Range().Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
/* SelectFirstDayTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* 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;
|
||||
using NUnit.Framework;
|
||||
using f = zaaReloaded2.Formatter;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace Tests.Controller.Elements
|
||||
{
|
||||
[TestFixture]
|
||||
class SelectFirstDayTest
|
||||
{
|
||||
[Test]
|
||||
public void SelectFirstDay()
|
||||
{
|
||||
SelectFirstDay element = new SelectFirstDay();
|
||||
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
|
||||
f.Formatter formatter = new f.Formatter();
|
||||
formatter.Laboratory = importer.Laboratory;
|
||||
element.Run(formatter);
|
||||
Assert.AreEqual(5, formatter.WorkingTimePoints.Count);
|
||||
DateTime firstDay = new DateTime(2015, 07, 04);
|
||||
Assert.AreEqual(firstDay.Date, formatter.WorkingTimePoints.First().Key.Date);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/* SelectFirstDayTest - Copy.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* 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;
|
||||
using NUnit.Framework;
|
||||
using f = zaaReloaded2.Formatter;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace Tests.Controller.Elements
|
||||
{
|
||||
[TestFixture]
|
||||
class SelectLastDayTest
|
||||
{
|
||||
[Test]
|
||||
public void SelectLastDay()
|
||||
{
|
||||
SelectLastDay element = new SelectLastDay();
|
||||
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
|
||||
f.Formatter formatter = new f.Formatter();
|
||||
formatter.Laboratory = importer.Laboratory;
|
||||
element.Run(formatter);
|
||||
// There are two time points of 6-July-2015 in the demo output file,
|
||||
// but since they have the exact same time stamps, they are merged
|
||||
// into one!
|
||||
Assert.AreEqual(1, formatter.WorkingTimePoints.Count);
|
||||
DateTime firstDay = new DateTime(2015, 07, 06);
|
||||
Assert.AreEqual(firstDay.Date, formatter.WorkingTimePoints.First().Key.Date);
|
||||
}
|
||||
}
|
||||
}
|
99
Tests/Formatter/DocumentWriterTest.cs
Executable file
99
Tests/Formatter/DocumentWriterTest.cs
Executable file
@ -0,0 +1,99 @@
|
||||
/* DocumentWriterClass.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* 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;
|
||||
using NUnit.Framework;
|
||||
using zaaReloaded2.Formatter;
|
||||
|
||||
namespace Tests.Formatter
|
||||
{
|
||||
[TestFixture]
|
||||
class DocumentWriterTest
|
||||
{
|
||||
DocumentWriter _docWriter;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_docWriter = new DocumentWriter();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddText()
|
||||
{
|
||||
string s = "hello world";
|
||||
_docWriter.Write(s);
|
||||
Assert.AreEqual(s, _docWriter.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddLine()
|
||||
{
|
||||
string s = "hello world";
|
||||
_docWriter.WriteLine(s);
|
||||
Assert.AreEqual(s + Environment.NewLine, _docWriter.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrependText()
|
||||
{
|
||||
string first = "first";
|
||||
string second = "second";
|
||||
_docWriter.Write(first);
|
||||
_docWriter.Prepend(second);
|
||||
Assert.AreEqual(second + first, _docWriter.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FlushingThrowsWithoutTarget()
|
||||
{
|
||||
_docWriter.Write("asdf");
|
||||
Assert.Throws<InvalidOperationException>(_docWriter.Flush);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FlushBuffer()
|
||||
{
|
||||
DocumentWriter parent = new DocumentWriter();
|
||||
_docWriter.Parent = parent;
|
||||
string s = "hello world";
|
||||
_docWriter.Write(s);
|
||||
_docWriter.Flush();
|
||||
Assert.AreEqual(s, parent.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BufferIsEmptyAfterFlush()
|
||||
{
|
||||
DocumentWriter parent = new DocumentWriter();
|
||||
_docWriter.Parent = parent;
|
||||
string s = "hello world";
|
||||
_docWriter.Write(s);
|
||||
_docWriter.Flush();
|
||||
Assert.IsFalse(_docWriter.HasBufferedText);
|
||||
Assert.AreEqual(String.Empty, _docWriter.ToString());
|
||||
}
|
||||
}
|
||||
}
|
7
Tests/Formatter/FormatterTest-all.txt
Executable file
7
Tests/Formatter/FormatterTest-all.txt
Executable file
@ -0,0 +1,7 @@
|
||||
|
||||
04.07.2015 12:31:00:
|
||||
Klinische Chemie: Na 144 mM, K 4,3 mM
|
||||
|
||||
06.07.2015 10:28:00:
|
||||
Klinische Chemie: Na 138 mM, K 4,6 mM
|
||||
|
7
Tests/Formatter/FormatterTest-eachday.txt
Executable file
7
Tests/Formatter/FormatterTest-eachday.txt
Executable file
@ -0,0 +1,7 @@
|
||||
|
||||
04.07.2015:
|
||||
Klinische Chemie: Na 144 mM, K 4,3 mM
|
||||
|
||||
06.07.2015:
|
||||
Klinische Chemie: Na 138 mM, K 4,6 mM
|
||||
|
4
Tests/Formatter/FormatterTest-firstday.txt
Executable file
4
Tests/Formatter/FormatterTest-firstday.txt
Executable file
@ -0,0 +1,4 @@
|
||||
|
||||
04.07.2015:
|
||||
Klinische Chemie: Na 144 mM, K 4,3 mM
|
||||
|
4
Tests/Formatter/FormatterTest-lastday.txt
Executable file
4
Tests/Formatter/FormatterTest-lastday.txt
Executable file
@ -0,0 +1,4 @@
|
||||
|
||||
06.07.2015:
|
||||
Klinische Chemie: Na 138 mM, K 4,6 mM
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,8 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controller\Elements\SelectLastDayTest.cs" />
|
||||
<Compile Include="Controller\Elements\SelectFirstDayTest.cs" />
|
||||
<Compile Include="Controller\SettingsRepositoryTest.cs" />
|
||||
<Compile Include="Formatter\DocumentWriterTest.cs" />
|
||||
<Compile Include="Thesaurus\ThesaurusTest.cs" />
|
||||
<Compile Include="Controller\Elements\ItemsTest.cs" />
|
||||
<Compile Include="Formatter\FormatterTest.cs" />
|
||||
@ -98,7 +97,18 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="demo-output.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Formatter\FormatterTest-eachday.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Formatter\FormatterTest-firstday.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Formatter\FormatterTest-lastday.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Formatter\FormatterTest-all.txt" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user