public async Task Given_MunicipalityWasNamed_twice_and_municipality_was_registered_Then_expected_item_is_updated() { var projection = new MunicipalityListProjections(); var resolver = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers); var crabMunicipalityId = new CrabMunicipalityId(1); var municipalityId = MunicipalityId.CreateFor(crabMunicipalityId); var nisCode = "456"; var municipalityWasRegistered = new MunicipalityWasRegistered(municipalityId, new NisCode(nisCode)); ((ISetProvenance)municipalityWasRegistered).SetProvenance(_provenance); var municipalityWasNamed = new MunicipalityWasNamed(municipalityId, new MunicipalityName("test", Language.Dutch)); ((ISetProvenance)municipalityWasNamed).SetProvenance(_provenance); var wasNamed = new MunicipalityWasNamed(municipalityId, new MunicipalityName("test21", Language.French)); ((ISetProvenance)wasNamed).SetProvenance(_provenance); await new ConnectedProjectionScenario <LegacyContext>(resolver) .Given( new Envelope <MunicipalityWasRegistered>(new Envelope( municipalityWasRegistered, EmptyMetadata)), new Envelope <MunicipalityWasNamed>(new Envelope( municipalityWasNamed, EmptyMetadata)), new Envelope <MunicipalityWasNamed>(new Envelope( wasNamed, EmptyMetadata))) .Verify(async context => { var municipality = await context.MunicipalityList.FirstAsync(a => a.MunicipalityId == municipalityId); municipality.MunicipalityId.Should().Be((Guid)municipalityId); municipality.NameDutch.Should().Be("test"); municipality.NameFrench.Should().Be("test21"); return(VerificationResult.Pass()); }) .Assert(); }
public async Task ImportStreetNameFromCrab( Func <IStreetNames> getStreetNames, CommandMessage <ImportStreetNameFromCrab> message, CancellationToken ct) { var streetNames = getStreetNames(); var streetNameId = StreetNameId.CreateFor(message.Command.StreetNameId); var municipalityId = MunicipalityId.CreateFor(message.Command.MunicipalityId); var streetName = await GetOrRegisterStreetName( streetNames, streetNameId, municipalityId, message.Command.NisCode, ct); ImportFromCrab(streetName.Value, message.Command); }
public async Task Given_MunicipalityDefinedNisCode_Then_nisCode_should_be_changed() { var projection = new MunicipalityListProjections(); var resolver = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers); var crabMunicipalityId = new CrabMunicipalityId(1); var municipalityId = MunicipalityId.CreateFor(crabMunicipalityId); var nisCode = "456"; var municipalityWasRegistered = new MunicipalityWasRegistered(municipalityId, new NisCode(nisCode)); ((ISetProvenance)municipalityWasRegistered).SetProvenance(_provenance); var municipalityNisCodeWasDefined = new MunicipalityNisCodeWasDefined(municipalityId, new NisCode(nisCode)); ((ISetProvenance)municipalityNisCodeWasDefined).SetProvenance(_provenance); await new ConnectedProjectionScenario <LegacyContext>(resolver) .Given( new Envelope <MunicipalityWasRegistered>(new Envelope( municipalityWasRegistered, EmptyMetadata)), new Envelope <MunicipalityNisCodeWasDefined>(new Envelope( municipalityNisCodeWasDefined, EmptyMetadata))) .Verify(async context => { var municipality = await context.MunicipalityList.FirstAsync(a => a.NisCode == nisCode); municipality.MunicipalityId.Should().Be((Guid)municipalityId); municipality.NisCode.Should().Be(nisCode); return(VerificationResult.Pass()); }) .Assert(); }
public async Task Given_MunicipalityDefinedPrimaryLanguage_Then_expected_item_is_updated() { var projection = new MunicipalityListProjections(); var resolver = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers); var crabMunicipalityId = new CrabMunicipalityId(1); var municipalityId = MunicipalityId.CreateFor(crabMunicipalityId); var nisCode = "456"; var municipalityWasRegistered = new MunicipalityWasRegistered(municipalityId, new NisCode(nisCode)); ((ISetProvenance)municipalityWasRegistered).SetProvenance(_provenance); var municipalityOfficialLanguageWasAdded = new MunicipalityOfficialLanguageWasAdded(municipalityId, Language.Dutch); ((ISetProvenance)municipalityOfficialLanguageWasAdded).SetProvenance(_provenance); await new ConnectedProjectionScenario <LegacyContext>(resolver) .Given( new Envelope <MunicipalityWasRegistered>(new Envelope( municipalityWasRegistered, EmptyMetadata)), new Envelope <MunicipalityOfficialLanguageWasAdded>(new Envelope( municipalityOfficialLanguageWasAdded, EmptyMetadata))) .Verify(async context => { var municipality = await context.MunicipalityList.FirstAsync(a => a.MunicipalityId == municipalityId); municipality.MunicipalityId.Should().Be((Guid)municipalityId); municipality.OfficialLanguages.Should().AllBeEquivalentTo(Language.Dutch); return(VerificationResult.Pass()); }) .Assert(); }
public MunicipalityCommandHandlerModule( Func <IMunicipalities> getMunicipalities, Func <ConcurrentUnitOfWork> getUnitOfWork, Func <IStreamStore> getStreamStore, EventMapping eventMapping, EventSerializer eventSerializer, MunicipalityProvenanceFactory provenanceFactory) { For <ImportMunicipalityFromCrab>() .AddSqlStreamStore(getStreamStore, getUnitOfWork, eventMapping, eventSerializer) .AddProvenance(getUnitOfWork, provenanceFactory) .Handle(async(message, ct) => { var municipalities = getMunicipalities(); var municipalityId = MunicipalityId.CreateFor(message.Command.MunicipalityId); var municipality = await municipalities.GetOptionalAsync(municipalityId, ct); if (!municipality.HasValue) { municipality = new Optional <Municipality>(Municipality.Register(municipalityId, message.Command.NisCode)); municipalities.Add(municipalityId, municipality.Value); } municipality.Value.ImportFromCrab( message.Command.MunicipalityId, message.Command.NisCode, message.Command.PrimaryLanguage, message.Command.SecondaryLanguage, message.Command.FacilityLanguage, message.Command.NumberOfFlags, message.Command.Lifetime, message.Command.Geometry, message.Command.Timestamp, message.Command.Operator, message.Command.Modification, message.Command.Organisation); }); For <ImportMunicipalityNameFromCrab>() .AddSqlStreamStore(getStreamStore, getUnitOfWork, eventMapping, eventSerializer) .AddProvenance(getUnitOfWork, provenanceFactory) .Handle(async(message, ct) => { var municipalities = getMunicipalities(); var municipalityId = MunicipalityId.CreateFor(message.Command.MunicipalityId); var municipality = await municipalities.GetAsync(municipalityId, ct); municipality.ImportNameFromCrab( message.Command.MunicipalityId, message.Command.MunicipalityNameId, message.Command.MunicipalityName, message.Command.Lifetime, message.Command.Timestamp, message.Command.Operator, message.Command.Modification, message.Command.Organisation); }); }