Skip to content

Commit

Permalink
feat: consume AddressRemovalWasCorrected
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal authored and ArneD committed May 28, 2024
1 parent 06a2dc9 commit f68cb5b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,109 +53,120 @@ await context
When<AddressWasApproved>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Current;
address!.Status = AddressStatus.Current;
});

When<AddressWasRejected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRejectedBecauseHouseNumberWasRejected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRejectedBecauseHouseNumberWasRetired>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRejectedBecauseStreetNameWasRejected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRejectedBecauseStreetNameWasRetired>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRetiredV2>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Retired;
address!.Status = AddressStatus.Retired;
});

When<AddressWasRetiredBecauseHouseNumberWasRetired>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Retired;
address!.Status = AddressStatus.Retired;
});

When<AddressWasRetiredBecauseStreetNameWasRejected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Retired;
address!.Status = AddressStatus.Retired;
});

When<AddressWasRetiredBecauseStreetNameWasRetired>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Retired;
address!.Status = AddressStatus.Retired;
});

When<AddressWasRemovedBecauseStreetNameWasRemoved>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.IsRemoved = true;
address!.IsRemoved = true;
});

When<AddressWasRemovedV2>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.IsRemoved = true;
address!.IsRemoved = true;
});

When<AddressRemovalWasCorrected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);

address!.Status = AddressStatus.Parse(message.Status);
address.GeometryMethod = message.GeometryMethod;
address.GeometrySpecification = message.GeometrySpecification;
address.Position = ParsePosition(message.ExtendedWkbGeometry);
address.IsRemoved = false;
});

When<AddressWasRemovedBecauseHouseNumberWasRemoved>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.IsRemoved = true;
address!.IsRemoved = true;
});

When<AddressWasDeregulated>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Current;
address!.Status = AddressStatus.Current;
});

When<AddressWasCorrectedFromApprovedToProposed>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Proposed;
address!.Status = AddressStatus.Proposed;
});

When<AddressWasCorrectedFromApprovedToProposedBecauseHouseNumberWasCorrected>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Proposed;
address!.Status = AddressStatus.Proposed;
});

When<AddressWasCorrectedFromRejectedToProposed>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Proposed;
address!.Status = AddressStatus.Proposed;
});

When<AddressWasCorrectedFromRetiredToCurrent>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Current;
address!.Status = AddressStatus.Current;
});

When<AddressHouseNumberWasReaddressed>(async (context, message, ct) =>
Expand Down Expand Up @@ -194,13 +205,13 @@ await context
When<AddressWasRejectedBecauseOfReaddress>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Rejected;
address!.Status = AddressStatus.Rejected;
});

When<AddressWasRetiredBecauseOfReaddress>(async (context, message, ct) =>
{
var address = await context.AddressConsumerItems.FindAsync(message.AddressPersistentLocalId, cancellationToken: ct);
address.Status = AddressStatus.Retired;
address!.Status = AddressStatus.Retired;
});

When<AddressPositionWasChanged>(async (context, message, ct) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ public ConsumerAddressKafkaProjectionTests(ITestOutputHelper outputHelper) : bas
[Fact]
public async Task AddressMigratedToStreetName_AddsAddress()
{
var addressStatus = Fixture
.Build<AddressStatus>()
.FromFactory(() =>
{
var statuses = new List<AddressStatus>
{
AddressStatus.Current, AddressStatus.Proposed, AddressStatus.Rejected, AddressStatus.Retired
};

return statuses[new Random(Fixture.Create<int>()).Next(0, statuses.Count - 1)];
})
.Create();
var addressStatus = GetRandomAddressStatus();

var addressWasMigratedToStreetName = Fixture
.Build<AddressWasMigratedToStreetName>()
Expand Down Expand Up @@ -728,6 +717,51 @@ await context.AddressConsumerItems.FindAsync(
});
}

[Fact]
public async Task AddressRemovalWasCorrected_UpdatesTheEntireAddress()
{
var addressWasProposedV2 = CreateAddressWasProposedV2();
var addressWasRemovedV2 = Fixture.Build<AddressWasRemovedV2>()
.FromFactory(() => new AddressWasRemovedV2(
addressWasProposedV2.StreetNamePersistentLocalId,
addressWasProposedV2.AddressPersistentLocalId,
Fixture.Create<Provenance>()))
.Create();
var addressRemovalWasCorrected = Fixture.Build<AddressRemovalWasCorrected>()
.FromFactory(() => new AddressRemovalWasCorrected(
addressWasProposedV2.StreetNamePersistentLocalId,
addressWasProposedV2.AddressPersistentLocalId,
GetRandomAddressStatus(),
Fixture.Create<string>(),
Fixture.Create<string>(),
Fixture.Create<string>(),
Fixture.Create<string>(),
Fixture.Create<ExtendedWkbGeometry>().ToString(),
Fixture.Create<bool>(),
Fixture.Create<string>(),
Fixture.Create<int?>(),
Fixture.Create<Provenance>()
))
.Create();

Given(addressWasProposedV2, addressWasRemovedV2, addressRemovalWasCorrected);

await Then(async context =>
{
var address =
await context.AddressConsumerItems.FindAsync(
addressWasProposedV2.AddressPersistentLocalId);

address.Should().NotBeNull();
address!.Status.Should().Be(AddressStatus.Parse(addressRemovalWasCorrected.Status));
address.GeometryMethod.Should().Be(addressRemovalWasCorrected.GeometryMethod);
address.GeometrySpecification.Should().Be(addressRemovalWasCorrected.GeometrySpecification);
address.Position.Should().Be(
(Point)_wkbReader.Read(addressRemovalWasCorrected.ExtendedWkbGeometry.ToByteArray()));
address.IsRemoved.Should().BeFalse();
});
}

[Fact]
public async Task AddressWasRemovedBecauseHouseNumberWasRemoved_UpdatesStatusAddress()
{
Expand Down Expand Up @@ -832,6 +866,23 @@ private AddressWasProposedV2 CreateAddressWasProposedV2()
.Create();
}

private AddressStatus GetRandomAddressStatus()
{
var addressStatus = Fixture
.Build<AddressStatus>()
.FromFactory(() =>
{
var statuses = new List<AddressStatus>
{
AddressStatus.Current, AddressStatus.Proposed, AddressStatus.Rejected, AddressStatus.Retired
};

return statuses[new Random(Fixture.Create<int>()).Next(0, statuses.Count - 1)];
})
.Create();
return addressStatus;
}

protected override ConsumerAddressContext CreateContext()
{
var options = new DbContextOptionsBuilder<ConsumerAddressContext>()
Expand Down

0 comments on commit f68cb5b

Please sign in to comment.