Skip to content

Commit

Permalink
fix: remove all duplicate address links when detaching (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikdepeuter authored May 29, 2024
1 parent 5a90221 commit 8bccf09
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/ParcelRegistry/Parcel/Parcel_State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,28 @@ private void When(ParcelAddressWasAttachedV2 @event)

private void When(ParcelAddressWasDetachedV2 @event)
{
_addressPersistentLocalIds.Remove(new AddressPersistentLocalId(@event.AddressPersistentLocalId));
_addressPersistentLocalIds.RemoveAll(x => x == new AddressPersistentLocalId(@event.AddressPersistentLocalId));

_lastEvent = @event;
}

private void When(ParcelAddressWasDetachedBecauseAddressWasRemoved @event)
{
_addressPersistentLocalIds.Remove(new AddressPersistentLocalId(@event.AddressPersistentLocalId));
_addressPersistentLocalIds.RemoveAll(x => x == new AddressPersistentLocalId(@event.AddressPersistentLocalId));

_lastEvent = @event;
}

private void When(ParcelAddressWasDetachedBecauseAddressWasRejected @event)
{
_addressPersistentLocalIds.Remove(new AddressPersistentLocalId(@event.AddressPersistentLocalId));
_addressPersistentLocalIds.RemoveAll(x => x == new AddressPersistentLocalId(@event.AddressPersistentLocalId));

_lastEvent = @event;
}

private void When(ParcelAddressWasDetachedBecauseAddressWasRetired @event)
{
_addressPersistentLocalIds.Remove(new AddressPersistentLocalId(@event.AddressPersistentLocalId));
_addressPersistentLocalIds.RemoveAll(x => x == new AddressPersistentLocalId(@event.AddressPersistentLocalId));

_lastEvent = @event;
}
Expand All @@ -151,7 +151,7 @@ private void When(ParcelAddressesWereReaddressed @event)
{
foreach (var addressPersistentLocalId in @event.DetachedAddressPersistentLocalIds)
{
_addressPersistentLocalIds.Remove(new AddressPersistentLocalId(addressPersistentLocalId));
_addressPersistentLocalIds.RemoveAll(x => x == new AddressPersistentLocalId(addressPersistentLocalId));
}

foreach (var addressPersistentLocalId in @event.AttachedAddressPersistentLocalIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenDetachingAddressBecauseAddressWasRejected
{
using System.Collections.Generic;
using System.Linq;
using Autofac;
using AutoFixture;
using BackOffice;
Expand Down Expand Up @@ -67,9 +68,12 @@ public void StateCheck()
var parcelWasMigrated = new ParcelWasMigratedBuilder(Fixture)
.WithStatus(ParcelStatus.Realized)
.WithAddress(addressPersistentLocalId)
.WithAddress(addressPersistentLocalId)
.WithAddress(456)
.Build();

parcelWasMigrated.AddressPersistentLocalIds.Count(x => x == addressPersistentLocalId).Should().Be(2);

var parcelAddressWasDetachedV2 = new ParcelAddressWasDetachedBecauseAddressWasRejectedBuilder(Fixture)
.WithAddress(addressPersistentLocalId)
.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenDetachingAddressBecauseAddressWasRemoved
{
using System.Collections.Generic;
using System.Linq;
using Autofac;
using AutoFixture;
using BackOffice;
Expand Down Expand Up @@ -66,9 +67,12 @@ public void StateCheck()
var parcelWasMigrated = new ParcelWasMigratedBuilder(Fixture)
.WithStatus(ParcelStatus.Realized)
.WithAddress(addressPersistentLocalId)
.WithAddress(addressPersistentLocalId)
.WithAddress(456)
.Build();

parcelWasMigrated.AddressPersistentLocalIds.Count(x => x == addressPersistentLocalId).Should().Be(2);

var parcelAddressWasDetachedV2 = new ParcelAddressWasDetachedBecauseAddressWasRemovedBuilder(Fixture)
.WithAddress(addressPersistentLocalId)
.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenDetachingAddressBecauseAddressWasRetired
{
using System.Collections.Generic;
using System.Linq;
using Autofac;
using AutoFixture;
using BackOffice;
Expand Down Expand Up @@ -66,9 +67,12 @@ public void StateCheck()
var parcelWasMigrated = new ParcelWasMigratedBuilder(Fixture)
.WithStatus(ParcelStatus.Realized)
.WithAddress(addressPersistentLocalId)
.WithAddress(addressPersistentLocalId)
.WithAddress(456)
.Build();

parcelWasMigrated.AddressPersistentLocalIds.Count(x => x == addressPersistentLocalId).Should().Be(2);

var parcelAddressWasDetachedV2 = new ParcelAddressWasDetachedBecauseAddressWasRetiredBuilder(Fixture)
.WithAddress(addressPersistentLocalId)
.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenDetachingParcelAddress
{
using System.Collections.Generic;
using System.Linq;
using Autofac;
using AutoFixture;
using BackOffice;
Expand Down Expand Up @@ -66,9 +67,12 @@ public void StateCheck()
var parcelWasMigrated = new ParcelWasMigratedBuilder(Fixture)
.WithStatus(ParcelStatus.Realized)
.WithAddress(addressPersistentLocalId)
.WithAddress(addressPersistentLocalId)
.WithAddress(456)
.Build();

parcelWasMigrated.AddressPersistentLocalIds.Count(x => x == addressPersistentLocalId).Should().Be(2);

var parcelAddressWasDetachedV2 = new ParcelAddressWasDetachedV2Builder(Fixture)
.WithAddress(addressPersistentLocalId)
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ public void StateCheck()
var parcelWasMigrated = new ParcelWasMigratedBuilder(Fixture)
.WithStatus(ParcelStatus.Realized)
.WithAddress(sourceAddressPersistentLocalId)
.WithAddress(sourceAddressPersistentLocalId)
.WithAddress(otherAddressPersistentLocalId)
.Build();

parcelWasMigrated.AddressPersistentLocalIds.Count(x => x == sourceAddressPersistentLocalId).Should().Be(2);

var @event = new ParcelAddressesWereReaddressed(
Fixture.Create<ParcelId>(),
Fixture.Create<VbrCaPaKey>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenRetiringParcel
namespace ParcelRegistry.Tests.AggregateTests.WhenRetiringParcel
{
using AutoFixture;
using Be.Vlaanderen.Basisregisters.AggregateSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
namespace ParcelRegistry.Tests.AggregateTests.WhenRetiringParcel
{
using System.Collections.Generic;
using Api.BackOffice.Abstractions.Extensions;
using AutoFixture;
using Be.Vlaanderen.Basisregisters.AggregateSource.Testing;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using Builders;
using Fixtures;
using Parcel;
using Parcel.Commands;
using Parcel.Events;
using Parcel.Exceptions;
using Xunit;
using Xunit.Abstractions;
using ParcelId = ParcelRegistry.Legacy.ParcelId;
using ParcelStatus = Parcel.ParcelStatus;

public class GivenParcelIsRemoved : ParcelRegistryTest
Expand Down

0 comments on commit 8bccf09

Please sign in to comment.