Skip to content

Commit

Permalink
Add tests for xtf log parser
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Mar 18, 2024
1 parent ee324de commit 1d69617
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/ILICheck.Web.Test/ILICheck.Web.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
<None Update="testdata\invalid.xtf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="testdata\xtflog\invalid.xtf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="testdata\xtflog\empty.xtf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="testdata\xtflog\valid.xtf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
62 changes: 62 additions & 0 deletions tests/ILICheck.Web.Test/XtfLogParserTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace ILICheck.Web.XtfLog
{
[TestClass]
public class XtfLogParserTest
{
[TestMethod]
[DeploymentItem(@"testdata/xtflog/valid.xtf", "xtflog")]
public void ParseValidXml()
{
using var reader = new StreamReader(File.OpenRead(Path.Combine("xtflog", "valid.xtf")));

var logEntries = XtfLogParser.Parse(reader);

Assert.AreEqual(2, logEntries.Count);

var first = logEntries[0];
Assert.AreEqual("1", first.Tid);
Assert.AreEqual("Error message 1", first.Message);
Assert.AreEqual("Error", first.Type);
Assert.AreEqual("Model.Topic.Class", first.ObjTag);
Assert.AreEqual("Data source 1", first.DataSource);
Assert.AreEqual(11, first.Line);
Assert.AreEqual("Technical details 1", first.TechDetails);
Assert.AreEqual(123.456m, first.Geometry.Coord.C1);
Assert.AreEqual(234.567m, first.Geometry.Coord.C2);

var second = logEntries[1];
Assert.AreEqual("2", second.Tid);
Assert.AreEqual("Info message 2", second.Message);
Assert.AreEqual("Info", second.Type);
Assert.IsNull(second.ObjTag);
Assert.IsNull(second.DataSource);
Assert.IsNull(second.Line);
Assert.IsNull(second.TechDetails);
Assert.IsNull(second.Geometry);
}

[TestMethod]
[DeploymentItem(@"testdata/xtflog/invalid.xtf", "xtflog")]
public void ParseInvalidXml()
{
using var reader = new StreamReader(File.OpenRead(Path.Combine("xtflog", "invalid.xtf")));

Assert.ThrowsException<InvalidOperationException>(() => XtfLogParser.Parse(reader));
}

[TestMethod]
[DeploymentItem(@"testdata/xtflog/empty.xtf", "xtflog")]
public void ParseEmptyXml()
{
using var reader = new StreamReader(File.OpenRead(Path.Combine("xtflog", "empty.xtf")));

var logEntries = XtfLogParser.Parse(reader);

Assert.AreEqual(0, logEntries.Count);
}
}
}
7 changes: 7 additions & 0 deletions tests/ILICheck.Web.Test/testdata/xtflog/empty.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<DATASECTION>
<IliVErrors.ErrorLog BID="1">
</IliVErrors.ErrorLog>
</DATASECTION>
</TRANSFER>
24 changes: 24 additions & 0 deletions tests/ILICheck.Web.Test/testdata/xtflog/invalid.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<DATASECTION>
<IliVErrors.ErrorLog BID="1">
<IliVErrors.ErrorLog.Error TID="1">
<Message>Error message 1</Message>
<Type>Error</Type>
<ObjTag>Model.Topic.Class</ObjTag>
<DataSource>Data source 1</DataSource>
<Line>11</Line>
<TechDetails>Technical details 1</TechDetails>
<Geometry>
<COORD>
<C1>123.456</C1>
<C2>234.567</C2>
</COORD>
</Geometry>
</IliVErrors.ErrorLog.Error>
<IliVErrors.ErrorLog.Error TID="2">
<Message>Info message 2</Message>
<Type>Info</Type>
</IliVErrors.ErrorLog.Error>
</DATASECTION>
</TRANSFER>
25 changes: 25 additions & 0 deletions tests/ILICheck.Web.Test/testdata/xtflog/valid.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3">
<DATASECTION>
<IliVErrors.ErrorLog BID="1">
<IliVErrors.ErrorLog.Error TID="1">
<Message>Error message 1</Message>
<Type>Error</Type>
<ObjTag>Model.Topic.Class</ObjTag>
<DataSource>Data source 1</DataSource>
<Line>11</Line>
<TechDetails>Technical details 1</TechDetails>
<Geometry>
<COORD>
<C1>123.456</C1>
<C2>234.567</C2>
</COORD>
</Geometry>
</IliVErrors.ErrorLog.Error>
<IliVErrors.ErrorLog.Error TID="2">
<Message>Info message 2</Message>
<Type>Info</Type>
</IliVErrors.ErrorLog.Error>
</IliVErrors.ErrorLog>
</DATASECTION>
</TRANSFER>

0 comments on commit 1d69617

Please sign in to comment.