-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from OpenBracketsCH/development
- Loading branch information
Showing
43 changed files
with
517 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const trimStringValues = (obj) => { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return obj; | ||
} | ||
|
||
const result = {}; | ||
Object.keys(obj).forEach((key) => { | ||
if (typeof obj[key] === 'string') { | ||
result[key] = obj[key].trim(); | ||
} else { | ||
result[key] = trimStringValues(obj[key]); | ||
} | ||
}); | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
backend/DefikarteBackend.Tests/DefikarteBackend.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Resources\swissboundaries3d_2024-01_4326.geojson" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resources\swissboundaries3d_2024-01_4326.geojson"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="Moq" Version="4.20.72" /> | ||
<PackageReference Include="NUnit" Version="4.2.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DefikarteBackend\DefikarteBackend.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
</Project> |
81 changes: 81 additions & 0 deletions
81
backend/DefikarteBackend.Tests/LocalisationServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using DefikarteBackend.Interfaces; | ||
using DefikarteBackend.Services; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using NetTopologySuite; | ||
using NetTopologySuite.Geometries; | ||
using NetTopologySuite.Geometries.Implementation; | ||
using System.Reflection; | ||
|
||
namespace DefikarteBackend.Tests | ||
{ | ||
[TestFixture] | ||
public class LocalisationServiceTests | ||
{ | ||
private Mock<IBlobStorageDataRepository> _blobRepositoryMock; | ||
private Mock<IServiceConfiguration> _configuratonMock; | ||
private Mock<ILogger> _loggerMock; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
NtsGeometryServices.Instance = new NtsGeometryServices( | ||
CoordinateArraySequenceFactory.Instance, | ||
new PrecisionModel(1000d), | ||
4326, | ||
GeometryOverlay.NG, | ||
new CoordinateEqualityComparer()); | ||
|
||
_blobRepositoryMock = new Mock<IBlobStorageDataRepository>(); | ||
var geoJson = GetFileContents("swissboundaries3d_2024-01_4326.geojson"); | ||
_blobRepositoryMock.Setup(x => x.ReadAsync(It.IsAny<string>())).ReturnsAsync(geoJson); | ||
|
||
_configuratonMock = new Mock<IServiceConfiguration>(); | ||
_configuratonMock.Setup(Setup => Setup.BlobStorageSwissBoundariesName).Returns("swissboundaries3d_2024-01_4326.geojson"); | ||
|
||
_loggerMock = new Mock<ILogger>(); | ||
} | ||
|
||
[Test] | ||
public async Task IsSwitzerlandAsync_GivenCooridnatesInSwitzerland_ShouldReturnTrueAsync() | ||
{ | ||
// Arrange | ||
var localisationService = new LocalisationService(NtsGeometryServices.Instance, _blobRepositoryMock.Object, _configuratonMock.Object, _loggerMock.Object); | ||
|
||
// Act | ||
var result = await localisationService.IsSwitzerlandAsync(47.0, 7.0).ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.That(result, Is.True); | ||
} | ||
|
||
[Test] | ||
public async Task IsSwitzerlandAsync_GivenCooridnatesOutsideSwitzerland_ShouldReturnFalseAsync() | ||
{ | ||
// Arrange | ||
var localisationService = new LocalisationService(NtsGeometryServices.Instance, _blobRepositoryMock.Object, _configuratonMock.Object, _loggerMock.Object); | ||
|
||
// Act | ||
var result = await localisationService.IsSwitzerlandAsync(47.73921, 8.04199).ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.That(result, Is.False); | ||
} | ||
|
||
private string GetFileContents(string resourceFile) | ||
{ | ||
var asm = Assembly.GetExecutingAssembly(); | ||
var resource = string.Format("DefikarteBackend.Tests.Resources.{0}", resourceFile); | ||
using (var stream = asm.GetManifestResourceStream(resource)) | ||
{ | ||
if (stream != null) | ||
{ | ||
var reader = new StreamReader(stream); | ||
return reader.ReadToEnd(); | ||
} | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/DefikarteBackend.Tests/Resources/swissboundaries3d_2024-01_4326.geojson
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 5 additions & 17 deletions
22
backend/Cache/BlobStorageCacheRepository.cs → ...ckend/Cache/BlobStorageCacheRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.