Skip to content

Commit

Permalink
Update test cases for geometry validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Sep 3, 2024
1 parent f11356e commit 51dbec9
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 37 deletions.
19 changes: 17 additions & 2 deletions Geodatenbezug.Test/Geodatenbezug.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,25 @@
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_donut.gpkg">
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_donut_valid_polygon.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg">
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_wo_donut.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_donut_invalid_polygon.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_w_donut.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_wo_donut.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_singlepart_donut.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_singlepart_donut.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_terrassenreben_v2_0_lv95_testdaten.gpkg">
Expand Down
141 changes: 141 additions & 0 deletions Geodatenbezug.Test/Processors/GeometryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using Geodatenbezug.Models;
using Microsoft.Extensions.Logging;
using Moq;
using OSGeo.OGR;

namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_donut_valid_polygon.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_wo_donut.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_donut_invalid_polygon.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_w_donut.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_wo_donut.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_singlepart_donut.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_singlepart_donut.gpkg", "testdata")]
public class GeometryTest
{
private readonly Topic topic = new()

Check failure on line 18 in Geodatenbezug.Test/Processors/GeometryTest.cs

View workflow job for this annotation

GitHub Actions / Code analysis and tests

Check failure on line 18 in Geodatenbezug.Test/Processors/GeometryTest.cs

View workflow job for this annotation

GitHub Actions / Code analysis and tests

{
TopicTitle = BaseTopic.lwb_perimeter_ln_sf.GetDescription(),
Canton = Canton.NE,
BaseTopic = BaseTopic.lwb_perimeter_ln_sf,
UpdatedAt = DateTime.Now,
};

private Mock<ILogger<Processor>> loggerMock;
private Mock<IGeodiensteApi> geodiensteApiMock;
private Mock<IAzureStorage> azureStorageMock;
private PerimeterLnSfProcessor processor;

[TestInitialize]
public void Initialize()
{
loggerMock = new Mock<ILogger<Processor>>(MockBehavior.Strict);
geodiensteApiMock = new Mock<IGeodiensteApi>(MockBehavior.Strict);
azureStorageMock = new Mock<IAzureStorage>(MockBehavior.Strict);
processor = new PerimeterLnSfProcessor(geodiensteApiMock.Object, azureStorageMock.Object, loggerMock.Object, topic);
}

[TestCleanup]
public void Cleanup()
{
loggerMock.VerifyAll();
}

[TestMethod]
public async Task RunGdalProcessingAsyncValidMultiPartWithoutDonut()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_wo_donut.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "perimeter_ln_sf";

var inputSource = Ogr.Open(processor.InputDataPath, 0);
var inputLayer = inputSource.GetLayerByName(layerName);

var resultSource = Ogr.Open(processor.InputDataPath.Replace(".gpkg", ".gdb", StringComparison.InvariantCulture), 0);
var resultLayer = resultSource.GetLayerByName(layerName);

Assert.AreEqual(1, inputLayer.GetFeatureCount(0));
Assert.AreEqual(2, resultLayer.GetFeatureCount(0));
}

[TestMethod]
public async Task RunGdalProcessingAsyncInvalidMultiPartWithoutDonut()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_wo_donut.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}

[TestMethod]
public async Task RunGdalProcessingAsyncValidMultiPartWithDonuts()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_w_donut.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "perimeter_ln_sf";

var inputSource = Ogr.Open(processor.InputDataPath, 0);
var inputLayer = inputSource.GetLayerByName(layerName);

var resultSource = Ogr.Open(processor.InputDataPath.Replace(".gpkg", ".gdb", StringComparison.InvariantCulture), 0);
var resultLayer = resultSource.GetLayerByName(layerName);

Assert.AreEqual(2, inputLayer.GetFeatureCount(0));
Assert.AreEqual(3, resultLayer.GetFeatureCount(0));
}

[TestMethod]
public async Task RunGdalProcessingAsyncValidSinglePartDonut()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_singlepart_donut.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "perimeter_ln_sf";

var inputSource = Ogr.Open(processor.InputDataPath, 0);
var inputLayer = inputSource.GetLayerByName(layerName);

var resultSource = Ogr.Open(processor.InputDataPath.Replace(".gpkg", ".gdb", StringComparison.InvariantCulture), 0);
var resultLayer = resultSource.GetLayerByName(layerName);

Assert.AreEqual(1, inputLayer.GetFeatureCount(0));
Assert.AreEqual(1, resultLayer.GetFeatureCount(0));
}

[TestMethod]
public async Task RunGdalProcessingAsyncInvalidSinglePartDonut()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_singlepart_donut.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}

[TestMethod]
public async Task RunGdalProcessingAsyncInvalidDonutValidPolygon()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_donut_valid_polygon.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}

[TestMethod]
public async Task RunGdalProcessingAsyncValidDonutInvalidPolygon()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_valid_donut_invalid_polygon.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}
}
35 changes: 0 additions & 35 deletions Geodatenbezug.Test/Processors/PerimeterLnSfProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_donut.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg", "testdata")]
public class PerimeterLnSfProcessorTest
{
private readonly Topic topic = new ()
Expand Down Expand Up @@ -84,37 +82,4 @@ public async Task RunGdalProcessingAsync()
Assert.AreEqual(firstInputFeature.GetFieldAsString("kanton"), firstResultFeature.GetFieldAsString("kanton"));
GdalAssert.AssertGeometry(firstInputFeature, firstResultFeature);
}

[TestMethod]
public async Task RunGdalProcessingAsyncValidDonutGeometry()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_donut.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "perimeter_ln_sf";

var inputSource = Ogr.Open(processor.InputDataPath, 0);
var inputLayer = inputSource.GetLayerByName(layerName);

var resultSource = Ogr.Open(processor.InputDataPath.Replace(".gpkg", ".gdb", StringComparison.InvariantCulture), 0);
var resultLayer = resultSource.GetLayerByName(layerName);

Assert.AreEqual(1, inputLayer.GetFeatureCount(0));
Assert.AreEqual(1, resultLayer.GetFeatureCount(0));

var firstInputFeature = inputLayer.GetNextFeature();
var firstResultFeature = resultLayer.GetNextFeature();
GdalAssert.AssertGeometry(firstInputFeature, firstResultFeature);
}

[TestMethod]
public async Task RunGdalProcessingAsyncInvalidGeometry()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 51dbec9

Please sign in to comment.