Skip to content

Commit

Permalink
fix: new address can be null for rejected or retired address because …
Browse files Browse the repository at this point in the history
…of municipality merger
  • Loading branch information
jvandaal authored and ArneD committed Jul 30, 2024
1 parent 19f2136 commit 061a945
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 27 deletions.
20 changes: 10 additions & 10 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ nuget Be.Vlaanderen.Basisregisters.Projector 15.0.0

nuget Be.Vlaanderen.Basisregisters.Crab 4.0.0

nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Notifications 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.14.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Notifications 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.14.1

nuget Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple 5.0.1
nuget Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Simple 5.0.1
Expand Down
30 changes: 15 additions & 15 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ NUGET
Autofac.Extensions.DependencyInjection (>= 9.0)
Be.Vlaanderen.Basisregisters.EventHandling (5.0)
Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
NetTopologySuite (>= 2.5)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.14.1)
Be.Vlaanderen.Basisregisters.GrAr.Edit (21.14.1)
NetTopologySuite (>= 2.5)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.14.1)
Be.Vlaanderen.Basisregisters.Api (>= 21.0)
Be.Vlaanderen.Basisregisters.Shaperon (>= 10.0.2)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.14.1)
Autofac (>= 8.0)
Be.Vlaanderen.Basisregisters.AggregateSource.SqlStreamStore (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Expand All @@ -279,31 +279,31 @@ NUGET
Serilog (>= 3.1.1)
Serilog.Extensions.Logging (>= 8.0)
System.Threading.Tasks.Dataflow (>= 8.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.14.1)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Notifications (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Notifications (21.14.1)
AWSSDK.SimpleNotificationService (>= 3.7.301.3)
System.Text.Json (>= 8.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.14.1)
Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Formatters.Json (>= 5.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Http.Polly (>= 8.0.3)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.14.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (21.14.1)
Be.Vlaanderen.Basisregisters.Auth.AcmIdm (>= 2.0)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.14)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.14.1)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.14.1)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple (5.0.1)
AWSSDK.Core (>= 3.7.302.15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,19 @@ await DetachBecauseRejected(

foreach (var relation in relations)
{
if (!message.NewAddressPersistentLocalId.HasValue)
{
await DetachBecauseRejected(
commandHandler,
new AddressPersistentLocalId(message.AddressPersistentLocalId),
message.Provenance,
ct);
return;
}

var command = new ReplaceParcelAddressBecauseOfMunicipalityMerger(
new ParcelId(relation.ParcelId),
new AddressPersistentLocalId(message.NewAddressPersistentLocalId),
new AddressPersistentLocalId(message.NewAddressPersistentLocalId.Value),
new AddressPersistentLocalId(message.AddressPersistentLocalId),
FromProvenance(message.Provenance));

Expand Down Expand Up @@ -175,9 +185,19 @@ await DetachBecauseRetired(

foreach (var relation in relations)
{
if (!message.NewAddressPersistentLocalId.HasValue)
{
await DetachBecauseRetired(
commandHandler,
new AddressPersistentLocalId(message.AddressPersistentLocalId),
message.Provenance,
ct);
return;
}

var command = new ReplaceParcelAddressBecauseOfMunicipalityMerger(
new ParcelId(relation.ParcelId),
new AddressPersistentLocalId(message.NewAddressPersistentLocalId),
new AddressPersistentLocalId(message.NewAddressPersistentLocalId.Value),
new AddressPersistentLocalId(message.AddressPersistentLocalId),
FromProvenance(message.Provenance));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,41 @@ await Then(async _ =>
});
}

[Fact]
public async Task DetachParcelAddressBecauseOfMunicipalityMerger_AddressWasRejectedBecauseOfMunicipalityMerger()
{
var oldAddressPersistentLocalId = 1;

var @event = new AddressWasRejectedBecauseOfMunicipalityMerger(
Fixture.Create<int>(),
oldAddressPersistentLocalId,
null,
new Provenance(
Instant.FromDateTimeOffset(DateTimeOffset.Now).ToString(),
Application.ParcelRegistry.ToString(),
Modification.Update.ToString(),
Organisation.Aiv.ToString(),
"test"));

AddParcelAddressRelations(Fixture.Create<ParcelId>(), [oldAddressPersistentLocalId]);
AddParcelAddressRelations(Fixture.Create<ParcelId>(), [oldAddressPersistentLocalId]);

Given(@event);
await Then(async _ =>
{
_mockCommandHandler.Verify(x => x.Handle(
It.IsAny<DetachAddressBecauseAddressWasRejected>(), CancellationToken.None),
Times.Exactly(2));

var oldAddressRelations = _fakeBackOfficeContext.ParcelAddressRelations
.Where(x => x.AddressPersistentLocalId == oldAddressPersistentLocalId)
.ToList();

oldAddressRelations.Should().BeEmpty();
await Task.CompletedTask;
});
}

[Fact]
public async Task ReplaceParcelAddressBecauseOfMunicipalityMerger_AddressWasRetiredBecauseOfMunicipalityMerger()
{
Expand Down Expand Up @@ -664,6 +699,41 @@ await Then(async _ =>
});
}

[Fact]
public async Task DetachParcelAddressBecauseOfMunicipalityMerger_AddressWasRetiredBecauseOfMunicipalityMerger()
{
var oldAddressPersistentLocalId = 1;

var @event = new AddressWasRetiredBecauseOfMunicipalityMerger(
Fixture.Create<int>(),
oldAddressPersistentLocalId,
null,
new Provenance(
Instant.FromDateTimeOffset(DateTimeOffset.Now).ToString(),
Application.ParcelRegistry.ToString(),
Modification.Update.ToString(),
Organisation.Aiv.ToString(),
"test"));

AddParcelAddressRelations(Fixture.Create<ParcelId>(), [oldAddressPersistentLocalId]);
AddParcelAddressRelations(Fixture.Create<ParcelId>(), [oldAddressPersistentLocalId]);

Given(@event);
await Then(async _ =>
{
_mockCommandHandler.Verify(x => x.Handle(
It.IsAny<DetachAddressBecauseAddressWasRetired>(), CancellationToken.None),
Times.Exactly(2));

var oldAddressRelations = _fakeBackOfficeContext.ParcelAddressRelations
.Where(x => x.AddressPersistentLocalId == oldAddressPersistentLocalId)
.ToList();

oldAddressRelations.Should().BeEmpty();
await Task.CompletedTask;
});
}

private void AddParcelAddressRelations(ParcelId parcelId, int[] addressPersistentLocalIds)
{
foreach (var addressPersistentLocalId in addressPersistentLocalIds)
Expand Down

0 comments on commit 061a945

Please sign in to comment.