public void WithDifferentHouseNumberId() { var oldHouseNumberId = new CrabHouseNumberId(-1); var oldCommand = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(oldHouseNumberId); var command = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Correction) .WithTerrainObjectHouseNumberId(oldCommand.TerrainObjectHouseNumberId); Assert(new Scenario() .Given(_parcelId, _fixture.Create <ParcelWasRegistered>(), _fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(oldHouseNumberId)), oldCommand.ToLegacyEvent()) .When(command) .Then(_parcelId, new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(oldHouseNumberId)), new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId)), command.ToLegacyEvent())); }
public void WhenDeleteAndInfiniteLifetimeWithAddress() { var command = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(_fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Insert); var deleteCommand = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(_fixture.Create <LocalDateTime>(), null)) .WithTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId) .WithHouseNumberId(command.HouseNumberId) .WithModification(CrabModification.Delete); var addressId = AddressId.CreateFor(command.HouseNumberId); Assert(new Scenario() .Given(_parcelId, _fixture.Create <ParcelWasRegistered>(), _fixture.Create <ParcelAddressWasAttached>() .WithAddressId(addressId), command.ToLegacyEvent()) .When(deleteCommand) .Then(_parcelId, new ParcelAddressWasDetached(_parcelId, addressId), deleteCommand.ToLegacyEvent())); }
public void WhenDeleteAndInfiniteLifetimeWithAddress_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Insert); var deleteCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId) .WithHouseNumberId(command.HouseNumberId) .WithModification(CrabModification.Delete); var addressId = AddressId.CreateFor(command.HouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(addressId), command.ToLegacyEvent()) .When(deleteCommand) .Then(new[] { new Fact(_parcelId, new ParcelAddressWasDetached(_parcelId, addressId)), new Fact(_parcelId, deleteCommand.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithLastModificationBasedOnCrab(Modification.Update) .Build(4, EventSerializerSettings)) })); }
public async Task RequestPersistentLocalIdForCrabSubaddressId(Func <IAddresses> getAddresses, CommandMessage <RequestPersistentLocalIdForCrabSubaddressId> message, CancellationToken ct) { var addressId = AddressId.CreateFor(message.Command.SubaddressId); var address = await getAddresses().GetAsync(addressId, ct); address.RequestPersistentLocalId(_persistentLocalIdGenerator); }
public void Customize(IFixture fixture) { var houseNumberId = fixture.Create <int>(); fixture.Customize <CrabHouseNumberId>(c => c.FromFactory(() => new CrabHouseNumberId(houseNumberId))); fixture.Customize <AddressId>(c => c.FromFactory(() => AddressId.CreateFor(fixture.Create <CrabHouseNumberId>()))); }
public void WithNoDeleteAndFiniteLifetime() { var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>(); var subaddress1 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithHouseNumberId(command.HouseNumberId); var subaddress2 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithHouseNumberId(command.HouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), command.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress1.SubaddressId)), subaddress1.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress2.SubaddressId)), subaddress2.ToLegacyEvent()) .When(command) .Then(_parcelId, new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(subaddress1.SubaddressId)), new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(subaddress2.SubaddressId)), new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(command.HouseNumberId)), command.ToLegacyEvent())); }
public void WithNoDeleteAndInfiniteLifetime_BasedOnSnapshot() { var command = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)); var addressId = AddressId.CreateFor(command.SubaddressId); var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent(); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>()) .Given(_snapshotId, SnapshotBuilder .CreateDefaultSnapshot(_parcelId) .WithParcelStatus(ParcelStatus.Realized) .WithAddressIds(new List <AddressId> { AddressId.CreateFor(command.HouseNumberId) }) .WithLastModificationBasedOnCrab(Modification.Update) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId> { { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) } }) .Build(3, EventSerializerSettings)) .When(command) .Then(new[] { new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, addressId)), new Fact(_parcelId, command.ToLegacyEvent()) })); }
public void AddTerrainObjectHouseNumber_BasedOnSnapshot() { var command = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Insert); var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent(); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>()) .Given(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithAddressIds(new[] { AddressId.CreateFor(command.HouseNumberId) }) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId>() { { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.HouseNumberId) } }) .WithIsRemoved(true) .Build(3, EventSerializerSettings) ) .When(command) .Throws(new ParcelRemovedException($"Cannot change removed parcel for parcel id {_parcelId}"))); }
public async Task ImportHouseNumberStatusFromCrab(Func <IAddresses> getAddresses, CommandMessage <ImportHouseNumberStatusFromCrab> message, CancellationToken ct) { var addresses = getAddresses(); var addressId = AddressId.CreateFor(message.Command.HouseNumberId); var address = await addresses.GetAsync(addressId, ct); ImportHouseNumberStatusFromCrab(address, message.Command); }
public async Task ImportSubaddressMailCantonFromCrab(Func <IAddresses> getAddresses, CommandMessage <ImportSubaddressMailCantonFromCrab> message, CancellationToken ct) { var addresses = getAddresses(); var addressId = AddressId.CreateFor(message.Command.SubaddressId); var address = await addresses.GetAsync(addressId, ct); ImportSubaddressMailCantonFromCrab(address, message.Command); }
public async Task AssignPersistentLocalIdForCrabSubaddressId(Func <IAddresses> getAddresses, CommandMessage <AssignPersistentLocalIdForCrabSubaddressId> message, CancellationToken ct) { var addressId = AddressId.CreateFor(message.Command.SubaddressId); var address = await getAddresses().GetAsync(addressId, ct); address.AssignPersistentLocalId( message.Command.PersistentLocalId, message.Command.AssignmentDate); }
public IEnumerable <AddressId> AddressIdsEligableToRemoveFor(CrabHouseNumberId houseNumberId) { if (LastSubaddressRecordsByHouseNumberId.ContainsKey(houseNumberId)) { return(LastSubaddressRecordsByHouseNumberId[houseNumberId] .Where(x => _addressIds.Contains(AddressId.CreateFor(new CrabSubaddressId(x.SubaddressId)))) .Select(x => AddressId.CreateFor(new CrabSubaddressId(x.SubaddressId)))); } return(new List <AddressId>()); }
public void WhenNoDeleteAndInfiniteLifetime() { var command = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(_fixture.Create <LocalDateTime>(), null)); Assert(new Scenario() .Given(_parcelId, _fixture.Create <ParcelWasRegistered>()) .When(command) .Then(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId)), command.ToLegacyEvent())); }
public IEnumerable <AddressId> AddressIdsEligableToAddFor(CrabHouseNumberId houseNumberId) { if (LastSubaddressRecordsByHouseNumberId.ContainsKey(houseNumberId)) { return(LastSubaddressRecordsByHouseNumberId[houseNumberId] .Where(x => x.Modification != CrabModification.Delete && !x.EndDateTime.HasValue && !_addressIds.Contains(AddressId.CreateFor(new CrabSubaddressId(x.SubaddressId)))) .Select(x => AddressId.CreateFor(new CrabSubaddressId(x.SubaddressId)))); } return(new List <AddressId>()); }
public void WithNoDeleteAndInfiniteLifetime_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)); var subaddress1 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithHouseNumberId(command.HouseNumberId); var subaddress2 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithHouseNumberId(command.HouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), subaddress1.ToLegacyEvent(), subaddress2.ToLegacyEvent()) .When(command) .Then(new [] { new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId))), new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(subaddress1.SubaddressId))), new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(subaddress2.SubaddressId))), new Fact(_parcelId, command.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithLastModificationBasedOnCrab(Modification.Update) .WithImportedSubaddressFromCrab(new List <AddressSubaddressWasImportedFromCrab> { subaddress1.ToLegacyEvent(), subaddress2.ToLegacyEvent() }) .WithAddressIds(new List <AddressId> { AddressId.CreateFor(command.HouseNumberId), AddressId.CreateFor(subaddress1.SubaddressId), AddressId.CreateFor(subaddress2.SubaddressId) }) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId> { { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) } }) .Build(6, EventSerializerSettings)) })); }
public void WhenNoDeleteAndFiniteLifetimeWithNoAddress() { var command = Fixture.Create <ImportSubaddressFromCrab>(); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent()) .When(command) .Then(_parcelId, command.ToLegacyEvent())); }
public void RemoveSubaddressCoupledToTwoTerrainObjectHouseNumbers() { var firstHouseNrCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert); var subaddress1 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var subaddress2 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var secondCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId) .WithModification(CrabModification.Correction); var removeSubaddress2 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithSubaddressId(subaddress2.SubaddressId) .WithModification(CrabModification.Delete) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(firstHouseNrCommand.HouseNumberId)), firstHouseNrCommand.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress1.SubaddressId)), subaddress1.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress2.SubaddressId)), subaddress2.ToLegacyEvent(), secondCommand.ToLegacyEvent(), subaddress2.ToLegacyEvent()) .When(removeSubaddress2) .Then(_parcelId, new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(removeSubaddress2.SubaddressId)), removeSubaddress2.ToLegacyEvent())); }
public void WhenLifetimeIsFinite_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>())); var terrainObjectHouseNumberWasImportedFromCrab = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent(); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelWasRealized>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), terrainObjectHouseNumberWasImportedFromCrab, Fixture.Create <ParcelAddressWasDetached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .WithLifetime(command.Lifetime) .WithTerrainObjectHouseNumberId(new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId)) .WithModification(CrabModification.Historize) .ToLegacyEvent()) .When(command) .Then(new [] { new Fact(_parcelId, command.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder .CreateDefaultSnapshot(_parcelId) .WithParcelStatus(ParcelStatus.Realized) .WithAddressIds(new List <AddressId>()) .WithLastModificationBasedOnCrab(Modification.Update) .WithImportedSubaddressFromCrab(new List <AddressSubaddressWasImportedFromCrab> { command.ToLegacyEvent() }) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId> { { new CrabTerrainObjectHouseNumberId(terrainObjectHouseNumberWasImportedFromCrab.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) } }) .Build(6, EventSerializerSettings)) })); }
public void ChangeAddedTerrainObjectHouseNumberToNewHouseNumber() { var firstHouseNrCommand = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithHouseNumberId(new CrabHouseNumberId(-1)) .WithModification(CrabModification.Insert); var subaddress1 = _fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var subaddress2 = _fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var secondCommand = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithHouseNumberId(new CrabHouseNumberId(-1)) .WithModification(CrabModification.Insert); var firstChangedCommand = _fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithTerrainObjectHouseNumberId(firstHouseNrCommand.TerrainObjectHouseNumberId) .WithModification(CrabModification.Correction); Assert(new Scenario() .Given(_parcelId, _fixture.Create <ParcelWasRegistered>(), _fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(firstHouseNrCommand.HouseNumberId)), firstHouseNrCommand.ToLegacyEvent(), _fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress1.SubaddressId)), subaddress1.ToLegacyEvent(), _fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress2.SubaddressId)), subaddress2.ToLegacyEvent(), secondCommand.ToLegacyEvent()) .When(firstChangedCommand) .Then(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(firstChangedCommand.HouseNumberId)), firstChangedCommand.ToLegacyEvent())); }
public void WhenDeleteAndInfiniteLifetimeWithNoAddress() { var command = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Delete); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent()) .When(command) .Then(_parcelId, command.ToLegacyEvent())); }
public AddressCrabHouseNumberIdExtractProjection(Encoding encoding) { _encoding = encoding ?? throw new ArgumentNullException(nameof(encoding)); When <Envelope <AddressWasRegistered> >(async(context, message, ct) => { await context.AddressCrabHouseNumberIdExtract.AddAsync(new AddressCrabHouseNumberIdExtractItem { AddressId = message.Message.AddressId, DbaseRecord = new AddressCrabHouseNumberIdDbaseRecord().ToBytes(_encoding), }, cancellationToken: ct); }); When <Envelope <AddressBecameComplete> >(async(context, message, ct) => { var item = await context.AddressCrabHouseNumberIdExtract.FindAsync(message.Message.AddressId, cancellationToken: ct); UpdateDbaseRecordField(item, record => { record.isvolledig.Value = true; }); }); When <Envelope <AddressBecameIncomplete> >(async(context, message, ct) => { var item = await context.AddressCrabHouseNumberIdExtract.FindAsync(message.Message.AddressId, cancellationToken: ct); UpdateDbaseRecordField(item, record => { record.isvolledig.Value = false; }); }); When <Envelope <AddressPersistentLocalIdWasAssigned> >(async(context, message, ct) => { var item = await context.AddressCrabHouseNumberIdExtract.FindAsync(message.Message.AddressId, cancellationToken: ct); item.PersistentLocalId = message.Message.PersistentLocalId; UpdateDbaseRecordField(item, record => { record.adresid.Value = message.Message.PersistentLocalId; }); }); When <Envelope <AddressHouseNumberWasImportedFromCrab> >(async(context, message, ct) => { Guid addressId = AddressId.CreateFor(new CrabHouseNumberId(message.Message.HouseNumberId)); var item = await context.AddressCrabHouseNumberIdExtract.FindAsync(addressId, cancellationToken: ct); if (item != null) { item.CrabHouseNumberId = message.Message.HouseNumberId; UpdateDbaseRecordField(item, record => { record.crabhnrid.Value = message.Message.HouseNumberId; }); } }); }
public void AddTerrainObjectHouseNumber() { var command = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Insert); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(command.HouseNumberId)), Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithHouseNumberId(command.HouseNumberId) .ToLegacyEvent(), Fixture.Create <ParcelWasRemoved>() ) .When(command) .Throws(new ParcelRemovedException($"Cannot change removed parcel for parcel id {_parcelId}"))); }
public async Task ImportHouseNumberFromCrab(Func <IAddresses> getAddresses, CommandMessage <ImportHouseNumberFromCrab> message, CancellationToken ct) { var addresses = getAddresses(); var addressId = AddressId.CreateFor(message.Command.HouseNumberId); var streetNameId = StreetNameId.CreateFor(message.Command.StreetNameId); var address = await GetOrRegisterAddress(addresses, addressId, streetNameId, message.Command.HouseNumber, ct); if (!address.HasValue) { address = new Optional <Address>( Address.Register( new AddressId(addressId), new StreetNameId(streetNameId), message.Command.HouseNumber)); addresses.Add(addressId, address.Value); } ImportHouseNumberFromCrab(address.Value, message.Command); }
private static async Task <CrabEditClientResult <AddressId> > AddToCrab( AddressCrabEditClient editClient, AddAddressRequest request, CancellationToken cancellationToken) { if (request.BoxNumber.IsNullOrWhiteSpace()) { var addHouseNumberResult = await editClient.AddHouseNumberToCrab(request, cancellationToken); return(new CrabEditClientResult <AddressId>( AddressId.CreateFor(addHouseNumberResult.Result), addHouseNumberResult.ExecutionTime)); } var addSubaddressResult = await editClient.AddSubaddressToCrab(request, cancellationToken); return(new CrabEditClientResult <AddressId>( AddressId.CreateFor(addSubaddressResult.Result), addSubaddressResult.ExecutionTime)); }
public void WithDifferentHouseNumberId_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var oldHouseNumberId = new CrabHouseNumberId(-1); var oldCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(oldHouseNumberId); var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Correction) .WithTerrainObjectHouseNumberId(oldCommand.TerrainObjectHouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(oldHouseNumberId)), oldCommand.ToLegacyEvent()) .When(command) .Then(new[] { new Fact(_parcelId, new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(oldHouseNumberId))), new Fact(_parcelId, new ParcelAddressWasAttached(_parcelId, AddressId.CreateFor(command.HouseNumberId))), new Fact(_parcelId, command.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithLastModificationBasedOnCrab(Modification.Update) .WithAddressIds(new List <AddressId> { AddressId.CreateFor(command.HouseNumberId) }) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId> { { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) } }) .Build(5, EventSerializerSettings)) })); }
public void ImportSubaddressFromCrab( CrabSubaddressId subaddressId, CrabHouseNumberId houseNumberId, BoxNumber boxNumber, CrabBoxNumberType boxNumberType, CrabLifetime lifetime, CrabTimestamp timestamp, CrabOperator @operator, CrabModification?modification, CrabOrganisation?organisation) { GuardRemoved(modification); var addressId = AddressId.CreateFor(subaddressId); if (_addressCollection.Contains(AddressId.CreateFor(houseNumberId)) && !_addressCollection.Contains(addressId) && modification != CrabModification.Delete && !lifetime.EndDateTime.HasValue) { ApplyChange(new ParcelAddressWasAttached(_parcelId, addressId)); } else if (_addressCollection.Contains(addressId) && (modification == CrabModification.Delete || lifetime.EndDateTime.HasValue)) { ApplyChange(new ParcelAddressWasDetached(_parcelId, addressId)); } ApplyChange(new AddressSubaddressWasImportedFromCrab( subaddressId, houseNumberId, boxNumber, boxNumberType, lifetime, timestamp, @operator, modification, organisation)); }
public void AddAlreadyExistingSubaddressForOtherTerrainObjectHouseNr() { var firstHouseNrCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert); var subaddress1 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var subaddress2 = Fixture.Create <ImportSubaddressFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithModification(CrabModification.Insert) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId); var secondCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(LocalDateTime.FromDateTime(DateTime.Now), null)) .WithHouseNumberId(firstHouseNrCommand.HouseNumberId) .WithModification(CrabModification.Correction); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(firstHouseNrCommand.HouseNumberId)), firstHouseNrCommand.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress1.SubaddressId)), subaddress1.ToLegacyEvent(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(AddressId.CreateFor(subaddress2.SubaddressId)), subaddress2.ToLegacyEvent(), secondCommand.ToLegacyEvent()) .When(subaddress1) .Then(_parcelId, subaddress1.ToLegacyEvent())); }
public void WhenDeleteAndInfiniteLifetimeWithAddress_BasedOnSnapshot() { var command = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithModification(CrabModification.Insert); var deleteCommand = Fixture.Create <ImportTerrainObjectHouseNumberFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), null)) .WithTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId) .WithHouseNumberId(command.HouseNumberId) .WithModification(CrabModification.Delete); var addressId = AddressId.CreateFor(command.HouseNumberId); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>(), Fixture.Create <ParcelAddressWasAttached>() .WithAddressId(addressId), command.ToLegacyEvent()) .Given(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithLastModificationBasedOnCrab(Modification.Insert) .WithAddressIds(new List <AddressId> { addressId }) .WithActiveHouseNumberIdsByTerrainObjectHouseNr(new Dictionary <CrabTerrainObjectHouseNumberId, CrabHouseNumberId> { { new CrabTerrainObjectHouseNumberId(command.TerrainObjectHouseNumberId), new CrabHouseNumberId(command.HouseNumberId) } }) .Build(2, EventSerializerSettings)) .When(deleteCommand) .Then(_parcelId, new ParcelAddressWasDetached(_parcelId, addressId), deleteCommand.ToLegacyEvent())); }
public void ImportTerrainObjectHouseNumberFromCrab( CrabTerrainObjectHouseNumberId terrainObjectHouseNumberId, CrabTerrainObjectId terrainObjectId, CrabHouseNumberId houseNumberId, CrabLifetime lifetime, CrabTimestamp timestamp, CrabOperator @operator, CrabModification?modification, CrabOrganisation?organisation) { GuardRemoved(modification); var legacyEvent = new TerrainObjectHouseNumberWasImportedFromCrab( terrainObjectHouseNumberId, terrainObjectId, houseNumberId, lifetime, timestamp, @operator, modification, organisation); var addressId = AddressId.CreateFor(houseNumberId); if (_addressCollection.Contains(addressId) && (modification == CrabModification.Delete || lifetime.EndDateTime.HasValue)) { if (_activeHouseNumberIdsByTerreinObjectHouseNr.Values.Count(x => x == houseNumberId) == 1) { foreach (var addressIdToRemove in _addressCollection.AddressIdsEligableToRemoveFor(houseNumberId)) { ApplyChange(new ParcelAddressWasDetached(_parcelId, addressIdToRemove)); } ApplyChange(new ParcelAddressWasDetached(_parcelId, addressId)); } } else { if (_activeHouseNumberIdsByTerreinObjectHouseNr.ContainsKey(terrainObjectHouseNumberId) && _activeHouseNumberIdsByTerreinObjectHouseNr[terrainObjectHouseNumberId] != houseNumberId) { var currentCrabHouseNumberId = _activeHouseNumberIdsByTerreinObjectHouseNr[terrainObjectHouseNumberId]; if (_activeHouseNumberIdsByTerreinObjectHouseNr.Values.Count(x => x == currentCrabHouseNumberId) == 1) { foreach (var addressIdToRemove in _addressCollection.AddressIdsEligableToRemoveFor( currentCrabHouseNumberId)) { ApplyChange(new ParcelAddressWasDetached(_parcelId, addressIdToRemove)); } ApplyChange(new ParcelAddressWasDetached(_parcelId, AddressId.CreateFor(currentCrabHouseNumberId))); } } if (!_addressCollection.Contains(addressId) && modification != CrabModification.Delete && !lifetime.EndDateTime.HasValue) { ApplyChange(new ParcelAddressWasAttached(_parcelId, addressId)); foreach (var addressIdToAdd in _addressCollection.AddressIdsEligableToAddFor(houseNumberId)) { ApplyChange(new ParcelAddressWasAttached(_parcelId, addressIdToAdd)); } } } ApplyChange(legacyEvent); }
public CrabIdToPersistentLocalIdProjections() { When <Envelope <AddressWasRegistered> >(async(context, message, ct) => { await context .CrabIdToPersistentLocalIds .AddAsync(new CrabIdToPersistentLocalIdItem { AddressId = message.Message.AddressId, StreetNameId = message.Message.StreetNameId, HouseNumber = message.Message.HouseNumber, }); }); When <Envelope <AddressHouseNumberWasChanged> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.HouseNumber = message.Message.HouseNumber; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressHouseNumberWasCorrected> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.HouseNumber = message.Message.HouseNumber; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressBoxNumberWasChanged> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.BoxNumber = message.Message.BoxNumber; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressBoxNumberWasCorrected> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.BoxNumber = message.Message.BoxNumber; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressBoxNumberWasRemoved> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.BoxNumber = null; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressStreetNameWasChanged> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.StreetNameId = message.Message.StreetNameId; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressStreetNameWasCorrected> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.StreetNameId = message.Message.StreetNameId; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressPostalCodeWasChanged> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.PostalCode = message.Message.PostalCode; }); When <Envelope <AddressPostalCodeWasCorrected> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.PostalCode = message.Message.PostalCode; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressPostalCodeWasRemoved> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.PostalCode = null; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressPersistentLocalIdWasAssigned> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.PersistentLocalId = message.Message.PersistentLocalId; }); When <Envelope <AddressBecameComplete> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.IsComplete = true; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressBecameIncomplete> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.IsComplete = false; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressWasRemoved> >(async(context, message, ct) => { var item = await context.CrabIdToPersistentLocalIds.FindAsync(message.Message.AddressId, cancellationToken: ct); item.IsRemoved = true; UpdateVersion(item, message.Message.Provenance.Timestamp); }); When <Envelope <AddressHouseNumberWasImportedFromCrab> >(async(context, message, ct) => { var addressId = (Guid)AddressId.CreateFor(new CrabHouseNumberId(message.Message.HouseNumberId)); var item = await context.CrabIdToPersistentLocalIds.FindAsync(addressId, cancellationToken: ct); if (item != null) { item.HouseNumberId = message.Message.HouseNumberId; } }); When <Envelope <AddressSubaddressWasImportedFromCrab> >(async(context, message, ct) => { var addressId = (Guid)AddressId.CreateFor(new CrabSubaddressId(message.Message.SubaddressId)); var item = await context.CrabIdToPersistentLocalIds.FindAsync(addressId, cancellationToken: ct); item.SubaddressId = message.Message.SubaddressId; }); // Below here - only update version When <Envelope <AddressBecameCurrent> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressBecameNotOfficiallyAssigned> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressOfficialAssignmentWasRemoved> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressPositionWasCorrected> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressPositionWasRemoved> >(async(context, message, ct) => { await FindAndUpdateVersion(context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressStatusWasCorrectedToRemoved> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressStatusWasRemoved> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasCorrectedToCurrent> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasCorrectedToNotOfficiallyAssigned> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasCorrectedToOfficiallyAssigned> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasCorrectedToProposed> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasCorrectedToRetired> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasOfficiallyAssigned> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasPositioned> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasProposed> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressWasRetired> >(async(context, message, ct) => { await FindAndUpdateVersion( context, message.Message.AddressId, message.Message.Provenance.Timestamp, ct); }); When <Envelope <AddressHouseNumberStatusWasImportedFromCrab> >(async(context, message, ct) => DoNothing()); When <Envelope <AddressHouseNumberPositionWasImportedFromCrab> >(async(context, message, ct) => DoNothing()); When <Envelope <AddressHouseNumberMailCantonWasImportedFromCrab> >(async(context, message, ct) => DoNothing()); When <Envelope <AddressSubaddressPositionWasImportedFromCrab> >(async(context, message, ct) => DoNothing()); When <Envelope <AddressSubaddressStatusWasImportedFromCrab> >(async(context, message, ct) => DoNothing()); }