2015-07-13 21:57:35 +00:00
|
|
|
|
/* ItemsTest.cs
|
|
|
|
|
* part of zaaReloaded2
|
|
|
|
|
*
|
2018-02-13 08:28:44 +00:00
|
|
|
|
* Copyright 2015-2018 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;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
using zaa = zaaReloaded2.Controller.Elements;
|
2015-08-30 05:48:32 +00:00
|
|
|
|
using zaaReloaded2.Controller.Comments;
|
2015-08-14 09:22:11 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2015-07-13 21:57:35 +00:00
|
|
|
|
|
2015-07-16 22:23:06 +00:00
|
|
|
|
namespace Tests.Controller.Elements
|
2015-07-13 21:57:35 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
class ItemsTest
|
|
|
|
|
{
|
2015-07-25 12:33:48 +00:00
|
|
|
|
Document _document;
|
2015-07-14 21:19:41 +00:00
|
|
|
|
zaaReloaded2.Formatter.Formatter _formatter;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
2015-07-25 12:33:48 +00:00
|
|
|
|
_document = new Document();
|
|
|
|
|
_formatter = new zaaReloaded2.Formatter.Formatter(_document);
|
2015-07-19 06:28:40 +00:00
|
|
|
|
_formatter.Settings.ReferenceStyle = ReferenceStyle.IfAbnormal;
|
2015-07-14 21:19:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
2015-07-25 12:33:48 +00:00
|
|
|
|
((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges);
|
2016-09-03 21:18:43 +00:00
|
|
|
|
Bovender.ComHelpers.ReleaseComObject(_document);
|
2015-07-14 21:19:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 21:57:35 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ItemsTestWithoutCaption()
|
|
|
|
|
{
|
2015-07-14 21:19:41 +00:00
|
|
|
|
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.
|
2015-07-14 21:19:41 +00:00
|
|
|
|
lab.AddTimePoint(tp);
|
|
|
|
|
|
|
|
|
|
_formatter.Laboratory = lab;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
|
2015-07-14 21:19:41 +00:00
|
|
|
|
_formatter.Run();
|
2015-08-09 17:54:48 +00:00
|
|
|
|
string expected = (
|
2015-08-14 09:22:11 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2015-07-14 21:19:41 +00:00
|
|
|
|
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.
|
2015-07-14 21:19:41 +00:00
|
|
|
|
lab.AddTimePoint(tp);
|
|
|
|
|
|
|
|
|
|
_formatter.Laboratory = lab;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
2015-07-14 21:19:41 +00:00
|
|
|
|
_formatter.Run();
|
2015-08-09 17:54:48 +00:00
|
|
|
|
string expected = (
|
2015-08-14 09:22:11 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2015-07-14 21:19:41 +00:00
|
|
|
|
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.
|
2015-07-14 21:19:41 +00:00
|
|
|
|
lab.AddTimePoint(tp);
|
|
|
|
|
|
|
|
|
|
_formatter.Laboratory = lab;
|
2015-07-15 23:49:17 +00:00
|
|
|
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
|
2015-07-14 21:19:41 +00:00
|
|
|
|
_formatter.Run();
|
2015-07-25 12:33:48 +00:00
|
|
|
|
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 = (
|
2015-08-14 09:22:11 +00:00
|
|
|
|
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 = (
|
2015-08-14 09:22:11 +00:00
|
|
|
|
StripMarkup(
|
|
|
|
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
|
|
|
|
|
)+
|
2015-08-29 00:06:10 +00: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 = (
|
2015-08-14 09:22:11 +00:00
|
|
|
|
StripMarkup(
|
|
|
|
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
|
|
|
|
|
) +
|
2015-08-29 00:06:10 +00: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
|
|
|
|
}
|
2015-08-14 09:22:11 +00:00
|
|
|
|
|
2015-08-29 01:16:44 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void ItemCommentWithoutHandler()
|
|
|
|
|
{
|
2015-09-04 15:59:04 +00:00
|
|
|
|
CommentPool.Default.Reset();
|
2015-08-29 01:16:44 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-14 09:22:11 +00:00
|
|
|
|
static string StripMarkup(string s)
|
|
|
|
|
{
|
|
|
|
|
return _markupStripper.Replace(s, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 18:14:24 +00:00
|
|
|
|
static readonly Regex _markupStripper = new Regex(@"<[^>]+>");
|
2015-07-13 21:57:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|