diff --git a/test/Guidelines.md b/test/Guidelines.md new file mode 100644 index 000000000..7088dac23 --- /dev/null +++ b/test/Guidelines.md @@ -0,0 +1,29 @@ +# Base Registries Unit Testing Guidelines + +## Introduction +This document outlines the guidelines for writing unit tests in C# following the "Given-When-Then" principle and encourages the use of the builder pattern for test data creation. + +## Given-When-Then Principle +We adhere to the "Given-When-Then" principle to structure our unit tests. The test method naming follows the format: +- **Given**: Describes the initial conditions. +- **When**: Describes the action or scenario. +- **Then**: Describes the expected outcome. + +### Folder Structure +- Tests related to "When" should be organized within folders that represent the action or scenario, e.g., "WhenProposingStreetName." + +### Class Structure +- Each test class should correspond to the "Given" part, e.g., "GivenMunicipality." + +### Method Naming +- Test method names should follow the format: "With{Condition}_Then{Outcome}," where: + - "With" represents the condition being set up. + - "Then" represents the expected outcome of the test. + +## Builder Pattern for Test Data +We encourage the use of the builder pattern to create test data. This approach provides a cleaner and more flexible way to set up test scenarios. + +### Test Data Builders +- Create separate test data builder classes or methods for each class under test. +- Builders should have clear and expressive methods for configuring the object's state. +- Default values being set by the builder should be documented in a summary diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasAFacilityLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipality.cs similarity index 55% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasAFacilityLanguage.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipality.cs index 22d6d544e..0c3a53ac7 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasAFacilityLanguage.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipality.cs @@ -7,17 +7,16 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenAddingMunicipalityFacility using Municipality; using Municipality.Commands; using Municipality.Events; - using Extensions; using Testing; using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityHasAFacilityLanguage : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityHasAFacilityLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -30,19 +29,15 @@ public GivenMunicipalityHasAFacilityLanguage(ITestOutputHelper testOutputHelper) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void ThenNone(Language language) + public void ThenMunicipalityFacilityLanguageWasAdded(Language language) { Fixture.Register(() => language); var commandLanguageAdded = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) + .Given(_streamId, + Fixture.Create()) .When(commandLanguageAdded) - .ThenNone()); + .Then(new Fact(_streamId, new MunicipalityFacilityLanguageWasAdded(_municipalityId, language)))); } [Theory] @@ -50,43 +45,36 @@ public void ThenNone(Language language) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void AndWasRemoved_FacilityLanguageWasAdded(Language language) + public void WithAlreadyExistingFacilityLanguage_ThenNone(Language language) { Fixture.Register(() => language); var commandLanguageAdded = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - Fixture.Create(), - Fixture.Create() - }) + Fixture.Create()) .When(commandLanguageAdded) - .Then(new[] - { - new Fact(_streamId, new MunicipalityFacilityLanguageWasAdded(_municipalityId, language)) - })); + .ThenNone()); } - [Fact] - public void AndHasMultipleLanguages_TheCorrectOneWasAdded() + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithRemovedFacilityLanguage_ThenFacilityLanguageWasAdded(Language language) { - var languageAddGerman = Fixture.Create().WithLanguage(Language.German); - var commandAddedEnglish = Fixture.Create().WithLanguage(Language.English); - var commandAddedDutch = Fixture.Create().WithLanguage(Language.Dutch); + Fixture.Register(() => language); + var commandLanguageAdded = Fixture.Create(); + Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - commandAddedEnglish.ToEvent(), - commandAddedDutch.ToEvent() - }) - .When(languageAddGerman) - .Then(new[] - { - new Fact(_streamId, new MunicipalityFacilityLanguageWasAdded(_municipalityId, Language.German)) - })); + Fixture.Create(), + Fixture.Create()) + .When(commandLanguageAdded) + .Then(new Fact(_streamId, new MunicipalityFacilityLanguageWasAdded(_municipalityId, language)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs deleted file mode 100644 index 571cd9afd..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenAddingMunicipalityFacilityLanguage -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityHasNoFacilityLanguage : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityHasNoFacilityLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenNone(Language language) - { - Fixture.Register(() => language); - var commandLanguageAdded = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandLanguageAdded) - .Then(new[] - { - new Fact(_streamId, new MunicipalityFacilityLanguageWasAdded(_municipalityId, language)) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasAOfficialLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipality.cs similarity index 63% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasAOfficialLanguage.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipality.cs index 761739ce2..a69be1165 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasAOfficialLanguage.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipality.cs @@ -12,12 +12,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenAddingMunicipalityOfficial using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityHasAOfficialLanguage : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityHasAOfficialLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -30,17 +30,31 @@ public GivenMunicipalityHasAOfficialLanguage(ITestOutputHelper testOutputHelper) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void ThenNone(Language language) + public void ThenMunicipalityOfficialLanguageWasAdded(Language language) + { + Fixture.Register(() => language); + var commandLanguageAdded = Fixture.Create(); + Assert(new Scenario() + .Given(_streamId, + Fixture.Create()) + .When(commandLanguageAdded) + .Then(new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, language)))); + } + + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithAlreadyExistingOfficialLanguage_ThenNone(Language language) { Fixture.Register(() => language); var commandLanguageAdded = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - Fixture.Create() - }) + Fixture.Create()) .When(commandLanguageAdded) .ThenNone()); } @@ -50,43 +64,33 @@ public void ThenNone(Language language) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void AndWasRemoved_OfficialLanguageWasAdded(Language language) + public void WithRemovedOfficialLanguage_ThenOfficialLanguageWasAdded(Language language) { Fixture.Register(() => language); var commandLanguageAdded = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), Fixture.Create(), - Fixture.Create() - }) + Fixture.Create()) .When(commandLanguageAdded) - .Then(new[] - { - new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, language)) - })); + .Then(new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, language)))); } [Fact] - public void AndHasMultipleLanguages_TheCorrectOneWasAdded() + public void WithOtherExistingLanguages_ThenAddTheNonExistingLanguage() { var languageAddGerman = Fixture.Create().WithLanguage(Language.German); var commandAddedEnglish = Fixture.Create().WithLanguage(Language.English); var commandAddedDutch = Fixture.Create().WithLanguage(Language.Dutch); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), commandAddedEnglish.ToEvent(), - commandAddedDutch.ToEvent() - }) + commandAddedDutch.ToEvent()) .When(languageAddGerman) - .Then(new[] - { - new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.German)) - })); + .Then(new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.German)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasNoOfficialLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasNoOfficialLanguage.cs deleted file mode 100644 index aed0b6d9b..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenAddingMunicipalityOfficialLanguage/GivenMunicipalityHasNoOfficialLanguage.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenAddingMunicipalityOfficialLanguage -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityHasNoOfficialLanguage : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityHasNoOfficialLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenNone(Language language) - { - Fixture.Register(() => language); - var commandLanguageAdded = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandLanguageAdded) - .Then(new[] - { - new Fact(_streamId, new MunicipalityOfficialLanguageWasAdded(_municipalityId, language)) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenApprovingStreetName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenApprovingStreetName/GivenMunicipality.cs index 23b2a1b36..852353222 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenApprovingStreetName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenApprovingStreetName/GivenMunicipality.cs @@ -5,14 +5,13 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenApprovingStreetName using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; - using Extensions; using Testing; using Xunit; using Xunit.Abstractions; @@ -34,8 +33,7 @@ public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHe [Fact] public void ThenStreetNameWasApproved() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); // Act, assert Assert(new Scenario() @@ -48,10 +46,9 @@ public void ThenStreetNameWasApproved() } [Fact] - public void ThenStreetNameIsNotFoundExceptionWasThrown() + public void WithNoStreetName_ThenThrowsStreetNameIsNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); @@ -63,34 +60,16 @@ public void ThenStreetNameIsNotFoundExceptionWasThrown() } [Fact] - public void ThenStreetNameIsRemovedExceptionWasThrown() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -103,33 +82,14 @@ public void ThenStreetNameIsRemovedExceptionWasThrown() } [Fact] - public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExceptionWasThrown() + public void WithInvalidMunicipalityStatus_ThenThrowsMunicipalityHasInvalidStatusException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .Build(); // Act, assert Assert(new Scenario() @@ -144,33 +104,14 @@ public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExcept [Theory] [InlineData(StreetNameStatus.Rejected)] [InlineData(StreetNameStatus.Retired)] - public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -185,30 +126,12 @@ public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus st [Fact] public void WithStreetNameAlreadyCurrent_ThenNone() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .Build(); // Act, assert Assert(new Scenario() @@ -221,10 +144,11 @@ public void WithStreetNameAlreadyCurrent_ThenNone() } [Fact] - public void ThenStreetNameStatusIsCurrent() + public void StateCheck() { var persistentLocalId = Fixture.Create(); var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); + aggregate.Initialize(new List { Fixture.Create(), diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingMunicipalityNisCode/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingMunicipalityNisCode/GivenMunicipality.cs index 12b4cc240..d3daa77ef 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingMunicipalityNisCode/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingMunicipalityNisCode/GivenMunicipality.cs @@ -14,32 +14,26 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenChangingMunicipalityNisCod public sealed class GivenMunicipality : StreetNameRegistryTest { - private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; public GivenMunicipality(ITestOutputHelper output) : base(output) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); _streamId = Fixture.Create(); } [Fact] public void ThenNisCodeChanged() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, Fixture.Create()) .When(command) - .Then(new[] - { - new Fact(_streamId, - new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)) - })); + .Then(new Fact(_streamId, + new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)))); } [Fact] @@ -47,7 +41,6 @@ public void ThenNisCodeChangedToNisCodeRonse() { var nisCode = new NisCode("45041"); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithNisCode(nisCode); Assert(new Scenario() @@ -61,11 +54,10 @@ public void ThenNisCodeChangedToNisCodeRonse() } [Fact] - public void ThenNisCodeChangedToNull() + public void WithNoNisCode_ThenThrowsNoNisCodeHasNoValueException() { var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) - .WithNisCode(null); + .WithNisCode(null!); Assert(new Scenario() .Given(_streamId, @@ -75,11 +67,10 @@ public void ThenNisCodeChangedToNull() } [Fact] - public void WithSameNisCodeThenNothingHappens() + public void WithTheSameNisCode_ThenNone() { var municipalityWasImported = Fixture.Create(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithNisCode(new NisCode(municipalityWasImported.NisCode)); Assert(new Scenario() @@ -91,13 +82,6 @@ public void WithSameNisCodeThenNothingHappens() public static class MunicipalityNisCodeWasChangedExtensions { - public static ChangeMunicipalityNisCode WithMunicipalityId( - this ChangeMunicipalityNisCode command, - MunicipalityId municipalityId) - { - return new ChangeMunicipalityNisCode(municipalityId, new NisCode(command.NisCode), command.Provenance); - } - public static ChangeMunicipalityNisCode WithNisCode( this ChangeMunicipalityNisCode command, NisCode nisCode) diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingStreetNameName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingStreetNameName/GivenMunicipality.cs index 8c7e32da2..d36fd6514 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingStreetNameName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenChangingStreetNameName/GivenMunicipality.cs @@ -8,6 +8,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenChangingStreetNameName using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; using Be.Vlaanderen.Basisregisters.GrAr.Legacy; using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; @@ -39,15 +40,15 @@ public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHe public void ThenStreetNameNameWasChanged() { var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(new StreetNameName("Kapelstraat", Language.Dutch)) .WithStreetNameName(new StreetNameName("Rue de la Croix - Rouge", Language.French)); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance)frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); // Act, assert Assert(new Scenario() @@ -59,7 +60,7 @@ public void ThenStreetNameNameWasChanged() Fixture.Create()) .When(command) .Then(new Fact(_streamId, new StreetNameNamesWereChanged(_municipalityId, - command.PersistentLocalId, new Names(new [] + command.PersistentLocalId, new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch), new StreetNameName("Rue de la Croix - Rouge", Language.French) @@ -67,11 +68,9 @@ public void ThenStreetNameNameWasChanged() } [Fact] - public void ThenThrowsStreetNameNotFoundException() + public void WithNoStreetName_ThenThrowsStreetNameNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); - + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); // Act, assert @@ -82,34 +81,16 @@ public void ThenThrowsStreetNameNotFoundException() } [Fact] - public void ThenThrowsStreetNameIsRemovedException() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var removedStreetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var removedStreetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -124,33 +105,14 @@ public void ThenThrowsStreetNameIsRemovedException() [Theory] [InlineData(StreetNameStatus.Retired)] [InlineData(StreetNameStatus.Rejected)] - public void ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -163,57 +125,22 @@ public void ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus statu } [Fact] - public void WithDuplicateNameAndRejectedStatus_ThenThrowsStreetNameHasInvalidStatusException() - { - var streetNameNames = new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }); - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) - .WithStreetNameName(streetNameNames.First()); - - var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)languageWasAdded).SetProvenance(Fixture.Create()); - - var streetNameWasProposedV2_1 = Fixture.Create(); - var streetNameWasProposedV2_2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - new PersistentLocalId(streetNameWasProposedV2_1.PersistentLocalId + 1)); - ((ISetProvenance)streetNameWasProposedV2_2).SetProvenance(Fixture.Create()); - - // Act, assert - - Assert(new Scenario() - .Given(_streamId, - Fixture.Create(), - Fixture.Create(), - languageWasAdded, - streetNameWasProposedV2_1, - streetNameWasProposedV2_2, - Fixture.Create()) - .When(command) - .Throws(new StreetNameHasInvalidStatusException(command.PersistentLocalId))); - } - - [Fact] - public void WithStreetNameNameAlreadyInUse_ThenThrowsStreetNameNameAlreadyExistsException() + public void WithStreetAlreadyActiveStreetNameName_ThenThrowsStreetNameNameAlreadyExistsException() { var streetNameNames = new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }); var command = Fixture.Create() .WithPersistentLocalId(new PersistentLocalId(123)) - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(streetNameNames.First()); var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)languageWasAdded).SetProvenance(Fixture.Create()); + languageWasAdded.SetProvenance(Fixture.Create()); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - new PersistentLocalId(456)); - ((ISetProvenance)streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("abc")) + .WithNames(streetNameNames) + .WithPersistentLocalId(456) + .Build(); // Act, assert Assert(new Scenario() @@ -231,16 +158,18 @@ public void WithStreetNameNameAlreadyInUse_ThenThrowsStreetNameNameAlreadyExists [Fact] public void WithInvalidLanguage_ThenThrowsStreetNameNameLanguageNotSupportedException() { - var streetNameNames = new Names(new[] { + var streetNameNames = new Names(new[] + { new StreetNameName("Kapelstraat", Language.Dutch), - new StreetNameName("Rue de la Chapelle", Language.French) }); + new StreetNameName("Rue de la Chapelle", Language.French) + }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(streetNameNames); - var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance)languageWasAdded).SetProvenance(Fixture.Create()); + var languageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); // Act, assert Assert(new Scenario() @@ -257,26 +186,26 @@ public void WithInvalidLanguage_ThenThrowsStreetNameNameLanguageNotSupportedExce [Fact] public void WithNoChanges_ThenNothing() { - var streetNameNames = new Names(new[] { + var streetNameNames = new Names(new[] + { new StreetNameName("Kapelstraat", Language.Dutch), - new StreetNameName("Rue de la Chapelle", Language.French) }); + new StreetNameName("Rue de la Chapelle", Language.French) + }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(streetNameNames); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance)frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - Fixture.Create()); - ((ISetProvenance)streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("abc")) + .WithNames(streetNameNames) + .Build(); // Act, assert Assert(new Scenario() @@ -293,28 +222,28 @@ public void WithNoChanges_ThenNothing() [Fact] public void WithOneChange_ThenOnlyOneStreetNameNameWasChanged() { - var streetNameNames = new Names(new[] { + var streetNameNames = new Names(new[] + { new StreetNameName("Kapelstraat", Language.Dutch), - new StreetNameName("Rue de la Chapelle", Language.French) }); + new StreetNameName("Rue de la Chapelle", Language.French) + }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(streetNameNames.First()) .WithStreetNameName(new StreetNameName("rue de la loi", Language.French)); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance)frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - Fixture.Create()); - ((ISetProvenance)streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("abc")) + .WithNames(streetNameNames) + .Build(); // Act, assert Assert(new Scenario() @@ -332,63 +261,33 @@ public void WithOneChange_ThenOnlyOneStreetNameNameWasChanged() [Theory] [InlineData("")] [InlineData("BO")] - public void WithConflictingHomonymAdditions_ThenStreetNameNameAlreadyExistsExceptionWasThrown(string homonymAddition) + public void WithConflictingHomonymAdditions_ThenThrowsStreetNameNameAlreadyExistsException(string homonymAddition) { var streetNameName = Fixture.Create(); Fixture.Register(() => new Names { streetNameName }); Fixture.Register(() => Language.Dutch); Fixture.Register(() => Taal.NL); + var homonymAdditions = !string.IsNullOrEmpty(homonymAddition) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) + : new HomonymAdditions(); + var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameAWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - !string.IsNullOrEmpty(homonymAddition) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - - var streetNameBWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }), - !string.IsNullOrEmpty(homonymAddition) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameAWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(123) + .WithStatus(StreetNameStatus.Current) + .WithHomonymAdditions(homonymAdditions) + .Build(); + + var streetNameBWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(456) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) })) + .WithHomonymAdditions(homonymAdditions) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameName(Fixture.Create().First()) .WithPersistentLocalId(new PersistentLocalId(streetNameBWasMigrated.PersistentLocalId)); @@ -406,63 +305,36 @@ public void WithConflictingHomonymAdditions_ThenStreetNameNameAlreadyExistsExcep [InlineData("", "BO")] [InlineData("BO", "")] [InlineData("BO", "DE")] - public void WithDifferentHomonymAdditions_ThenStreetNameNamesWereChanged(string homonymAdditionA, string homonymAdditionB) + public void WithDifferentHomonymAdditions_ThenThrowsStreetNameNamesWereChanged(string homonymAdditionA, string homonymAdditionB) { var streetNameName = Fixture.Create(); Fixture.Register(() => new Names { streetNameName }); Fixture.Register(() => Language.Dutch); Fixture.Register(() => Taal.NL); + var homonymAdditionsA = !string.IsNullOrEmpty(homonymAdditionA) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionA, Language.Dutch) }) + : new HomonymAdditions(); + var homonymAdditionsB = !string.IsNullOrEmpty(homonymAdditionB) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionB, Language.Dutch) }) + : new HomonymAdditions(); + var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameAWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - !string.IsNullOrEmpty(homonymAdditionA) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionA, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - - var streetNameBWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }), - !string.IsNullOrEmpty(homonymAdditionB) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionB, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameAWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(123) + .WithStatus(StreetNameStatus.Current) + .WithHomonymAdditions(homonymAdditionsA) + .Build(); + + var streetNameBWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(456) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) })) + .WithHomonymAdditions(homonymAdditionsB) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameName(Fixture.Create().First()) .WithPersistentLocalId(new PersistentLocalId(streetNameBWasMigrated.PersistentLocalId)); @@ -479,18 +351,21 @@ public void WithDifferentHomonymAdditions_ThenStreetNameNamesWereChanged(string [Fact] public void StateCheck() { - var streetNameNames = new Names(new[] { + var streetNameNames = new Names(new[] + { new StreetNameName("Kapelstraat", Language.Dutch), - new StreetNameName("Rue de la Chapelle", Language.French) }); + new StreetNameName("Rue de la Chapelle", Language.French) + }); var persistentLocalId = Fixture.Create(); var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance)frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); aggregate.Initialize(new List { diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetName.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetName.cs index 422e88796..b1e982f04 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetName.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetName.cs @@ -6,11 +6,10 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingHomonymAdditions using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; using Testing; using Xunit; @@ -30,39 +29,26 @@ public GivenStreetName(ITestOutputHelper testOutputHelper) : base(testOutputHelp } [Fact] - public void WithDifferentAddition_ThenStreetNameHomonymAdditionsCorrectedEvent() + public void WithDifferentAdditions_ThenStreetNameHomonymAdditionsCorrected() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var homonymAdditions = new HomonymAdditions { new("DEF", Language.Dutch) }; + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(homonymAdditions) + .Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameHomonymAddition("DEF", Language.Dutch) - }, - new List(), - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names - { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("QRS", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -74,47 +60,32 @@ public void WithDifferentAddition_ThenStreetNameHomonymAdditionsCorrectedEvent() .Then(new Fact(_streamId, new StreetNameHomonymAdditionsWereCorrected( Fixture.Create(), command.PersistentLocalId, - new HomonymAdditions - { - new StreetNameHomonymAddition("DEF", Language.Dutch) - })))); + homonymAdditions)))); } [Fact] public void WithOneDifferentAndOneSameAddition_ThenOnlyOneAdditionWasCorrected() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch), - new StreetNameHomonymAddition("SameFrenchAddition", Language.French), - }, - new List(), - Fixture.Create()); + new("DEF", Language.Dutch), + new("SameFrenchAddition", Language.French), + }).Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("SameFrenchAddition", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -128,45 +99,34 @@ public void WithOneDifferentAndOneSameAddition_ThenOnlyOneAdditionWasCorrected() command.PersistentLocalId, new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch) + new("DEF", Language.Dutch) })))); } [Fact] public void WithNoCorrections_ThenNone() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("ABC", Language.Dutch), - new StreetNameHomonymAddition("DEF", Language.French), - }, - new List(), - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + new("ABC", Language.Dutch), + new("DEF", Language.French), + }) + .Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("DEF", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -181,37 +141,26 @@ public void WithNoCorrections_ThenNone() [Theory] [InlineData(StreetNameStatus.Current)] [InlineData(StreetNameStatus.Proposed)] - public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrectedEvent(StreetNameStatus status) + public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrected(StreetNameStatus status) { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch) - }, - new List(), - Fixture.Create()); + new("DEF", Language.Dutch) + }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -225,7 +174,7 @@ public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrectedEvent(StreetN command.PersistentLocalId, new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch) + new("DEF", Language.Dutch) })))); } @@ -234,28 +183,17 @@ public void StateCheck() { var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(Fixture.Create(), Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names { new StreetNameName("Bergstraat", Language.Dutch), }, - new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - - var streetNameHomonymAdditionWasCorrected = new StreetNameHomonymAdditionsWereCorrected( - Fixture.Create(), - Fixture.Create(), - new List() { new StreetNameHomonymAddition("DEF", Language.Dutch) }); - ((ISetProvenance)streetNameHomonymAdditionWasCorrected).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { new("Bergstraat", Language.Dutch) }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch) })) + .Build(); + + var streetNameHomonymAdditionWasCorrected = new StreetNameHomonymAdditionsWereCorrectedBuilder(Fixture) + .WithHomonymAdditions(new List { new("DEF", Language.Dutch) }) + .Build(); // Act aggregate.Initialize(new List diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameInvalidStatus.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameInvalidStatus.cs index 55ffe474d..6d4ec976c 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameInvalidStatus.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameInvalidStatus.cs @@ -1,15 +1,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingHomonymAdditions { - using System.Collections.Generic; using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; - using StreetNameRegistry.Municipality.Exceptions; + using Municipality.Exceptions; using Testing; using Xunit; using Xunit.Abstractions; @@ -32,35 +29,25 @@ public GivenStreetNameInvalidStatus(ITestOutputHelper testOutputHelper) : base(t [InlineData(StreetNameStatus.Retired)] public void ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch) - }, - new List(), - Fixture.Create()); + new("DEF", Language.Dutch) + }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - new Names - { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(new[] + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .WithNames( + new Names + { + new("Bergstraat", Language.Dutch), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameNameWithoutHomonymAdditionAlreadyExists.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameNameWithoutHomonymAdditionAlreadyExists.cs index 98845d328..c6c0999ca 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameNameWithoutHomonymAdditionAlreadyExists.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameNameWithoutHomonymAdditionAlreadyExists.cs @@ -1,12 +1,10 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingHomonymAdditions { - using System.Collections.Generic; using AutoFixture; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; using Testing; @@ -31,55 +29,39 @@ public GivenStreetNameNameWithoutHomonymAdditionAlreadyExists(ITestOutputHelper [InlineData("HO", "ho")] public void ThenThrowsStreetNameNameAlreadyExistsException(string homonymAddition, string newHomonymAddition) { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - new PersistentLocalId(123), - new HomonymAdditions - { - new StreetNameHomonymAddition(newHomonymAddition, Language.Dutch) - }, - new List(), - Fixture.Create()); + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithPersistentLocalId(123) + .WithHomonymAdditions( + new HomonymAdditions + { + new(newHomonymAddition, Language.Dutch) + }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(123) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bremt", Language.Dutch), - }, - new HomonymAdditions(new[] + new("Bremt", Language.Dutch), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("A", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); - var streetNameWasMigratedToMunicipality2 = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality2 = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(456) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bremt", Language.Dutch), - }, - new HomonymAdditions(new[] + new ("Bremt", Language.Dutch), + }).WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality2).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameWithoutHomonymAddition.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameWithoutHomonymAddition.cs index f5af3a888..2631bb6ec 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameWithoutHomonymAddition.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingHomonymAdditions/GivenStreetNameWithoutHomonymAddition.cs @@ -1,12 +1,10 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingHomonymAdditions { - using System.Collections.Generic; using AutoFixture; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; using Testing; @@ -29,37 +27,26 @@ public GivenStreetNameWithoutHomonymAddition(ITestOutputHelper testOutputHelper) [Fact] public void ThenThrowsCannotCorrectNonExistentHomonymAdditionException() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.German) - }, - new List(), - Fixture.Create()); + new("DEF", Language.German) + }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("QRS", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasNotCurrent.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipality.cs similarity index 66% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasNotCurrent.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipality.cs index 3f2ff4ef3..f7ff25f72 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasNotCurrent.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipality.cs @@ -11,12 +11,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingMunicipalityToCu using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityWasNotCurrent : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityWasNotCurrent(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -25,31 +25,26 @@ public GivenMunicipalityWasNotCurrent(ITestOutputHelper testOutputHelper) : base } [Fact] - public void ThenMunicipalityGetsCorrectedToCurrent() + public void ThenMunicipalityWasCorrectedToCurrent() { var commandCorrectMunicipality = Fixture.Create(); + Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - }) + Fixture.Create()) .When(commandCorrectMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasCorrectedToCurrent(_municipalityId)) - })); + .Then(new Fact(_streamId, new MunicipalityWasCorrectedToCurrent(_municipalityId)))); } [Fact] - public void AndCorrectedToCurrent_ThenNone() + public void WithCurrentMunicipality_ThenNone() { var commandCorrectMunicipality = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - Fixture.Create(), - }) + Fixture.Create()) .When(commandCorrectMunicipality) .ThenNone()); } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasAlreadyCurrent.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasAlreadyCurrent.cs deleted file mode 100644 index 86472d5e6..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToCurrent/GivenMunicipalityWasAlreadyCurrent.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingMunicipalityToCurrent -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityWasAlreadyCurrent : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityWasAlreadyCurrent(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - [Fact] - public void ThenNone() - { - var commandCorrectMunicipality = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) - .When(commandCorrectMunicipality) - .ThenNone()); - } - - [Fact] - public void AndChangedToRetired_ThenItIsChangedToCurrent() - { - var commandCorrectMunicipality = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) - .When(commandCorrectMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasCorrectedToCurrent(_municipalityId)) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasNotRetired.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipality.cs similarity index 66% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasNotRetired.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipality.cs index 89546e0fa..c6a922e7a 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasNotRetired.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipality.cs @@ -11,12 +11,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingMunicipalityToRe using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityWasNotRetired : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityWasNotRetired(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -25,31 +25,25 @@ public GivenMunicipalityWasNotRetired(ITestOutputHelper testOutputHelper) : base } [Fact] - public void ThenMunicipalityGetsCorrectedToRetired() + public void ThenMunicipalityWasCorrectedToRetired() { var commandCorrectMunicipality = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - }) + Fixture.Create()) .When(commandCorrectMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasCorrectedToRetired(_municipalityId)) - })); + .Then(new Fact(_streamId, new MunicipalityWasCorrectedToRetired(_municipalityId)))); } [Fact] - public void AndCorrectedToRetired_ThenNone() + public void WithRetiredMunicipality_ThenNone() { var commandCorrectMunicipality = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - Fixture.Create(), - }) + Fixture.Create()) .When(commandCorrectMunicipality) .ThenNone()); } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasAlreadyRetired.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasAlreadyRetired.cs deleted file mode 100644 index 2dd71b38a..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingMunicipalityToRetired/GivenMunicipalityWasAlreadyRetired.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingMunicipalityToRetired -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityWasAlreadyRetired : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityWasAlreadyRetired(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - [Fact] - public void ThenNone() - { - var commandCorrectMunicipality = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) - .When(commandCorrectMunicipality) - .ThenNone()); - } - - [Fact] - public void AndChangedToCurrent_ThenItIsChangedToRetired() - { - var commandCorrectMunicipality = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) - .When(commandCorrectMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasCorrectedToRetired(_municipalityId)) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipality.cs similarity index 59% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasAlreadyNamed.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipality.cs index dd5f2895f..a9ded1d46 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasAlreadyNamed.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipality.cs @@ -12,12 +12,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingNameMunicipality using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityWasAlreadyNamed : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityWasAlreadyNamed(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -30,25 +30,34 @@ public GivenMunicipalityWasAlreadyNamed(ITestOutputHelper testOutputHelper) : ba [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void ThenNamedAgain(Language language) + public void ThenMunicipalityGetsNamed(Language language) + { + var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); + Assert(new Scenario() + .Given(_streamId, Fixture.Create()) + .When(commandNameMunicipality) + .Then(new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))))); + } + + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithTheSameMunicipalityName_ThenMunicipalityWasNamed(Language language) { var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); var municipalityWasNamed = new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language)); - ((ISetProvenance)municipalityWasNamed).SetProvenance(Fixture.Create()); + municipalityWasNamed.SetProvenance(Fixture.Create()); Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - municipalityWasNamed - }) + .Given(_streamId, + Fixture.Create(), municipalityWasNamed) .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))) - })); + .Then( + new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))))); } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs deleted file mode 100644 index 6b90d95d6..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingNameMunicipality -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityWasNotAlreadyNamed : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityWasNotAlreadyNamed(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenMunicipalityGetsNamed(Language language) - { - var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasAlreadyNamed.cs index 38694e53b..4064caafd 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasAlreadyNamed.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasAlreadyNamed.cs @@ -36,19 +36,13 @@ public void ThenNamedAgain(Language language) var municipalityWasNamed = new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language)); - ((ISetProvenance)municipalityWasNamed).SetProvenance(Fixture.Create()); + municipalityWasNamed.SetProvenance(Fixture.Create()); Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - municipalityWasNamed - }) + .Given(_streamId, + Fixture.Create(), municipalityWasNamed) .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName(string.Empty, language))) - })); + .Then(new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName(string.Empty, language))))); } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs index 8ccc5d387..101e00d01 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNameToClearedMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs @@ -24,7 +24,6 @@ public GivenMunicipalityWasNotAlreadyNamed(ITestOutputHelper testOutputHelper) : _streamId = Fixture.Create(); } - [Theory] [InlineData(Language.Dutch)] [InlineData(Language.French)] @@ -34,15 +33,10 @@ public void ThenMunicipalityGetsNamed(Language language) { var commandNameMunicipality = Fixture.Create().WithLanguage(language); Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) + .Given(_streamId, + Fixture.Create()) .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName(string.Empty, language))) - })); + .Then(new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName(string.Empty, language))))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNisCode/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNisCode/GivenMunicipality.cs index a3240cb90..438f560ed 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNisCode/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingNisCode/GivenMunicipality.cs @@ -13,41 +13,25 @@ public class GivenMunicipality : StreetNameRegistryTest { - private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; public GivenMunicipality(ITestOutputHelper output) : base(output) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); _streamId = Fixture.Create(); } [Fact] public void ThenMunicipalityNisCodeWasChanged() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, Fixture.Create()) .When(command) - .Then(new[] - { - new Fact(_streamId, new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)) - })); - } - } - - public static class CorrectMunicipalityNisCodeExtensions - { - public static CorrectMunicipalityNisCode WithMunicipalityId( - this CorrectMunicipalityNisCode command, - MunicipalityId municipalityId) - { - return new CorrectMunicipalityNisCode(municipalityId, command.NisCode, command.Provenance); + .Then(new Fact(_streamId, new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingRetirementStreetName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingRetirementStreetName/GivenMunicipality.cs index f51b48cc8..440687a47 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingRetirementStreetName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingRetirementStreetName/GivenMunicipality.cs @@ -5,14 +5,14 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingRetirementStreet using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; + using Extensions; using FluentAssertions; using global::AutoFixture; using Municipality; using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; - using Extensions; using Testing; using Xunit; using Xunit.Abstractions; @@ -48,14 +48,13 @@ public void ThenStreetNameRetirementWasCorrected() } [Fact] - public void WithExistingStreetName_ThenStreetNameNameAlreadyExistsExceptionWasThrown() + public void WithExistingStreetName_ThenThrowsStreetNameNameAlreadyExistsException() { var streetNameName = Fixture.Create(); Fixture.Register(() => new Names { streetNameName }); Fixture.Register(() => new PersistentLocalId(2)); - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, @@ -68,10 +67,9 @@ public void WithExistingStreetName_ThenStreetNameNameAlreadyExistsExceptionWasTh } [Fact] - public void ThenStreetNameNotFoundExceptionWasThrown() + public void WithStreetNameNotFound_ThenThrowsStreetNameNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); @@ -83,34 +81,16 @@ public void ThenStreetNameNotFoundExceptionWasThrown() } [Fact] - public void ThenStreetNameIsRemovedExceptionWasThrown() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var removedStreetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var removedStreetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -129,27 +109,11 @@ public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExcept .WithMunicipalityId(_municipalityId); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithMunicipalityId(_municipalityId) + .WithStatus(StreetNameStatus.Proposed) + .WithPrimaryLanguage(Language.Dutch) + .Build(); // Act, assert Assert(new Scenario() @@ -170,27 +134,11 @@ public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus st .WithMunicipalityId(_municipalityId); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithMunicipalityId(_municipalityId) + .WithStatus(status) + .WithPrimaryLanguage(Language.Dutch) + .Build(); // Act, assert Assert(new Scenario() @@ -209,26 +157,11 @@ public void WithCurrentStreetName_ThenNone() .WithMunicipalityId(_municipalityId); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithMunicipalityId(_municipalityId) + .WithStatus(StreetNameStatus.Current) + .WithPrimaryLanguage(Language.Dutch) + .Build(); // Act, assert Assert(new Scenario() @@ -253,7 +186,7 @@ public void ThenStreetNameStatusIsRetired() Fixture.Create(), Fixture.Create() }); - + // Act aggregate.CorrectStreetNameRetirement(persistentLocalId); diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameApproval/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameApproval/GivenMunicipality.cs index 42ef69f10..2ddc754f7 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameApproval/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameApproval/GivenMunicipality.cs @@ -5,7 +5,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingStreetNameApprov using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; @@ -47,31 +47,13 @@ public void ThenStreetNameApprovalWasCorrectedToProposed() } [Fact] - public void OnRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() + public void WithRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Proposed) + .Build(); // Act, assert Assert(new Scenario() @@ -96,31 +78,14 @@ public void WithoutProposedStreetName_ThenThrowsStreetNameIsNotFoundException() } [Fact] - public void OnRemovedStreetName_ThenThrowsStreetNameIsRemovedException() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -135,31 +100,13 @@ public void OnRemovedStreetName_ThenThrowsStreetNameIsRemovedException() [Theory] [InlineData(StreetNameStatus.Rejected)] [InlineData(StreetNameStatus.Retired)] - public void OnStreetNameWithInvalidStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -176,26 +123,9 @@ public void WithStreetNameAlreadyProposed_ThenNone() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Proposed) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs index 55c536706..258a2a5e2 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameName/GivenMunicipality.cs @@ -18,6 +18,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingStreetNameName using Xunit; using Xunit.Abstractions; using Be.Vlaanderen.Basisregisters.GrAr.Legacy; + using Builders; public sealed class GivenMunicipality : StreetNameRegistryTest { @@ -38,24 +39,24 @@ public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHe [Fact] public void ThenStreetNameNameWasCorrected() { - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - dutchLanguageWasAdded.SetProvenance(Fixture.Create()); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - frenchLanguageWasAdded.SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); var streetNameWasProposed = new StreetNameWasProposedV2( _municipalityId, new NisCode("1011"), - new Names(new List() + new Names(new List { - new StreetNameName("Kaplestraat", Language.Dutch), - new StreetNameName("Rue d'la Croix - Rouge", Language.French), + new("Kaplestraat", Language.Dutch), + new("Rue d'la Croix - Rouge", Language.French), }), Fixture.Create()); streetNameWasProposed.SetProvenance(Fixture.Create()); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(new StreetNameName("Kapelstraat", Language.Dutch)) .WithStreetNameName(new StreetNameName("Rue de la Croix - Rouge", Language.French)); @@ -70,33 +71,31 @@ public void ThenStreetNameNameWasCorrected() streetNameWasProposed) .When(command) .Then(new Fact(_streamId, new StreetNameNamesWereCorrected(_municipalityId, - command.PersistentLocalId, command.StreetNameNames)) + command.PersistentLocalId, command.StreetNameNames)) )); } [Fact] - public void WhenCorrectionExceedsLevenshteinThreshold_ThrowException() + public void WithACorrectionThatExceedsLevenshteinThreshold_ThenThrowsStreetNameNameCorrectionExceededCharacterChangeLimitException() { var originalName = "0123546789"; var correctedName = "012354----"; - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - dutchLanguageWasAdded.SetProvenance(Fixture.Create()); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - frenchLanguageWasAdded.SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposed = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("1011"), - new Names(new List() + var streetNameWasProposed = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("1011")) + .WithNames(new Names(new List { - new StreetNameName(originalName, Language.Dutch) - }), - Fixture.Create()); - streetNameWasProposed.SetProvenance(Fixture.Create()); + new(originalName, Language.Dutch) + })) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(new StreetNameName(correctedName, Language.Dutch)); @@ -113,30 +112,29 @@ public void WhenCorrectionExceedsLevenshteinThreshold_ThrowException() } [Fact] - public void WhenCorrectionExactly30Percent_ThenStreetNameWasCorrected() + public void WithACorrectionExactly30Percent_ThenStreetNameWasCorrected() { var originalName = "0123456789"; var correctedName = "0123456---"; - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - dutchLanguageWasAdded.SetProvenance(Fixture.Create()); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - frenchLanguageWasAdded.SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposed = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("1011"), - new Names(new List() + var streetNameWasProposed = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("1011")) + .WithNames(new Names(new List { - new StreetNameName(originalName, Language.Dutch) - }), - Fixture.Create()); - streetNameWasProposed.SetProvenance(Fixture.Create()); + new(originalName, Language.Dutch) + })) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(new StreetNameName(correctedName, Language.Dutch)); + // Act, assert Assert(new Scenario() .Given(_streamId, @@ -147,15 +145,14 @@ public void WhenCorrectionExactly30Percent_ThenStreetNameWasCorrected() streetNameWasProposed) .When(command) .Then(new Fact(_streamId, new StreetNameNamesWereCorrected(_municipalityId, - command.PersistentLocalId, command.StreetNameNames)) + command.PersistentLocalId, command.StreetNameNames)) )); } [Fact] - public void ThenThrowsStreetNameNotFoundException() + public void WithStreetNameNotFound_ThenThrowsStreetNameNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); @@ -167,34 +164,16 @@ public void ThenThrowsStreetNameNotFoundException() } [Fact] - public void ThenThrowsStreetNameIsRemovedException() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var removedStreetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: true); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var removedStreetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -209,33 +188,14 @@ public void ThenThrowsStreetNameIsRemovedException() [Theory] [InlineData(StreetNameStatus.Retired)] [InlineData(StreetNameStatus.Rejected)] - public void ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -252,18 +212,16 @@ public void WithDuplicateNameAndRejectedStatus_ThenThrowsStreetNameHasInvalidSta { var streetNameNames = new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameName(streetNameNames.First()); - var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance) languageWasAdded).SetProvenance(Fixture.Create()); + var languageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - new PersistentLocalId(command.PersistentLocalId + 1)); - ((ISetProvenance) streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode(new NisCode("abc")) + .WithNames(streetNameNames) + .WithPersistentLocalId(new PersistentLocalId(command.PersistentLocalId + 1)) + .Build(); // Act, assert Assert(new Scenario() @@ -284,19 +242,17 @@ public void WithStreetNameNameAlreadyInUse_ThenThrowsStreetNameNameAlreadyExists var streetNameNames = new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }); var command = Fixture.Create() .WithPersistentLocalId(new PersistentLocalId(123)) - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(streetNameNames.First()); - var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance) languageWasAdded).SetProvenance(Fixture.Create()); + var languageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - new PersistentLocalId(456)); - ((ISetProvenance) streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode("abc") + .WithNames(streetNameNames) + .WithPersistentLocalId(456) + .Build(); // Act, assert Assert(new Scenario() @@ -321,11 +277,11 @@ public void WithInvalidLanguage_ThenThrowsStreetNameNameLanguageNotSupportedExce }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(streetNameNames); - var languageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance) languageWasAdded).SetProvenance(Fixture.Create()); + var languageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); // Act, assert Assert(new Scenario() @@ -349,21 +305,19 @@ public void WithNoChanges_ThenNothing() }); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(streetNameNames); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance) dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance) frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - Fixture.Create()); - ((ISetProvenance) streetNameWasProposedV2).SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode("abc") + .WithNames(streetNameNames) + .Build(); // Act, assert Assert(new Scenario() @@ -386,21 +340,19 @@ public void WithOneChange_ThenOnlyOneStreetNameNameWasChanged() new StreetNameName("Rue d'la Chapelle", Language.French) }); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - dutchLanguageWasAdded.SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - frenchLanguageWasAdded.SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); - var streetNameWasProposedV2 = new StreetNameWasProposedV2( - _municipalityId, - new NisCode("abc"), - streetNameNames, - Fixture.Create()); - streetNameWasProposedV2.SetProvenance(Fixture.Create()); + var streetNameWasProposedV2 = new StreetNameWasProposedV2Builder(Fixture) + .WithNisCode("abc") + .WithNames(streetNameNames) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names()) .WithStreetNameName(streetNameNames.First()) .WithStreetNameName(new StreetNameName("Rue de la Chapelle", Language.French)); @@ -431,56 +383,25 @@ public void WithConflictingHomonymAdditions_ThenStreetNameNameAlreadyExistsExcep Fixture.Register(() => Language.Dutch); Fixture.Register(() => Taal.NL); + var homonymAdditions = !string.IsNullOrEmpty(homonymAddition) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) + : new HomonymAdditions(); + var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameAWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - !string.IsNullOrEmpty(homonymAddition) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - - var streetNameBWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) }), - !string.IsNullOrEmpty(homonymAddition) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAddition, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameAWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithHomonymAdditions(homonymAdditions) + .Build(); + + var streetNameBWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithPersistentLocalId(456) + .WithHomonymAdditions(homonymAdditions) + .WithNames(new Names(new[] { new StreetNameName("Kapelstraat", Language.Dutch) })) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameName(Fixture.Create().First()) .WithPersistentLocalId(new PersistentLocalId(streetNameBWasMigrated.PersistentLocalId)); @@ -505,56 +426,29 @@ public void WithDifferentHomonymAdditions_ThenStreetNameNamesWereCorrected(strin Fixture.Register(() => Language.Dutch); Fixture.Register(() => Taal.NL); + var homonymAdditionsA = !string.IsNullOrEmpty(homonymAdditionA) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionA, Language.Dutch) }) + : new HomonymAdditions(); + + var homonymAdditionsB = !string.IsNullOrEmpty(homonymAdditionB) + ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionB, Language.Dutch) }) + : new HomonymAdditions(); + var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameAWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - !string.IsNullOrEmpty(homonymAdditionA) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionA, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - - var streetNameBWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names(new[] { new StreetNameName("Kaplestraat", Language.Dutch) }), - !string.IsNullOrEmpty(homonymAdditionB) - ? new HomonymAdditions(new[] { new StreetNameHomonymAddition(homonymAdditionB, Language.Dutch) }) - : new HomonymAdditions(), - true, - false); - - ((ISetProvenance) streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameAWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(123) + .WithStatus(StreetNameStatus.Current) + .WithHomonymAdditions(homonymAdditionsA) + .Build(); + + var streetNameBWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(456) + .WithNames(new Names(new[] { new StreetNameName("Kaplestraat", Language.Dutch) })) + .WithHomonymAdditions(homonymAdditionsB) + .Build(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameName(new StreetNameName("kapelstraat", Language.Dutch)) .WithPersistentLocalId(new PersistentLocalId(streetNameBWasMigrated.PersistentLocalId)); @@ -580,11 +474,12 @@ public void StateCheck() var persistentLocalId = Fixture.Create(); var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.Dutch); - ((ISetProvenance) dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(_municipalityId, Language.French); - ((ISetProvenance) frenchLanguageWasAdded).SetProvenance(Fixture.Create()); + var frenchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .WithLanguage(Language.French) + .Build(); aggregate.Initialize(new List { diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameRejection/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameRejection/GivenMunicipality.cs index 4c1172675..1dfdc2f05 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameRejection/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenCorrectingStreetNameRejection/GivenMunicipality.cs @@ -6,6 +6,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenCorrectingStreetNameReject using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; @@ -47,30 +48,13 @@ public void ThenStreetNameRejectionWasCorrectedProposed() } [Fact] - public void OnRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() + public void WithRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Rejected, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Rejected) + .Build(); // Act, assert Assert(new Scenario() @@ -95,30 +79,14 @@ public void WithoutProposedStreetName_ThenThrowsStreetNameIsNotFoundException() } [Fact] - public void OnRemovedStreetName_ThenThrowsStreetNameIsRemovedException() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Rejected, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Rejected) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -133,30 +101,13 @@ public void OnRemovedStreetName_ThenThrowsStreetNameIsRemovedException() [Theory] [InlineData(StreetNameStatus.Current)] [InlineData(StreetNameStatus.Retired)] - public void OnStreetNameWithInvalidStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -169,7 +120,7 @@ public void OnStreetNameWithInvalidStatus_ThenThrowsStreetNameHasInvalidStatusEx } [Fact] - public void WithActiveExistingStreetName_ThenStreetNameNameAlreadyExistsExceptionWasThrown() + public void WithActiveExistingStreetName_ThenThrowsStreetNameNameAlreadyExistsException() { var streetNameName = Fixture.Create(); Fixture.Register(() => new Names { streetNameName }); @@ -188,30 +139,13 @@ public void WithActiveExistingStreetName_ThenStreetNameNameAlreadyExistsExceptio } [Fact] - public void WithStreetNameAlreadyProposed_ThenNone() + public void WithAlreadyProposedStreetName_ThenNone() { var command = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - isCompleted: true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Proposed) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenDefiningNisCode/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenDefiningNisCode/GivenMunicipality.cs index a70250ee9..91a1a2c00 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenDefiningNisCode/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenDefiningNisCode/GivenMunicipality.cs @@ -34,10 +34,7 @@ public void ThenMunicipalityNisCodeWasChanged() .Given(_streamId, Fixture.Create()) .When(command) - .Then(new[] - { - new Fact(_streamId, new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)) - })); + .Then(new Fact(_streamId, new MunicipalityNisCodeWasChanged(command.MunicipalityId, command.NisCode)))); } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenMunicipalityAlreadyExists.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenMunicipalityAlreadyExists.cs index 6ddbf1178..8ed804088 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenMunicipalityAlreadyExists.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenMunicipalityAlreadyExists.cs @@ -28,10 +28,7 @@ public void ThenMunicipalityAlreadyExists() var command = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create() - }) + .Given(_streamId, Fixture.Create()) .When(command) .Throws(new AggregateSourceException($"Municipality with id {command.MunicipalityId} already exists"))); } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenNoMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenNoMunicipality.cs index b511ec159..be2f72be3 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenNoMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenImportingMunicipality/GivenNoMunicipality.cs @@ -26,34 +26,8 @@ public void ThenMunicipalityWasImported() Assert(new Scenario() .GivenNone() .When(command) - .Then(new[] - { - new Fact(new MunicipalityStreamId(command.MunicipalityId), - new MunicipalityWasImported(command.MunicipalityId, command.NisCode)) - })); - } - } - - public static class ImportMunicipalityExtensions - { - public static ImportMunicipality WithMunicipalityId( - this ImportMunicipality command, - MunicipalityId municipalityId) - { - return new ImportMunicipality( - municipalityId, - new NisCode(command.NisCode), - command.Provenance); - } - - public static ImportMunicipality WithNisCode( - this ImportMunicipality command, - NisCode nisCode) - { - return new ImportMunicipality( - new MunicipalityId(command.MunicipalityId), - nisCode, - command.Provenance); + .Then(new Fact(new MunicipalityStreamId(command.MunicipalityId), + new MunicipalityWasImported(command.MunicipalityId, command.NisCode)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipality.cs similarity index 56% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasAlreadyNamed.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipality.cs index 88c1aae81..65cd01f91 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasAlreadyNamed.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipality.cs @@ -11,12 +11,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenNamingMunicipality using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityWasAlreadyNamed : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityWasAlreadyNamed(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -29,20 +29,27 @@ public GivenMunicipalityWasAlreadyNamed(ITestOutputHelper testOutputHelper) : ba [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void ThenNamedAgain(Language language) + public void ThenMunicipalityGetsNamed(Language language) { var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - Fixture.Create() - }) + .Given(_streamId, Fixture.Create()) .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))) - })); + .Then(new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))))); + } + + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithTheSameMunicipalityName_ThenMunicipalityWasNamed(Language language) + { + var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); + Assert(new Scenario() + .Given(_streamId, Fixture.Create(), Fixture.Create()) + .When(commandNameMunicipality) + .Then(new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))))); } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs deleted file mode 100644 index 2808e7877..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenNamingMunicipality/GivenMunicipalityWasNotAlreadyNamed.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenNamingMunicipality -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityWasNotAlreadyNamed : StreetNameRegistryTest - { - private readonly MunicipalityId _municipalityId; - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityWasNotAlreadyNamed(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); - _streamId = Fixture.Create(); - } - - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenMunicipalityGetsNamed(Language language) - { - var commandNameMunicipality = Fixture.Create().WithName("GreatName", language); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandNameMunicipality) - .Then(new[] - { - new Fact(_streamId, new MunicipalityWasNamed(_municipalityId, new MunicipalityName("GreatName", language))) - })); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenProposingStreetName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenProposingStreetName/GivenMunicipality.cs index 32d1ec63d..9983f3a23 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenProposingStreetName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenProposingStreetName/GivenMunicipality.cs @@ -5,13 +5,13 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenProposingStreetName using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; using Be.Vlaanderen.Basisregisters.GrAr.Legacy; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; + using Extensions; using global::AutoFixture; using Municipality; using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; - using Extensions; using Testing; using Xunit; using Xunit.Abstractions; @@ -47,27 +47,25 @@ public void ThenStreetNameWasProposed() Assert(new Scenario() .Given(_streamId, municipalityWasImported, municipalityOfficialLanguageWasAdded) .When(command) - .Then(new[] - { - new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)) - })); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, + command.PersistentLocalId)))); } [Theory] [InlineData("Bremstraat", "Bremstraat")] [InlineData("Bremstraat", "bremstraat")] - public void WithExistingStreetName_ThenStreetNameNameAlreadyExistsExceptionWasThrown(string name, string newName) + public void WithExistingStreetNameName_ThenThrowsStreetNameNameAlreadyExistsException(string name, string newName) { var municipalityWasImported = Fixture.Create(); - var municipalityOfficialLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(Fixture.Create(), Language.Dutch); - municipalityOfficialLanguageWasAdded.SetProvenance(Fixture.Create()); + var municipalityOfficialLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); var streetNameWasProposed = Fixture.Create() - .WithNames(new Names(new List{ new StreetNameName(name, Language.Dutch) })); + .WithNames(new Names(new List { new(name, Language.Dutch) })); var command = Fixture.Create() - .WithStreetNameNames(new Names(new List{ new StreetNameName(newName, Language.Dutch) })) - .WithMunicipalityId(_municipalityId); + .WithStreetNameNames(new Names(new List { new(newName, Language.Dutch) })); Assert(new Scenario() .Given(_streamId, @@ -85,7 +83,6 @@ public void WithExistingPersistentLocalId_ThenThrowsStreetNamePersistentLocalIdA var streetNameWasProposed = Fixture.Create(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithPersistentLocalId(new PersistentLocalId(streetNameWasProposed.PersistentLocalId)); Assert(new Scenario() @@ -109,8 +106,7 @@ public void WithExistingRetiredStreetName_ThenStreetNameWasProposed() var municipalityOfficialLanguageWasAdded = Fixture.Create(); var streetNameWasMigrated = Fixture.Create(); - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, @@ -118,7 +114,9 @@ public void WithExistingRetiredStreetName_ThenStreetNameWasProposed() municipalityOfficialLanguageWasAdded, streetNameWasMigrated) .When(command) - .Then(new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)))); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, + command.PersistentLocalId)))); } [Fact] @@ -134,8 +132,7 @@ public void WithExistingRejectedStreetName_ThenStreetNameWasProposed() var municipalityOfficialLanguageWasAdded = Fixture.Create(); var streetNameWasMigrated = Fixture.Create(); - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, @@ -143,7 +140,9 @@ public void WithExistingRejectedStreetName_ThenStreetNameWasProposed() municipalityOfficialLanguageWasAdded, streetNameWasMigrated) .When(command) - .Then(new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)))); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, + command.PersistentLocalId)))); } [Fact] @@ -156,26 +155,10 @@ public void WithExistingRemovedStreetName_ThenStreetNameWasProposed() var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); var command = Fixture.Create() .WithMunicipalityId(_municipalityId); @@ -186,11 +169,13 @@ public void WithExistingRemovedStreetName_ThenStreetNameWasProposed() municipalityOfficialLanguageWasAdded, streetNameWasMigrated) .When(command) - .Then(new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)))); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, + command.PersistentLocalId)))); } [Fact] - public void WithOneExistingStreetNameAndOneNew_ThenStreetNameNameAlreadyExistsExceptionWasThrown() + public void WithOneExistingStreetNameAndOneNew_ThenThrowsStreetNameNameAlreadyExistsException() { var existingStreetNameName = Fixture.Create(); var newStreetNameName = Fixture.Create(); @@ -200,7 +185,6 @@ public void WithOneExistingStreetNameAndOneNew_ThenStreetNameNameAlreadyExistsEx var streetNameWasProposed = Fixture.Create(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names { existingStreetNameName, newStreetNameName }); Assert(new Scenario() @@ -226,7 +210,6 @@ public void WithNoConflictingStreetNames_ThenStreetNameWasProposed() var municipalityOfficialLanguageWasAdded = Fixture.Create(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(new Names { newStreetNameName }); Assert(new Scenario() @@ -235,20 +218,21 @@ public void WithNoConflictingStreetNames_ThenStreetNameWasProposed() municipalityOfficialLanguageWasAdded, streetNameWasProposed) .When(command) - .Then(new[] - { - new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)) - })); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2( + _municipalityId, + new NisCode(municipalityWasImported.NisCode), + command.StreetNameNames, + command.PersistentLocalId)))); } [Fact] - public void WithMunicipalityRetired_ThenMunicipalityHasInvalidStatusExceptionWasThrown() + public void WithMunicipalityRetired_ThenThrowsMunicipalityHasInvalidStatusException() { var municipalityWasImported = Fixture.Create(); var municipalityWasRetired = Fixture.Create(); var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithRandomStreetName(Fixture); Assert(new Scenario() @@ -260,7 +244,7 @@ public void WithMunicipalityRetired_ThenMunicipalityHasInvalidStatusExceptionWas } [Fact] - public void WithOfficialLanguageDutchAndProposedLanguageIsFrench_ThenStreetNameNameLanguageNotSupportedExceptionWasThrown() + public void WithOfficialLanguageDutchAndProposedLanguageIsFrench_ThenThrowsStreetNameNameLanguageNotSupportedException() { Fixture.Register(() => Language.Dutch); var municipalityWasImported = Fixture.Create(); @@ -268,11 +252,10 @@ public void WithOfficialLanguageDutchAndProposedLanguageIsFrench_ThenStreetNameN var names = new Names { - new StreetNameName(Fixture.Create(), Language.French) + new(Fixture.Create(), Language.French) }; var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(names); Assert(new Scenario() @@ -280,11 +263,12 @@ public void WithOfficialLanguageDutchAndProposedLanguageIsFrench_ThenStreetNameN municipalityWasImported, municipalityOfficialLanguageWasAdded) .When(command) - .Throws(new StreetNameNameLanguageIsNotSupportedException($"The language '{Language.French}' is not an official or facility language of municipality '{_municipalityId}'."))); + .Throws(new StreetNameNameLanguageIsNotSupportedException( + $"The language '{Language.French}' is not an official or facility language of municipality '{_municipalityId}'."))); } [Fact] - public void WithFacilityLanguageFrenchAndProposedLanguageIsDutch_ThenStreetNameNameLanguageNotSupportedExceptionWasThrown() + public void WithFacilityLanguageFrenchAndProposedLanguageIsDutch_ThenThrowsStreetNameNameLanguageNotSupportedException() { Fixture.Register(() => Language.French); var municipalityWasImported = Fixture.Create(); @@ -292,11 +276,10 @@ public void WithFacilityLanguageFrenchAndProposedLanguageIsDutch_ThenStreetNameN var names = new Names { - new StreetNameName(Fixture.Create(), Language.Dutch) + new(Fixture.Create(), Language.Dutch) }; var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(names); Assert(new Scenario() @@ -304,11 +287,13 @@ public void WithFacilityLanguageFrenchAndProposedLanguageIsDutch_ThenStreetNameN municipalityWasImported, municipalityFacilityLanguageWasAdded) .When(command) - .Throws(new StreetNameNameLanguageIsNotSupportedException($"The language '{Language.Dutch}' is not an official or facility language of municipality '{_municipalityId}'."))); + .Throws(new StreetNameNameLanguageIsNotSupportedException( + $"The language '{Language.Dutch}' is not an official or facility language of municipality '{_municipalityId}'."))); } [Fact] - public void WithOfficialLanguageDutchAndFacilityLanguageFrenchAndProposedLanguageIsFrench_ThenStreetNameNameLanguageNotSupportedExceptionWasThrown() + public void + WithOfficialLanguageDutchAndFacilityLanguageFrenchAndProposedLanguageIsFrench_ThenThrowsStreetNameNameLanguageNotSupportedException() { Fixture.Register(() => Language.Dutch); var municipalityWasImported = Fixture.Create(); @@ -318,11 +303,10 @@ public void WithOfficialLanguageDutchAndFacilityLanguageFrenchAndProposedLanguag var names = new Names { - new StreetNameName(Fixture.Create(), Language.French) + new(Fixture.Create(), Language.French) }; var command = Fixture.Create() - .WithMunicipalityId(_municipalityId) .WithStreetNameNames(names); Assert(new Scenario() @@ -335,7 +319,7 @@ public void WithOfficialLanguageDutchAndFacilityLanguageFrenchAndProposedLanguag } [Fact] - public void WithExistingStreetNameAndNoHomonymAdditions_ThenStreetNameNameAlreadyExistsExceptionWasThrown() + public void WithExistingStreetNameAndNoHomonymAdditions_ThenThrowsStreetNameNameAlreadyExistsException() { var streetNameName = Fixture.Create(); Fixture.Register(() => new Names { streetNameName }); @@ -344,26 +328,9 @@ public void WithExistingStreetNameAndNoHomonymAdditions_ThenStreetNameNameAlread var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .Build(); var command = Fixture.Create() .WithMunicipalityId(_municipalityId); @@ -387,29 +354,12 @@ public void WithExistingStreetNameAndHomonymAdditions_ThenStreetNameWasProposed( var municipalityWasImported = Fixture.Create(); var municipalityOfficialLanguageWasAdded = Fixture.Create(); - var streetNameWasMigrated = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(){new StreetNameHomonymAddition("test", Language.Dutch)}, - true, - false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameWasMigrated = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithHomonymAdditions(new HomonymAdditions() { new("test", Language.Dutch) }) + .Build(); - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, @@ -417,7 +367,9 @@ public void WithExistingStreetNameAndHomonymAdditions_ThenStreetNameWasProposed( municipalityOfficialLanguageWasAdded, streetNameWasMigrated) .When(command) - .Then(new Fact(_streamId, new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, command.PersistentLocalId)))); + .Then(new Fact(_streamId, + new StreetNameWasProposedV2(_municipalityId, new NisCode(municipalityWasImported.NisCode), command.StreetNameNames, + command.PersistentLocalId)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRejectingStreetName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRejectingStreetName/GivenMunicipality.cs index cc4ec2c8c..830d1b092 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRejectingStreetName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRejectingStreetName/GivenMunicipality.cs @@ -5,14 +5,13 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRejectingStreetName using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; - using Extensions; using Testing; using Xunit; using Xunit.Abstractions; @@ -34,8 +33,7 @@ public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHe [Fact] public void ThenStreetNameWasRejected() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); // Act, assert Assert(new Scenario() @@ -48,10 +46,9 @@ public void ThenStreetNameWasRejected() } [Fact] - public void ThenStreetNameNotFoundExceptionWasThrown() + public void WithNoStreetName_ThenThrowsStreetNameNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); @@ -63,34 +60,16 @@ public void ThenStreetNameNotFoundExceptionWasThrown() } [Fact] - public void ThenStreetNameIsRemovedExceptionWasThrown() + public void WithRemovedStreetName_ThenThrowsStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var removedStreetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var removedStreetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -103,33 +82,14 @@ public void ThenStreetNameIsRemovedExceptionWasThrown() } [Fact] - public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExceptionWasThrown() + public void WithRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Proposed) + .Build(); // Act, assert Assert(new Scenario() @@ -144,33 +104,14 @@ public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExcept [Theory] [InlineData(StreetNameStatus.Current)] [InlineData(StreetNameStatus.Retired)] - public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -185,30 +126,12 @@ public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus st [Fact] public void WithStreetNameAlreadyRejected_ThenNone() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Rejected, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Rejected) + .Build(); // Act, assert Assert(new Scenario() @@ -221,7 +144,7 @@ public void WithStreetNameAlreadyRejected_ThenNone() } [Fact] - public void ThenStreetNameStatusIsRejected() + public void StateCheck() { var persistentLocalId = Fixture.Create(); var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetName.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetName.cs index cd3e2ed75..1d03d2180 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetName.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetName.cs @@ -6,6 +6,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingHomonymAdditions using Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using FluentAssertions; using global::AutoFixture; using Municipality; @@ -38,27 +39,20 @@ public void WithSameLanguage_ThenStreetNameHomonymAdditionsWereRemoved() new List() { Language.Dutch }, Fixture.Create()); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] - { - new StreetNameHomonymAddition("ABC", Language.Dutch), - new StreetNameHomonymAddition("QRS", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions( + new HomonymAdditions(new[] + { + new StreetNameHomonymAddition("ABC", Language.Dutch), + new StreetNameHomonymAddition("QRS", Language.French), + })) + .Build(); // Act, assert Assert(new Scenario() @@ -70,38 +64,28 @@ public void WithSameLanguage_ThenStreetNameHomonymAdditionsWereRemoved() .Then(new Fact(_streamId, new StreetNameHomonymAdditionsWereRemoved( Fixture.Create(), command.PersistentLocalId, - new List(){ Language.Dutch })))); + new List() { Language.Dutch })))); } [Fact] public void WithNoMatchingLanguage_ThenNone() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions(), - new List() { Language.Dutch }, - Fixture.Create()); + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditionsToRemove(new List { Language.Dutch }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names - { - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameHomonymAddition("QRS", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions( + new HomonymAdditions(new[] + { + new StreetNameHomonymAddition("QRS", Language.French), + })) + .Build(); // Act, assert Assert(new Scenario() @@ -116,34 +100,23 @@ public void WithNoMatchingLanguage_ThenNone() [Theory] [InlineData(StreetNameStatus.Current)] [InlineData(StreetNameStatus.Proposed)] - public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrectedEvent(StreetNameStatus status) + public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrected(StreetNameStatus status) { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions(), - new List() { Language.Dutch }, - Fixture.Create()); + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditionsToRemove(new List { Language.Dutch }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - new Names + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + }) + .WithHomonymAdditions( new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -155,7 +128,7 @@ public void WithValidStatus_ThenStreetNameHomonymAdditionsCorrectedEvent(StreetN .Then(new Fact(_streamId, new StreetNameHomonymAdditionsWereRemoved( Fixture.Create(), command.PersistentLocalId, - new List() { Language.Dutch })))); + new List { Language.Dutch })))); } [Fact] @@ -163,28 +136,18 @@ public void StateCheck() { var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); - var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(Fixture.Create(), Language.Dutch); - ((ISetProvenance)dutchLanguageWasAdded).SetProvenance(Fixture.Create()); + var dutchLanguageWasAdded = new MunicipalityOfficialLanguageWasAddedBuilder(Fixture) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names { new StreetNameName("Bergstraat", Language.Dutch), }, - new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - - var homonymAdditionsWereRemoved = new StreetNameHomonymAdditionsWereRemoved( - Fixture.Create(), - Fixture.Create(), - new List() { Language.Dutch} ); - ((ISetProvenance)homonymAdditionsWereRemoved).SetProvenance(Fixture.Create()); + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { new StreetNameName("Bergstraat", Language.Dutch), }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), })) + .Build(); + + var homonymAdditionsWereRemoved = new StreetNameHomonymAdditionsWereRemovedBuilder(Fixture) + .WithLanguages(new List { Language.Dutch }) + .Build(); // Act aggregate.Initialize(new List diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameInvalidStatus.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameInvalidStatus.cs index b6797566e..e9672ae27 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameInvalidStatus.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameInvalidStatus.cs @@ -3,10 +3,9 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingHomonymAdditions using System.Collections.Generic; using AutoFixture; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; using Testing; @@ -31,32 +30,22 @@ public GivenStreetNameInvalidStatus(ITestOutputHelper testOutputHelper) : base(t [InlineData(StreetNameStatus.Retired)] public void ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions(), - new List() { Language.Dutch }, - Fixture.Create()); + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditionsToRemove(new List() { Language.Dutch }) + .Build(); - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - new Names - { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(new[] + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .WithNames( + new Names + { + new("Bergstraat", Language.Dutch), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameNameWithHomonymAdditionAlreadyExists.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameNameWithHomonymAdditionAlreadyExists.cs index 51b4e6d5a..e0e721451 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameNameWithHomonymAdditionAlreadyExists.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingHomonymAdditions/GivenStreetNameNameWithHomonymAdditionAlreadyExists.cs @@ -4,10 +4,9 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingHomonymAdditions using AutoFixture; using Be.Vlaanderen.Basisregisters.AggregateSource; using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using Builders; using global::AutoFixture; using Municipality; - using Municipality.Commands; using Municipality.Events; using Municipality.Exceptions; using Testing; @@ -28,51 +27,34 @@ public GivenStreetNameNameWithHomonymAdditionAlreadyExists(ITestOutputHelper tes } [Fact] - public void ThenStreetNameNameAlreadyExistsException() + public void ThenThrowsStreetNameNameAlreadyExistsException() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - new PersistentLocalId(123), - new HomonymAdditions(), - new List() { Language.Dutch }, - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(123), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithPersistentLocalId(123) + .WithHomonymAdditionsToRemove(new List { Language.Dutch }) + .Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(123) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - - var secondStreetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - new PersistentLocalId(456), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + })) + .Build(); + + var secondStreetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithPersistentLocalId(456) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - }, - new HomonymAdditions(), - true, - false); - ((ISetProvenance)secondStreetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + new("Bergstraat", Language.Dutch), + }) + .Build(); // Act, assert Assert(new Scenario() @@ -88,32 +70,20 @@ public void ThenStreetNameNameAlreadyExistsException() [Fact] public void WithNoMatchingLanguage_ThenNone() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions(), - new List() { Language.Dutch }, - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("QRS", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -128,38 +98,25 @@ public void WithNoMatchingLanguage_ThenNone() [Fact] public void WithOneDifferentAndOneSameAddition_ThenOnlyOneAdditionWasCorrected() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch), - new StreetNameHomonymAddition("SameFrenchAddition", Language.French), - }, - new List(), - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + new("DEF", Language.Dutch), + new("SameFrenchAddition", Language.French), + }).Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }).WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("SameFrenchAddition", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() @@ -173,45 +130,34 @@ public void WithOneDifferentAndOneSameAddition_ThenOnlyOneAdditionWasCorrected() command.PersistentLocalId, new HomonymAdditions { - new StreetNameHomonymAddition("DEF", Language.Dutch) + new("DEF", Language.Dutch) })))); } [Fact] public void WithNoCorrections_ThenNone() { - var command = new CorrectStreetNameHomonymAdditions( - Fixture.Create(), - Fixture.Create(), - new HomonymAdditions + var command = new CorrectStreetNameHomonymAdditionsBuilder(Fixture) + .WithHomonymAdditions(new HomonymAdditions { - new StreetNameHomonymAddition("ABC", Language.Dutch), - new StreetNameHomonymAddition("DEF", Language.French), - }, - new List(), - Fixture.Create()); - - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - new Names + new("ABC", Language.Dutch), + new("DEF", Language.French), + }) + .Build(); + + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithNames(new Names { - new StreetNameName("Bergstraat", Language.Dutch), - new StreetNameName("Rue De Montaigne", Language.French), - }, - new HomonymAdditions(new[] + new("Bergstraat", Language.Dutch), + new("Rue De Montaigne", Language.French), + }) + .WithHomonymAdditions(new HomonymAdditions(new[] { new StreetNameHomonymAddition("ABC", Language.Dutch), new StreetNameHomonymAddition("DEF", Language.French), - }), - true, - false); - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); + })) + .Build(); // Act, assert Assert(new Scenario() diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasALanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipality.cs similarity index 78% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasALanguage.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipality.cs index ae822e745..47a8e74a2 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasALanguage.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipality.cs @@ -12,12 +12,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingMunicipalityFacili using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityHasAFacilityLanguage : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityHasAFacilityLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -45,7 +45,7 @@ public void ThenFacilityLanguageWasRemoved(Language language) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void AndWasRemoved_ThenNone(Language language) + public void WithAlreadyRemovedLanguage_ThenNone(Language language) { Fixture.Register(() => language); var commandLanguageRemoved = Fixture.Create(); @@ -55,6 +55,21 @@ public void AndWasRemoved_ThenNone(Language language) .ThenNone()); } + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithNonExistingLanguage_ThenNone(Language language) + { + Fixture.Register(() => language); + var commandLanguageRemoved = Fixture.Create(); + Assert(new Scenario() + .Given(_streamId, Fixture.Create()) + .When(commandLanguageRemoved) + .ThenNone()); + } + [Fact] public void AndHasMultipleLanguages_TheCorrectOneWasRemoved() { diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs deleted file mode 100644 index 7e06c4026..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityFacilityLanguage/GivenMunicipalityHasNoFacilityLanguage.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingMunicipalityFacilityLanguage -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityHasNoFacilityLanguage : StreetNameRegistryTest - { - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityHasNoFacilityLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _streamId = Fixture.Create(); - } - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenNone(Language language) - { - Fixture.Register(() => language); - var commandLanguageRemoved = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandLanguageRemoved) - .ThenNone()); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasALanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipality.cs similarity index 69% rename from test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasALanguage.cs rename to test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipality.cs index 3f4bd56fa..dcf308683 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasALanguage.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipality.cs @@ -12,12 +12,12 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingMunicipalityOffici using Xunit; using Xunit.Abstractions; - public sealed class GivenMunicipalityHasAOfficialLanguage : StreetNameRegistryTest + public sealed class GivenMunicipality : StreetNameRegistryTest { private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; - public GivenMunicipalityHasAOfficialLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); @@ -35,16 +35,11 @@ public void ThenOfficialLanguageWasRemoved(Language language) Fixture.Register(() => language); var commandLanguageRemoved = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), - Fixture.Create() - }) + Fixture.Create()) .When(commandLanguageRemoved) - .Then(new[] - { - new Fact(_streamId, new MunicipalityOfficialLanguageWasRemoved(_municipalityId, language)) - })); + .Then(new Fact(_streamId, new MunicipalityOfficialLanguageWasRemoved(_municipalityId, language)))); } [Theory] @@ -52,17 +47,30 @@ public void ThenOfficialLanguageWasRemoved(Language language) [InlineData(Language.French)] [InlineData(Language.English)] [InlineData(Language.German)] - public void AndWasRemoved_ThenNone(Language language) + public void WithRemovedLanguage_ThenNone(Language language) { Fixture.Register(() => language); var commandLanguageRemoved = Fixture.Create(); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), Fixture.Create(), - Fixture.Create() - }) + Fixture.Create()) + .When(commandLanguageRemoved) + .ThenNone()); + } + + [Theory] + [InlineData(Language.Dutch)] + [InlineData(Language.French)] + [InlineData(Language.English)] + [InlineData(Language.German)] + public void WithNonExistingLanguage_ThenNone(Language language) + { + Fixture.Register(() => language); + var commandLanguageRemoved = Fixture.Create(); + Assert(new Scenario() + .Given(_streamId, Fixture.Create()) .When(commandLanguageRemoved) .ThenNone()); } @@ -74,17 +82,12 @@ public void AndHasMultipleLanguages_TheCorrectOneWasRemoved() var commandAddedEnglish = Fixture.Create().WithLanguage(Language.English); var commandAddedDutch = Fixture.Create().WithLanguage(Language.Dutch); Assert(new Scenario() - .Given(_streamId, new object[] - { + .Given(_streamId, Fixture.Create(), commandAddedEnglish.ToEvent(), - commandAddedDutch.ToEvent() - }) + commandAddedDutch.ToEvent()) .When(commandLanguageRemoved) - .Then(new[] - { - new Fact(_streamId, new MunicipalityOfficialLanguageWasRemoved(_municipalityId, Language.English)) - })); + .Then(new Fact(_streamId, new MunicipalityOfficialLanguageWasRemoved(_municipalityId, Language.English)))); } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasNoFacilityLanguage.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasNoFacilityLanguage.cs deleted file mode 100644 index 05357a3ee..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingMunicipalityOfficialLanguage/GivenMunicipalityHasNoFacilityLanguage.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingMunicipalityOfficialLanguage -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using global::AutoFixture; - using Municipality; - using Municipality.Commands; - using Municipality.Events; - using Testing; - using Xunit; - using Xunit.Abstractions; - - public sealed class GivenMunicipalityHasNoOfficialLanguage : StreetNameRegistryTest - { - private readonly MunicipalityStreamId _streamId; - - public GivenMunicipalityHasNoOfficialLanguage(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new InfrastructureCustomization()); - Fixture.Customize(new WithFixedMunicipalityId()); - _streamId = Fixture.Create(); - } - - [Theory] - [InlineData(Language.Dutch)] - [InlineData(Language.French)] - [InlineData(Language.English)] - [InlineData(Language.German)] - public void ThenNone(Language language) - { - Fixture.Register(() => language); - var commandLanguageRemoved = Fixture.Create(); - Assert(new Scenario() - .Given(_streamId, new object[] - { - Fixture.Create(), - }) - .When(commandLanguageRemoved) - .ThenNone()); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetName.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetName.cs index 6d59cfcd1..f8b4cf913 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetName.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetName.cs @@ -34,5 +34,20 @@ public void ThenStreetNameWasRemovedV2() .Then(new Fact(municipalityStreamId, new StreetNameWasRemovedV2(command.MunicipalityId, command.PersistentLocalId)))); } + + [Fact] + public void WithRemovedStreetName_ThenNone() + { + var command = Fixture.Create(); + + // Act, assert + Assert(new Scenario() + .Given(new MunicipalityStreamId(Fixture.Create()), + Fixture.Create(), + Fixture.Create(), + Fixture.Create()) + .When(command) + .ThenNone()); + } } } diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetNameAlreadyRemoved.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetNameAlreadyRemoved.cs deleted file mode 100644 index 5f1eff1f3..000000000 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRemovingStreetName/GivenStreetNameAlreadyRemoved.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace StreetNameRegistry.Tests.AggregateTests.WhenRemovingStreetName -{ - using AutoFixture; - using Be.Vlaanderen.Basisregisters.AggregateSource.Testing; - using Municipality.Commands; - using Testing; - using Xunit; - using Xunit.Abstractions; - using global::AutoFixture; - using Municipality; - using Municipality.Events; - - public class GivenStreetNameAlreadyRemoved : StreetNameRegistryTest - { - public GivenStreetNameAlreadyRemoved(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - Fixture.Customize(new WithFixedMunicipalityId()); - Fixture.Customize(new WithFixedPersistentLocalId()); - } - - [Fact] - public void ThenDoNone() - { - var command = Fixture.Create(); - - // Act, assert - Assert(new Scenario() - .Given(new MunicipalityStreamId(Fixture.Create()), - Fixture.Create(), - Fixture.Create(), - Fixture.Create()) - .When(command) - .ThenNone()); - } - } -} diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringMunicipality/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringMunicipality/GivenMunicipality.cs index 89933b851..e73bf780e 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringMunicipality/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringMunicipality/GivenMunicipality.cs @@ -38,7 +38,7 @@ public void ThenMunicipalityWasRetired() } [Fact] - public void WhenMunicipalityAlreadyRetiredThenNothingHappens() + public void WithRetiredMunicipality_ThenNone() { var municipalityWasImported = Fixture.Create(); var municipalityWasRetired = Fixture.Create(); diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringStreetName/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringStreetName/GivenMunicipality.cs index f4a57affa..899e94399 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringStreetName/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenRetiringStreetName/GivenMunicipality.cs @@ -13,6 +13,7 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenRetiringStreetName using Municipality.Exceptions; using Extensions; using System.Collections.Generic; + using Builders; using Testing; using Xunit; using Xunit.Abstractions; @@ -34,8 +35,7 @@ public GivenMunicipality(ITestOutputHelper testOutputHelper) : base(testOutputHe [Fact] public void ThenStreetNameWasRetired() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); // Act, assert Assert(new Scenario() @@ -49,11 +49,9 @@ public void ThenStreetNameWasRetired() } [Fact] - public void ThenStreetNameNotFoundExceptionWasThrown() + public void WithNoStreetName_ThenThrowsStreetNameNotFoundException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); - + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); // Act, assert @@ -64,34 +62,16 @@ public void ThenStreetNameNotFoundExceptionWasThrown() } [Fact] - public void ThenStreetNameIsRemovedExceptionWasThrown() + public void WithRemovedStreetName_ThenStreetNameIsRemovedException() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var removedStreetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Current, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: true); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var removedStreetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Current) + .WithIsRemoved() + .Build(); // Act, assert Assert(new Scenario() @@ -104,33 +84,15 @@ public void ThenStreetNameIsRemovedExceptionWasThrown() } [Fact] - public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExceptionWasThrown() + public void WithRetiredMunicipality_ThenThrowsMunicipalityHasInvalidStatusException() { var command = Fixture.Create() .WithMunicipalityId(_municipalityId); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Proposed, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Proposed) + .Build(); // Act, assert Assert(new Scenario() @@ -145,33 +107,14 @@ public void WithMunicipalityStatusRetired_ThenMunicipalityHasInvalidStatusExcept [Theory] [InlineData(StreetNameStatus.Proposed)] [InlineData(StreetNameStatus.Rejected)] - public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus status) + public void WithInvalidStreetNameStatus_ThenThrowsStreetNameHasInvalidStatusException(StreetNameStatus status) { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - status, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); - + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(status) + .Build(); // Act, assert Assert(new Scenario() @@ -184,32 +127,14 @@ public void ThenStreetNameHasInvalidStatusExceptionWasThrown(StreetNameStatus st } [Fact] - public void WithStreetNameAlreadyRetired_ThenNone() + public void WithRetiredStreetName_ThenNone() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); var municipalityWasImported = Fixture.Create(); - var streetNameMigratedToMunicipality = Fixture.Build() - .FromFactory(() => - { - var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( - _municipalityId, - Fixture.Create(), - Fixture.Create(), - Fixture.Create(), - StreetNameStatus.Retired, - Language.Dutch, - null, - Fixture.Create(), - new HomonymAdditions(), - true, - isRemoved: false); - - ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(Fixture.Create()); - return streetNameWasMigratedToMunicipality; - }) - .Create(); + var streetNameMigratedToMunicipality = new StreetNameWasMigratedToMunicipalityBuilder(Fixture) + .WithStatus(StreetNameStatus.Retired) + .Build(); // Act, assert Assert(new Scenario() @@ -222,7 +147,7 @@ public void WithStreetNameAlreadyRetired_ThenNone() } [Fact] - public void ThenStreetNameStatusIsRetired() + public void StateCheck() { var persistentLocalId = Fixture.Create(); var aggregate = new MunicipalityFactory(NoSnapshotStrategy.Instance).Create(); diff --git a/test/StreetNameRegistry.Tests/AggregateTests/WhenSettingMunicipalityToCurrent/GivenMunicipality.cs b/test/StreetNameRegistry.Tests/AggregateTests/WhenSettingMunicipalityToCurrent/GivenMunicipality.cs index e055cea3c..977ba843a 100644 --- a/test/StreetNameRegistry.Tests/AggregateTests/WhenSettingMunicipalityToCurrent/GivenMunicipality.cs +++ b/test/StreetNameRegistry.Tests/AggregateTests/WhenSettingMunicipalityToCurrent/GivenMunicipality.cs @@ -13,40 +13,33 @@ namespace StreetNameRegistry.Tests.AggregateTests.WhenSettingMunicipalityToCurre public sealed class GivenMunicipality : StreetNameRegistryTest { - private readonly MunicipalityId _municipalityId; private readonly MunicipalityStreamId _streamId; public GivenMunicipality(ITestOutputHelper output) : base(output) { Fixture.Customize(new InfrastructureCustomization()); Fixture.Customize(new WithFixedMunicipalityId()); - _municipalityId = Fixture.Create(); _streamId = Fixture.Create(); } [Fact] public void ThenMunicipalityBecameCurrent() { - var command = Fixture.Create() - .WithMunicipalityId(_municipalityId); + var command = Fixture.Create(); Assert(new Scenario() .Given(_streamId, Fixture.Create()) .When(command) - .Then(new[] - { - new Fact(_streamId, new MunicipalityBecameCurrent(command.MunicipalityId)) - })); + .Then(new Fact(_streamId, new MunicipalityBecameCurrent(command.MunicipalityId)))); } [Fact] - public void WhenMunicipalityAlreadyBecameCurrentThenNothingHappens() + public void WithCurrentMunicipality_ThenNone() { var municipalityWasImported = Fixture.Create(); var municipalityBecameCurrent = Fixture.Create(); - var command = Fixture.Create() - .WithMunicipalityId(new MunicipalityId(_municipalityId)); + var command = Fixture.Create(); Assert(new Scenario() .Given( @@ -58,14 +51,4 @@ public void WhenMunicipalityAlreadyBecameCurrentThenNothingHappens() .ThenNone()); } } - - public static class SetMunicipalityToCurrentExtensions - { - public static SetMunicipalityToCurrent WithMunicipalityId( - this SetMunicipalityToCurrent command, - MunicipalityId municipalityId) - { - return new SetMunicipalityToCurrent(municipalityId, command.Provenance); - } - } } diff --git a/test/StreetNameRegistry.Tests/Builders/CorrectStreetNameHomonymAdditionsBuilder.cs b/test/StreetNameRegistry.Tests/Builders/CorrectStreetNameHomonymAdditionsBuilder.cs new file mode 100644 index 000000000..9249bfdc6 --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/CorrectStreetNameHomonymAdditionsBuilder.cs @@ -0,0 +1,64 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using System.Collections.Generic; + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Commands; + + /// + /// Builder for creating instances of StreetNameHomonymAdditionsWereRemoved. + /// By default, the homonym additions to remove is an empty list. + /// + public class CorrectStreetNameHomonymAdditionsBuilder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private PersistentLocalId? _persistentLocalId; + private HomonymAdditions? _homonymAdditions; + private List? _homonymAdditionsToRemove; + + public CorrectStreetNameHomonymAdditionsBuilder(Fixture fixture) + { + _fixture = fixture; + } + + public CorrectStreetNameHomonymAdditionsBuilder WithMunicipalityId(MunicipalityId? municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public CorrectStreetNameHomonymAdditionsBuilder WithPersistentLocalId(int persistentLocalId) + { + _persistentLocalId = new PersistentLocalId(persistentLocalId); + return this; + } + + public CorrectStreetNameHomonymAdditionsBuilder WithHomonymAdditions(HomonymAdditions? homonymAdditions) + { + _homonymAdditions = homonymAdditions; + return this; + } + + public CorrectStreetNameHomonymAdditionsBuilder WithHomonymAdditionsToRemove(List? homonymAdditionsToRemove) + { + _homonymAdditionsToRemove = homonymAdditionsToRemove; + return this; + } + + /// + /// Constructs a SCorrectStreetNameHomonymAdditions object with optional parameters. + /// + /// A new instance of CorrectStreetNameHomonymAdditions. + public CorrectStreetNameHomonymAdditions Build() + { + return new CorrectStreetNameHomonymAdditions( + _municipalityId ?? _fixture.Create(), + _persistentLocalId ?? _fixture.Create(), + _homonymAdditions ?? _fixture.Create(), + _homonymAdditionsToRemove ?? new List(), + _fixture.Create()); + } + } +} diff --git a/test/StreetNameRegistry.Tests/Builders/MunicipalityOfficialLanguageWasAddedBuilder.cs b/test/StreetNameRegistry.Tests/Builders/MunicipalityOfficialLanguageWasAddedBuilder.cs new file mode 100644 index 000000000..7505cc044 --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/MunicipalityOfficialLanguageWasAddedBuilder.cs @@ -0,0 +1,48 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Events; + + /// + /// Constructs a MunicipalityOfficialLanguageWasAdded object with optional parameters. + /// By default, the Language is Dutch + /// + /// MunicipalityOfficialLanguageWasAdded + public class MunicipalityOfficialLanguageWasAddedBuilder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private Language? _language; + + public MunicipalityOfficialLanguageWasAddedBuilder(Fixture fixture) + { + _fixture = fixture; + } + + public MunicipalityOfficialLanguageWasAddedBuilder WithMunicipalityId(MunicipalityId municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public MunicipalityOfficialLanguageWasAddedBuilder WithLanguage(Language language) + { + _language = language; + return this; + } + + /// + /// Constructs a MunicipalityOfficialLanguageWasAdded object with optional parameters. + /// + /// A new instance of MunicipalityOfficialLanguageWasAdded. + public MunicipalityOfficialLanguageWasAdded Build() + { + var municipalityOfficialLanguageWasAdded = + new MunicipalityOfficialLanguageWasAdded(_municipalityId ?? _fixture.Create(), _language ?? Language.Dutch); + municipalityOfficialLanguageWasAdded.SetProvenance(_fixture.Create()); + return municipalityOfficialLanguageWasAdded; + } + } +} diff --git a/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereCorrectedBuilder.cs b/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereCorrectedBuilder.cs new file mode 100644 index 000000000..53d6d3714 --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereCorrectedBuilder.cs @@ -0,0 +1,51 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using System.Collections.Generic; + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Events; + + public class StreetNameHomonymAdditionsWereCorrectedBuilder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private PersistentLocalId? _persistentLocalId; + private List? _homonymAdditions; + + public StreetNameHomonymAdditionsWereCorrectedBuilder(Fixture fixture) + { + _fixture = fixture; + } + + public StreetNameHomonymAdditionsWereCorrectedBuilder WithMunicipalityId(MunicipalityId municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public StreetNameHomonymAdditionsWereCorrectedBuilder WithPersistentLocalId(int persistentLocalId) + { + _persistentLocalId = new PersistentLocalId(persistentLocalId); + return this; + } + + public StreetNameHomonymAdditionsWereCorrectedBuilder WithHomonymAdditions(List additions) + { + _homonymAdditions = additions; + return this; + } + + public StreetNameHomonymAdditionsWereCorrected Build() + { + var streetNameHomonymAdditionsWereCorrected = new StreetNameHomonymAdditionsWereCorrected( + _municipalityId ?? _fixture.Create(), + _persistentLocalId ?? _fixture.Create(), + _homonymAdditions ?? new List()); + + ((ISetProvenance)streetNameHomonymAdditionsWereCorrected).SetProvenance(_fixture.Create()); + + return streetNameHomonymAdditionsWereCorrected; + } + } +} diff --git a/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereRemovedBuilder.cs b/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereRemovedBuilder.cs new file mode 100644 index 000000000..5d50d50d9 --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/StreetNameHomonymAdditionsWereRemovedBuilder.cs @@ -0,0 +1,58 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using System.Collections.Generic; + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Events; + + /// + /// Builder for creating instances of StreetNameHomonymAdditionsWereRemoved. + /// By default, the languages to remove are dutch. + /// + public class StreetNameHomonymAdditionsWereRemovedBuilder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private List? _languages; + private PersistentLocalId? _persistentLocalId; + + public StreetNameHomonymAdditionsWereRemovedBuilder(Fixture fixture) + { + _fixture = fixture; + } + + public StreetNameHomonymAdditionsWereRemovedBuilder WithMunicipalityId(MunicipalityId municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public StreetNameHomonymAdditionsWereRemovedBuilder WithLanguages(List languages) + { + _languages = languages; + return this; + } + + public StreetNameHomonymAdditionsWereRemovedBuilder WithPersistentLocalId(int persistentLocalId) + { + _persistentLocalId = new PersistentLocalId(persistentLocalId); + return this; + } + + /// + /// Constructs a StreetNameHomonymAdditionsWereRemoved object with optional parameters. + /// + /// A new instance of StreetNameHomonymAdditionsWereRemoved. + public StreetNameHomonymAdditionsWereRemoved Build() + { + var streetNameHomonymAdditionsWereRemoved = new StreetNameHomonymAdditionsWereRemoved( + _municipalityId ?? _fixture.Create(), + _persistentLocalId ?? _fixture.Create(), + _languages ?? new List { Language.Dutch }); + + ((ISetProvenance)streetNameHomonymAdditionsWereRemoved).SetProvenance(_fixture.Create()); + return streetNameHomonymAdditionsWereRemoved; + } + } +} diff --git a/test/StreetNameRegistry.Tests/Builders/StreetNameWasMigratedToMunicipalityBuilder.cs b/test/StreetNameRegistry.Tests/Builders/StreetNameWasMigratedToMunicipalityBuilder.cs new file mode 100644 index 000000000..c723d4363 --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/StreetNameWasMigratedToMunicipalityBuilder.cs @@ -0,0 +1,122 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Events; + + /// + /// Builder for creating instances of StreetNameWasMigratedToMunicipality. + /// By default, the primary language is Dutch, IsCompleted is true, and IsRemoved is false. + /// + public class StreetNameWasMigratedToMunicipalityBuilder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private NisCode? _nisCode; + private StreetNameId? _streetNameId; + private PersistentLocalId? _persistentLocalId; + private StreetNameStatus? _status; + private Language? _primaryLanguage; + private Language? _secondaryLanguage; + private Names? _names; + private HomonymAdditions? _homonymAdditions; + private bool _isCompleted = true; + private bool _isRemoved; + + public StreetNameWasMigratedToMunicipalityBuilder(Fixture fixture) + { + _fixture = fixture; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithMunicipalityId(MunicipalityId municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithNisCode(NisCode nisCode) + { + _nisCode = nisCode; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithStreetNameId(StreetNameId streetNameId) + { + _streetNameId = streetNameId; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithPersistentLocalId(int persistentLocalId) + { + _persistentLocalId = new PersistentLocalId(persistentLocalId); + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithStatus(StreetNameStatus streetNameStatus) + { + _status = streetNameStatus; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithPrimaryLanguage(Language language) + { + _primaryLanguage = language; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithSecondaryLanguage(Language language) + { + _secondaryLanguage = language; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithNames(Names names) + { + _names = names; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithHomonymAdditions(HomonymAdditions additions) + { + _homonymAdditions = additions; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithUnCompleted() + { + _isCompleted = false; + return this; + } + + public StreetNameWasMigratedToMunicipalityBuilder WithIsRemoved() + { + _isRemoved = true; + return this; + } + + /// + /// Constructs a StreetNameWasMigratedToMunicipality object with optional parameters. + /// + /// A new instance of StreetNameWasMigratedToMunicipality. + public StreetNameWasMigratedToMunicipality Build() + { + var streetNameWasMigratedToMunicipality = new StreetNameWasMigratedToMunicipality( + _municipalityId ?? _fixture.Create(), + _nisCode ?? _fixture.Create(), + _streetNameId ?? _fixture.Create(), + _persistentLocalId ?? _fixture.Create(), + _status ?? _fixture.Create(), + _primaryLanguage ?? Language.Dutch, + _secondaryLanguage ?? _fixture.Create(), + _names ?? _fixture.Create(), + _homonymAdditions ?? _fixture.Create(), + _isCompleted, + _isRemoved); + + ((ISetProvenance)streetNameWasMigratedToMunicipality).SetProvenance(_fixture.Create()); + + return streetNameWasMigratedToMunicipality; + } + } +} diff --git a/test/StreetNameRegistry.Tests/Builders/StreetNameWasProposedV2Builder.cs b/test/StreetNameRegistry.Tests/Builders/StreetNameWasProposedV2Builder.cs new file mode 100644 index 000000000..10818ea7f --- /dev/null +++ b/test/StreetNameRegistry.Tests/Builders/StreetNameWasProposedV2Builder.cs @@ -0,0 +1,58 @@ +namespace StreetNameRegistry.Tests.Builders +{ + using Be.Vlaanderen.Basisregisters.GrAr.Provenance; + using global::AutoFixture; + using Municipality; + using Municipality.Events; + + public class StreetNameWasProposedV2Builder + { + private readonly Fixture _fixture; + private MunicipalityId? _municipalityId; + private NisCode? _nisCode; + private PersistentLocalId? _persistentLocalId; + private Names? _names; + + public StreetNameWasProposedV2Builder(Fixture fixture) + { + _fixture = fixture; + } + + public StreetNameWasProposedV2Builder WithMunicipalityId(MunicipalityId municipalityId) + { + _municipalityId = municipalityId; + return this; + } + + public StreetNameWasProposedV2Builder WithNisCode(string nisCode) + { + _nisCode = new NisCode(nisCode); + return this; + } + + public StreetNameWasProposedV2Builder WithPersistentLocalId(int persistentLocalId) + { + _persistentLocalId = new PersistentLocalId(persistentLocalId); + return this; + } + + public StreetNameWasProposedV2Builder WithNames(Names names) + { + _names = names; + return this; + } + + public StreetNameWasProposedV2 Build() + { + var streetNameWasProposedV2 = new StreetNameWasProposedV2( + _municipalityId ?? _fixture.Create(), + _nisCode ?? _fixture.Create(), + _names ?? _fixture.Create(), + _persistentLocalId ?? _fixture.Create()); + + streetNameWasProposedV2.SetProvenance(_fixture.Create()); + + return streetNameWasProposedV2; + } + } +}