zaaReloaded2/Tests/Controller/Elements/ItemsTest.cs

243 lines
9.4 KiB
C#
Raw Permalink Normal View History

2015-07-13 21:57:35 +00:00
/* ItemsTest.cs
* part of zaaReloaded2
*
2017-02-23 15:44:07 +00:00
* Copyright 2015-2017 Daniel Kraus
2015-07-13 21:57:35 +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 NUnit.Framework;
using Microsoft.Office.Interop.Word;
using zaaReloaded2.LabModel;
using zaaReloaded2.Formatter;
using zaa = zaaReloaded2.Controller.Elements;
2015-08-30 05:48:32 +00:00
using zaaReloaded2.Controller.Comments;
using System.Text.RegularExpressions;
2015-07-13 21:57:35 +00:00
namespace Tests.Controller.Elements
2015-07-13 21:57:35 +00:00
{
[TestFixture]
class ItemsTest
{
Document _document;
zaaReloaded2.Formatter.Formatter _formatter;
[SetUp]
public void SetUp()
{
_document = new Document();
_formatter = new zaaReloaded2.Formatter.Formatter(_document);
2015-07-19 06:28:40 +00:00
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
}
[TearDown]
public void TearDown()
{
((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges);
Bovender.ComHelpers.ReleaseComObject(_document);
}
2015-07-13 21:57:35 +00:00
[Test]
public void ItemsTestWithoutCaption()
{
Laboratory lab = new Laboratory();
2015-07-13 21:57:35 +00:00
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "133"));
tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output.
lab.AddTimePoint(tp);
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
_formatter.Run();
2015-08-09 17:54:48 +00:00
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
"Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r")
);
2015-08-09 17:54:48 +00:00
Assert.AreEqual(expected, _document.Range().Text);
2015-07-13 21:57:35 +00:00
}
[Test]
public void ItemsTestWithCaption()
{
Laboratory lab = new Laboratory();
2015-07-13 21:57:35 +00:00
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output.
lab.AddTimePoint(tp);
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
_formatter.Run();
2015-08-09 17:54:48 +00:00
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
"Klinische Chemie: Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r")
);
2015-08-09 17:54:48 +00:00
Assert.AreEqual(expected, _document.Range().Text);
2015-07-13 21:57:35 +00:00
}
[Test]
public void ItemsTestWithCaptionButNoItems()
{
Laboratory lab = new Laboratory();
2015-07-13 21:57:35 +00:00
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output.
lab.AddTimePoint(tp);
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
_formatter.Run();
Assert.AreEqual("\r", _document.Range().Text);
2015-07-13 21:57:35 +00:00
}
2015-07-19 06:28:40 +00:00
[Test]
public void GenericItemsWildcard()
{
Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("K", "6", ""));
tp.AddItem(new LabItem("Cl", "110", ""));
lab.AddTimePoint(tp);
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, *"));
_formatter.Run();
2015-08-09 17:54:48 +00:00
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
) +
2015-08-09 17:54:48 +00:00
"Klinische Chemie: Na 133, Cl 110, K 6\r\r").Replace(Environment.NewLine, "\r");
Assert.AreEqual(expected, _document.Range().Text);
2015-07-19 06:28:40 +00:00
}
[Test]
public void MaterialWildcard()
{
Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("U-Na", "99", ""));
tp.AddItem(new LabItem("Cl", "110", ""));
tp.AddItem(new LabItem("SU-Protein", "2.8", ""));
lab.AddTimePoint(tp);
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*"));
_formatter.Run();
2015-08-09 17:54:48 +00:00
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
)+
"Klinische Chemie: Na 133, SU-Protein 3\r\r").Replace(Environment.NewLine, "\r");
2015-08-09 17:54:48 +00:00
Assert.AreEqual(expected, _document.Range().Text);
2015-07-19 06:28:40 +00:00
}
[Test]
public void MaterialAndGenericWildcard()
{
Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("U-Na", "99", ""));
tp.AddItem(new LabItem("Cl", "110", ""));
tp.AddItem(new LabItem("SU-Protein", "2.8", ""));
lab.AddTimePoint(tp);
_formatter.Settings.ReferenceStyle = ReferenceStyle.Never;
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*, *"));
_formatter.Run();
2015-08-09 17:54:48 +00:00
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
) +
"Klinische Chemie: Na 133, SU-Protein 3, Cl 110, U-Na 99\r\r")
2015-08-09 17:54:48 +00:00
.Replace(Environment.NewLine, "\r");
Assert.AreEqual(expected, _document.Range().Text);
2015-07-19 06:28:40 +00:00
}
[Test]
public void ItemCommentWithoutHandler()
{
CommentPool.Default.Reset();
Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "133"));
tp.AddItem(new LabItem("K", "6", "5"));
lab.AddTimePoint(tp);
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(
new zaa.Items("Na \"(Zielbereich: <> mmol/l)\""));
_formatter.Run();
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
"Na 133\r\r").Replace(Environment.NewLine, "\r")
);
Assert.AreEqual(expected, _document.Range().Text);
}
2015-08-30 05:48:32 +00:00
[Test]
public void ItemCommentWithHandler()
{
Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "133"));
tp.AddItem(new LabItem("K", "6", "5"));
lab.AddTimePoint(tp);
_formatter.Laboratory = lab;
_formatter.Settings.Elements.Add(
new zaa.Items("Na \"(Zielbereich: <default> µg/l)\""));
bool messageSent = false;
CommentPool.Default.FillInComment += (sender, args) =>
{
messageSent = true;
args.Comment.Value = "4-7";
};
_formatter.Run();
Assert.IsTrue(messageSent, "FillInComment message was not sent");
string expected = (
StripMarkup(
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
"Na 133 (Zielbereich: 4-7 µg/l)\r\r").Replace(Environment.NewLine, "\r")
);
Assert.AreEqual(expected, _document.Range().Text);
}
static string StripMarkup(string s)
{
return _markupStripper.Replace(s, string.Empty);
}
static readonly Regex _markupStripper = new Regex(@"<[^>]+>");
2015-07-13 21:57:35 +00:00
}
}