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 void ThenIsRegistered_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportTerrainObjectFromCrab>() .WithLifetime(new CrabLifetime(null, null)) .WithModification(CrabModification.Insert); var parcelId = new ParcelId(command.CaPaKey.CreateDeterministicId()); var snapshotId = GetSnapshotIdentifier(parcelId); Assert(new Scenario() .GivenNone() .When(command) .Then(new [] { new Fact(parcelId, new ParcelWasRegistered(parcelId, command.CaPaKey)), new Fact(parcelId, new ParcelWasRealized(parcelId)), new Fact(parcelId, command.ToLegacyEvent()), new Fact(snapshotId, SnapshotBuilder.CreateDefaultSnapshot(parcelId) .WithParcelStatus(ParcelStatus.Realized) .Build(2, EventSerializerSettings)) })); }
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 IntervalStrategy_ShouldSnapshotAccordingToTheInterval(int interval, int[] expected) { var strategy = new IntervalStrategy(interval); for (var index = 1; index <= expected.Last(); index++) { if (expected.Contains(index)) { Assert.True(strategy.ShouldTakeSnapshot(new PersistedEvent(null, index))); } else { Assert.False(strategy.ShouldTakeSnapshot(new PersistedEvent(null, index))); } } }
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 WhenLifetimeIsFinite_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportTerrainObjectFromCrab>() .WithLifetime(new CrabLifetime(Fixture.Create <LocalDateTime>(), Fixture.Create <LocalDateTime>())); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>()) .When(command) .Then(new [] { new Fact(_parcelId, new ParcelWasRetired(_parcelId)), new Fact(_parcelId, command.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithParcelStatus(ParcelStatus.Retired) .Build(2, EventSerializerSettings)) })); }
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 WhenModificationDelete_WithSnapshot() { Fixture.Register(() => (ISnapshotStrategy)IntervalStrategy.SnapshotEvery(1)); var command = Fixture.Create <ImportTerrainObjectFromCrab>() .WithModification(CrabModification.Delete); Assert(new Scenario() .Given(_parcelId, Fixture.Create <ParcelWasRegistered>()) .When(command) .Then(new [] { new Fact(_parcelId, new ParcelWasRemoved(_parcelId)), new Fact(_parcelId, command.ToLegacyEvent()), new Fact(_snapshotId, SnapshotBuilder.CreateDefaultSnapshot(_parcelId) .WithIsRemoved(true) .WithLastModificationBasedOnCrab(Modification.Delete) .Build(2, EventSerializerSettings)) })); }