Skip to content

Commit

Permalink
fix: use persistentlocalids for propose streetnames for municipality …
Browse files Browse the repository at this point in the history
…merger
  • Loading branch information
rikdepeuter authored and ArneD committed Sep 17, 2024
1 parent f25b54c commit 84040ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,19 @@ public async Task<IActionResult> ProposeForMunicipalityMerger(
recordNr++;

var oldNisCode = csv.GetField<string>("OUD NIS code");
var oldStreetNamePuri = csv.GetField<string>("OUD straatnaamid");
var oldStreetNamePersistentLocalIdAsString = csv.GetField<string>("OUD straatnaamid");
var newNisCode = csv.GetField<string>("NIEUW NIS code");
var streetName = csv.GetField<string>("NIEUW straatnaam");
var homonymAddition = csv.GetField<string>("NIEUW homoniemtoevoeging");

if (string.IsNullOrWhiteSpace(oldNisCode))
return BadRequest($"OldNisCode is required at record number {recordNr}");

if (string.IsNullOrWhiteSpace(oldStreetNamePuri))
return BadRequest($"OldStreetNamePuri is required at record number {recordNr}");

if (!OsloPuriValidator.TryParseIdentifier(oldStreetNamePuri, out var oldStreetNamePersistentLocalIdAsString)
|| !int.TryParse(oldStreetNamePersistentLocalIdAsString, out var oldStreetNamePersistentLocalId))
return BadRequest($"OldStreetNamePuri is NaN at record number {recordNr}");
if (string.IsNullOrWhiteSpace(oldStreetNamePersistentLocalIdAsString))
return BadRequest($"OldStreetNamePersistentLocalId is required at record number {recordNr}");

if (!int.TryParse(oldStreetNamePersistentLocalIdAsString, out var oldStreetNamePersistentLocalId))
return BadRequest($"OldStreetNamePersistentLocalId is NaN at record number {recordNr}");

if (string.IsNullOrWhiteSpace(newNisCode))
return BadRequest($"NisCode is required at record number {recordNr}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void WithNoNisCode_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11001;http://b/123;;Name;HO"),
"11001;123;;Name;HO"),
"bla",
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand All @@ -79,7 +79,7 @@ public void WithDifferentNisCodeThanRoute_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11000;http://b/123;11001;Name;HO"),
"11000;123;11001;Name;HO"),
nisCode,
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand All @@ -95,7 +95,7 @@ public void WithNoStreetName_ThenReturnsBadRequest()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString("OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
"11000;http://b/123;NisCode;;HO"),
"11000;123;NisCode;;HO"),
"NisCode",
Mock.Of<IPersistentLocalIdGenerator>(),
_municipalityConsumerContext,
Expand Down Expand Up @@ -128,7 +128,7 @@ public void WithValidCsv_ThenReturnsOk()
var result =
Controller.ProposeForMunicipalityMerger(
CsvHelpers.CreateFormFileFromString($"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n" +
$"{oldNisCode};http://a/123;11001;Street;HO\n{oldNisCode};http://a/456;11001;Name;NYM\n{oldNisCode};http://a/789;11001;Street;HO"),
$"{oldNisCode};123;11001;Street;HO\n{oldNisCode};456;11001;Name;NYM\n{oldNisCode};789;11001;Street;HO"),
"11001",
mockPersistentLocalIdGenerator.Object,
_municipalityConsumerContext,
Expand Down
2 changes: 1 addition & 1 deletion test/StreetNameRegistry.Tests/CsvHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public sealed class CsvHelpers
{
public const string OldNisCode = "11000";
public const string Example = $"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n{OldNisCode};http://v/a/123;11001;naam;BB";
public const string Example = $"OUD NIS code;OUD straatnaamid;NIEUW NIS code;NIEUW straatnaam;NIEUW homoniemtoevoeging\n{OldNisCode};123;11001;naam;BB";
//Convert the string to be able to passed as IFormFile

public static IFormFile CreateFormFileFromString(string content, string fileName = "file.csv")
Expand Down

0 comments on commit 84040ec

Please sign in to comment.