Skip to content

Commit

Permalink
Amend LegacyPipeParserBadInputTest based on these changes and convers…
Browse files Browse the repository at this point in the history
…ation with @JlKmn
  • Loading branch information
milkshakeuk committed Apr 14, 2021
1 parent 7fd168b commit 0a71e31
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 57 deletions.
4 changes: 2 additions & 2 deletions tests/NHapi.Base.NUnit/Model/AbstractGroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void AddNonstandardSegment_WithKnownType_AllowsReturnOfSegment()
var result = message.GetStructure(segmentToTest, 1);

// Assert
Assert.AreEqual(expectedSegmentType.Name, result.GetType().Name);
Assert.AreEqual(expectedSegmentType, result.GetType());
}

[Test]
Expand All @@ -40,7 +40,7 @@ public void AddNonstandardSegment_WithUnknownType_AllowsReturnOfSegment()
var result = message.GetStructure(segmentToTest);

// Assert
Assert.AreEqual(expectedSegmentType.Name, result.GetType().Name);
Assert.AreEqual(expectedSegmentType, result.GetType());
}

[Test]
Expand Down
6 changes: 3 additions & 3 deletions tests/NHapi.Base.NUnit/Model/AbstractSegmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public void TestEnsureEnoughFields()
msh.GetField(n + 3, 0);

// Assert
Assert.AreEqual(nameof(Varies), msh.GetField(n + 1, 0).GetType().Name);
Assert.AreEqual(nameof(Varies), msh.GetField(n + 2, 0).GetType().Name);
Assert.AreEqual(nameof(Varies), msh.GetField(n + 3, 0).GetType().Name);
Assert.AreEqual(typeof(Varies), msh.GetField(n + 1, 0).GetType());
Assert.AreEqual(typeof(Varies), msh.GetField(n + 2, 0).GetType());
Assert.AreEqual(typeof(Varies), msh.GetField(n + 3, 0).GetType());
}

[Test]
Expand Down
15 changes: 7 additions & 8 deletions tests/NHapi.NUnit/Parser/LegacyPipeParserBadInputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ public class LegacyPipeParserBadInputTests
private const string SO = "TestData/BadInputs/stackoverflow1";
private const string SO2 = "TestData/BadInputs/stackoverflow2";

[TestCase(AOOR1)]
[TestCase(SYS1)]
[TestCase(NULLREF1)]
[TestCase(IOOR1)]
[TestCase(SYS2)]
public void TestBadInputsThrowHL7Exception(string path)
[TestCase(AOOR1, typeof(EncodingNotSupportedException))]
[TestCase(NULLREF1, typeof(EncodingNotSupportedException))]
[TestCase(IOOR1, typeof(HL7Exception))]
public void TestBadInputsThrowException(string path, Type expectedExceptionType)
{
// Arrange
var parser = new LegacyPipeParser();
var text = File.ReadAllText(path);

// Act / Assert
var exception = Assert.Throws<HL7Exception>(
() => parser.Parse(text));
var exception = Assert.Throws(expectedExceptionType, () => parser.Parse(text));

// Write exception details to console
Console.WriteLine(exception);
Expand All @@ -45,6 +42,8 @@ public void TestBadInputsThrowHL7Exception(string path)
[TestCase(HANG1)]
[TestCase(SO)]
[TestCase(SO2)]
[TestCase(SYS1)]
[TestCase(SYS2)]
public void TestBadInputsAreHandledGracefully(string path)
{
// Arrange
Expand Down
96 changes: 52 additions & 44 deletions tests/NHapi.NUnit/Parser/PipeParserUnexpectedSegmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ public class PipeParserUnexpectedSegmentTests
[Test]
public void Parse_V23_ORM_O01()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.3
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.3\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -30,12 +31,13 @@ public void Parse_V23_ORM_O01()
[Test]
public void Parse_V23_ORM_O01_WithCustomEvnSegment()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.3
EVN||20180503
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.3\r"
+ "EVN||20180503\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -54,11 +56,12 @@ public void Parse_V23_ORM_O01_WithCustomEvnSegment()
[Test]
public void Parse_V24_ORM_O01()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.4
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.4\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -73,12 +76,13 @@ public void Parse_V24_ORM_O01()
[Test]
public void Parse_V24_ORM_O01_WithCustomEvnSegment()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.4
EVN||20180503
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.4\r"
+ "EVN||20180503\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -97,11 +101,12 @@ public void Parse_V24_ORM_O01_WithCustomEvnSegment()
[Test]
public void Parse_V25_ORM_O01()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -116,12 +121,13 @@ public void Parse_V25_ORM_O01()
[Test]
public void Parse_V25_ORM_O01_WithCustomEvnSegment()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5
EVN||20180503
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5\r"
+ "EVN||20180503\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -140,11 +146,12 @@ public void Parse_V25_ORM_O01_WithCustomEvnSegment()
[Test]
public void Parse_V251_ORM_O01()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5.1
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5.1\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand All @@ -159,12 +166,13 @@ public void Parse_V251_ORM_O01()
[Test]
public void Parse_V251_ORM_O01_WithCustomEvnSegment()
{
var message = @"MSH|^~\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5.1
EVN||20180503
PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F
PV1||I|3906||||||||||||||||100001
ORC|CA|1410|3121||CA
OBR|1|1410|3121|RX50^ADDOME SUPINO";
var message =
"MSH|^~\\&|sys1|sys1|sys2|sys2|20180503174921||ORM^O01|1234567890|P|2.5.1\r"
+ "EVN||20180503\r"
+ "PID|||1^^^XXX~2^^^YYY||LastName^FirstName||19660429|F\r"
+ "PV1||I|3906||||||||||||||||100001\r"
+ "ORC|CA|1410|3121||CA\r"
+ "OBR|1|1410|3121|RX50^ADDOME SUPINO";

var parser = new PipeParser();

Expand Down

0 comments on commit 0a71e31

Please sign in to comment.