Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove all duplicate address links when detaching #785

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading