-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: or-2006 prevent regsitreer kbo from being instered twice
- Loading branch information
1 parent
c644cfc
commit cda36d1
Showing
23 changed files
with
567 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace AssociationRegistry.EventStore; | ||
|
||
using Locks; | ||
using Vereniging; | ||
|
||
public interface ILockStore | ||
{ | ||
Task<KboLockDocument?> GetKboNummerLock(KboNummer kboNummer); | ||
Task SetKboNummerLock(KboNummer kboNummer); | ||
Task DeleteKboNummerLock(KboNummer kboNummer); | ||
Task CleanKboNummerLocks(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace AssociationRegistry.EventStore; | ||
|
||
using Locks; | ||
using Marten; | ||
using Vereniging; | ||
|
||
public class LockStore : ILockStore | ||
{ | ||
private readonly IDocumentStore _documentStore; | ||
|
||
public LockStore(IDocumentStore documentStore) | ||
{ | ||
_documentStore = documentStore; | ||
} | ||
|
||
public async Task CleanKboNummerLocks() | ||
{ | ||
await using var session = _documentStore.LightweightSession(); | ||
session.DeleteWhere<KboLockDocument>(doc => doc.CreatedAt <= DateTimeOffset.UtcNow.AddMinutes(-1)); | ||
await session.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<KboLockDocument?> GetKboNummerLock(KboNummer kboNummer) | ||
{ | ||
try | ||
{ | ||
await using var session = _documentStore.QuerySession(); | ||
|
||
return await session.LoadAsync<KboLockDocument>(kboNummer); | ||
} | ||
catch | ||
{ | ||
return await Task.FromResult<KboLockDocument?>(null); | ||
} | ||
} | ||
|
||
public async Task SetKboNummerLock(KboNummer kboNummer) | ||
{ | ||
await using var session = _documentStore.LightweightSession(); | ||
|
||
session.Store(new KboLockDocument | ||
{ | ||
KboNummer = kboNummer, | ||
CreatedAt = DateTimeOffset.UtcNow, | ||
}); | ||
|
||
await session.SaveChangesAsync(); | ||
} | ||
|
||
public async Task DeleteKboNummerLock(KboNummer kboNummer) | ||
{ | ||
await using var session = _documentStore.LightweightSession(); | ||
|
||
session.Delete<KboLockDocument>(kboNummer); | ||
|
||
await session.SaveChangesAsync(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AssociationRegistry.EventStore.Locks; | ||
|
||
using Marten.Schema; | ||
|
||
public class KboLockDocument | ||
{ | ||
[Identity] | ||
public string KboNummer { get; set; } | ||
Check warning on line 8 in src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs GitHub Actions / analyze-code
Check warning on line 8 in src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs GitHub Actions / Run Tests (test/AssociationRegistry.Test)
Check warning on line 8 in src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs GitHub Actions / Run Tests (test/AssociationRegistry.Test.Public.Api)
Check warning on line 8 in src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs GitHub Actions / Run Tests (test/AssociationRegistry.Test.Acm.Api)
Check warning on line 8 in src/AssociationRegistry/EventStore/Locks/KboLockDocument.cs GitHub Actions / Run Tests (test/AssociationRegistry.Test.Admin.Api)
|
||
|
||
public DateTimeOffset CreatedAt { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
namespace AssociationRegistry.Vereniging; | ||
|
||
using EventStore; | ||
using EventStore.Locks; | ||
using Framework; | ||
|
||
public interface IVerenigingsRepository | ||
{ | ||
Task<StreamActionResult> Save(VerenigingsBase vereniging, CommandMetadata metadata, CancellationToken cancellationToken); | ||
Task<TVereniging> Load<TVereniging>(VCode vCode, long? expectedVersion) where TVereniging : IHydrate<VerenigingState>, new(); | ||
Task<VerenigingsRepository.VCodeAndNaam?> GetVCodeAndNaam(KboNummer kboNummer); | ||
Task<KboLockDocument?> GetKboNummerLock(KboNummer kboNummer); | ||
Task SetKboNummerLock(KboNummer kboNummer); | ||
Task DeleteKboNummerLock(KboNummer kboNummer); | ||
} |
24 changes: 20 additions & 4 deletions
24
...Registry.Test.Admin.Api/Fakes/MagdaGeefVerenigingNumberFoundMagdaGeefVerenigingService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
namespace AssociationRegistry.Test.Admin.Api.Fakes; | ||
|
||
using AssociationRegistry.Framework; | ||
using AutoFixture; | ||
using Framework; | ||
using Kbo; | ||
using ResultNet; | ||
using Vereniging; | ||
|
||
public class MagdaGeefVerenigingNumberFoundMagdaGeefVerenigingService : IMagdaGeefVerenigingService | ||
{ | ||
private readonly VerenigingVolgensKbo _verenigingVolgensKbo; | ||
private readonly VerenigingVolgensKbo? _verenigingVolgensKbo; | ||
|
||
public MagdaGeefVerenigingNumberFoundMagdaGeefVerenigingService(VerenigingVolgensKbo verenigingVolgensKbo) | ||
public MagdaGeefVerenigingNumberFoundMagdaGeefVerenigingService(VerenigingVolgensKbo? verenigingVolgensKbo = null) | ||
{ | ||
_verenigingVolgensKbo = verenigingVolgensKbo; | ||
} | ||
|
||
public Task<Result<VerenigingVolgensKbo>> GeefVereniging(KboNummer kboNummer, CommandMetadata metadata, CancellationToken cancellationToken) | ||
=> Task.FromResult(VerenigingVolgensKboResult.GeldigeVereniging(_verenigingVolgensKbo)); | ||
public Task<Result<VerenigingVolgensKbo>> GeefVereniging( | ||
KboNummer kboNummer, | ||
CommandMetadata metadata, | ||
CancellationToken cancellationToken) | ||
=> Task.FromResult(VerenigingVolgensKboResult.GeldigeVereniging(_verenigingVolgensKbo ?? VerenigingVolgensKbo(kboNummer))); | ||
|
||
private static VerenigingVolgensKbo VerenigingVolgensKbo(KboNummer kboNummer) | ||
{ | ||
var v = new Fixture().CustomizeAdminApi().Create<VerenigingVolgensKbo>() with | ||
{ | ||
KboNummer = kboNummer, | ||
Type = Verenigingstype.VZW, | ||
}; | ||
|
||
return v; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...kheid/CommandHandling/When_Duplicate_KboNummer/WithLock_And_LockNotRemovedWhileWaiting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace AssociationRegistry.Test.Admin.Api.VerenigingMetRechtspersoonlijkheid.When_RegistreerVerenigingMetRechtspersoonlijkheid. | ||
CommandHandling. | ||
When_Duplicate_KboNummer; | ||
|
||
using Acties.RegistreerVerenigingUitKbo; | ||
using AssociationRegistry.Framework; | ||
using AutoFixture; | ||
using EventStore; | ||
using Fakes; | ||
using FluentAssertions; | ||
using Framework; | ||
using Kbo; | ||
using Moq; | ||
using Test.Framework; | ||
using Xunit; | ||
using Xunit.Categories; | ||
|
||
[UnitTest] | ||
public class WithLock_And_LockNotRemovedWhileWaiting | ||
{ | ||
private readonly RegistreerVerenigingUitKboCommandHandler _commandHandler; | ||
private readonly CommandEnvelope<RegistreerVerenigingUitKboCommand> _envelope; | ||
|
||
public WithLock_And_LockNotRemovedWhileWaiting() | ||
{ | ||
var fixture = new Fixture().CustomizeAdminApi(); | ||
|
||
var moederVCodeAndNaam = fixture.Create<VerenigingsRepository.VCodeAndNaam>(); | ||
|
||
_envelope = new CommandEnvelope<RegistreerVerenigingUitKboCommand>(fixture.Create<RegistreerVerenigingUitKboCommand>(), | ||
fixture.Create<CommandMetadata>()); | ||
|
||
ILockStore lockStoreMock = new AlwaysLockStoreMock(); | ||
var repositoryMock = new VerenigingRepositoryMock(moederVCodeAndNaam: moederVCodeAndNaam, lockStore: lockStoreMock); | ||
|
||
_commandHandler = new RegistreerVerenigingUitKboCommandHandler( | ||
repositoryMock, | ||
new InMemorySequentialVCodeService(), | ||
Mock.Of<IMagdaGeefVerenigingService>()); | ||
} | ||
|
||
[Fact] | ||
public void Then_It_Throws_An_Exception() | ||
{ | ||
var handle = async () => await _commandHandler | ||
.Handle(_envelope, CancellationToken.None); | ||
|
||
handle.Should().ThrowAsync<ApplicationException>() | ||
.WithMessage($"Kan niet langer wachten op lock voor KBO nummer {_envelope.Command.KboNummer}"); | ||
} | ||
} |
Oops, something went wrong.