public async Task Given_MunicipalityWasRegistered_Then_expected_item_is_added()
        {
            var projection = new MunicipalityListProjections();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            var municipalityId            = Guid.NewGuid();
            var nisCode                   = "123";
            var municipalityWasRegistered = new MunicipalityWasRegistered(new MunicipalityId(municipalityId), new NisCode(nisCode));

            ((ISetProvenance)municipalityWasRegistered).SetProvenance(_provenance);

            await new ConnectedProjectionScenario <LegacyContext>(resolver)
            .Given(
                new Envelope <MunicipalityWasRegistered>(new Envelope(
                                                             municipalityWasRegistered,
                                                             EmptyMetadata)))

            .Verify(async context =>
            {
                var municipality = await context.MunicipalityList.FirstAsync(a => a.MunicipalityId == municipalityId);

                municipality.MunicipalityId
                .Should()
                .Be(municipalityId);

                municipality.NisCode
                .Should()
                .Be(nisCode);

                return(VerificationResult.Pass());
            })

            .Assert();
        }
Ejemplo n.º 2
0
        public async Task WhenPeriodOfLifeCycleStageWasChanged()
        {
            var projection = new PublicServiceLifeCycleListProjections();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            var stageWasAddedToLifeCycle         = _fixture.Create <StageWasAddedToLifeCycle>();
            var periodOfLifeCycleStageWasChanged = new PeriodOfLifeCycleStageWasChanged(
                new PublicServiceId(stageWasAddedToLifeCycle.PublicServiceId),
                LifeCycleStageId.FromNumber(stageWasAddedToLifeCycle.LifeCycleStageId),
                _fixture.Create <LifeCycleStagePeriod>());

            await new ConnectedProjectionScenario <BackofficeContext>(resolver)
            .Given(
                new Envelope <StageWasAddedToLifeCycle>(new Envelope(stageWasAddedToLifeCycle, new Dictionary <string, object>())),
                new Envelope <PeriodOfLifeCycleStageWasChanged>(new Envelope(periodOfLifeCycleStageWasChanged, new Dictionary <string, object>())))
            .Verify(async context =>
            {
                var publicService =
                    await context.PublicServiceLifeCycleList.FirstAsync(a =>
                                                                        a.PublicServiceId == stageWasAddedToLifeCycle.PublicServiceId && a.LifeCycleStageId == stageWasAddedToLifeCycle.LifeCycleStageId);

                publicService.Should().BeEquivalentTo(new PublicServiceLifeCycleItem()
                {
                    LifeCycleStageId   = stageWasAddedToLifeCycle.LifeCycleStageId,
                    PublicServiceId    = stageWasAddedToLifeCycle.PublicServiceId,
                    LifeCycleStageType = stageWasAddedToLifeCycle.LifeCycleStageType,
                    From = periodOfLifeCycleStageWasChanged.From,
                    To   = periodOfLifeCycleStageWasChanged.To
                });

                return(VerificationResult.Pass());
            })
            .Assert();
        }
Ejemplo n.º 3
0
        public async Task WhenPublicServiceWasRegistered()
        {
            var projection = new PublicServiceListProjections(new ClockProviderStub(DateTime.Now));
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            var publicServiceId            = PublicServiceId.FromNumber(123);
            var publicServiceWasRegistered = new PublicServiceWasRegistered(publicServiceId, new PublicServiceName("Ophaling huisvuil"), PrivateZoneId.Unregistered);

            await new ConnectedProjectionScenario <BackofficeContext>(resolver)
            .Given(
                new Envelope <PublicServiceWasRegistered>(new Envelope(
                                                              publicServiceWasRegistered, new Dictionary <string, object>())))
            .Verify(async context =>
            {
                var publicService = await context.PublicServiceList.FirstAsync(a => a.PublicServiceId == publicServiceId);

                publicService.PublicServiceId.Should().Be("DVR000000123");
                publicService.Name.Should().Be("Ophaling huisvuil");
                publicService.CompetentAuthorityCode.Should().BeNullOrEmpty();
                publicService.CompetentAuthorityName.Should().BeNullOrEmpty();
                publicService.ExportToOrafin.Should().Be(false);

                return(VerificationResult.Pass());
            })
            .Assert();
        }
Ejemplo n.º 4
0
        public async Task WhenLifeCycleStageWasRemoved()
        {
            var projection = new PublicServiceLifeCycleListProjections();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            var stageWasAddedToLifeCycle = _fixture.Create <StageWasAddedToLifeCycle>();
            var lifeCycleStageWasRemoved = new LifeCycleStageWasRemoved(
                new PublicServiceId(stageWasAddedToLifeCycle.PublicServiceId),
                LifeCycleStageId.FromNumber(stageWasAddedToLifeCycle.LifeCycleStageId));

            await new ConnectedProjectionScenario <BackofficeContext>(resolver)
            .Given(
                new Envelope <StageWasAddedToLifeCycle>(new Envelope(stageWasAddedToLifeCycle, new Dictionary <string, object>())),
                new Envelope <LifeCycleStageWasRemoved>(new Envelope(lifeCycleStageWasRemoved, new Dictionary <string, object>())))
            .Verify(async context =>
            {
                var publicService =
                    await context.PublicServiceLifeCycleList.FirstOrDefaultAsync(a =>
                                                                                 a.PublicServiceId == stageWasAddedToLifeCycle.PublicServiceId && a.LifeCycleStageId == stageWasAddedToLifeCycle.LifeCycleStageId);

                publicService.Should().BeNull();

                return(VerificationResult.Pass());
            })
            .Assert();
        }
Ejemplo n.º 5
0
        protected ConnectedProjectionScenario <TContext> Given(params object[] messages)
        {
            var projection = CreateProjection();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            return(new ConnectedProjectionScenario <TContext>(resolver)
                   .Given(messages));
        }
Ejemplo n.º 6
0
 public static ProjectionScenario <IAsyncDocumentSession> For(
     ProjectionHandler <IAsyncDocumentSession>[] handlers)
 {
     if (handlers == null)
     {
         throw new ArgumentNullException("handlers");
     }
     return(new ProjectionScenario <IAsyncDocumentSession>(
                ConcurrentResolve.WhenEqualToHandlerMessageType(handlers)));
 }
Ejemplo n.º 7
0
        public void WhenAssignableToHandlerMessageTypeResolverReturnsExpectedResult(
            SqlProjectionHandler[] resolvable,
            object message,
            SqlProjectionHandler[] resolved)
        {
            var sut    = ConcurrentResolve.WhenAssignableToHandlerMessageType(resolvable);
            var result = sut(message);

            Assert.That(result, Is.EquivalentTo(resolved));
        }
        public async Task Given_no_messages_Then_list_is_empty()
        {
            var projection = new MunicipalityListProjections();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            await new ConnectedProjectionScenario <LegacyContext>(resolver)
            .Given()
            .Verify(async context =>
                    await context.MunicipalityList.AnyAsync()
                        ? VerificationResult.Fail()
                        : VerificationResult.Pass())
            .Assert();
        }
        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();
        }
Ejemplo n.º 10
0
        public async Task StreetNameVersionWasIncreasedCreatesRecordWithCorrectProvenance()
        {
            var id = Arrange(Generate.StreetNameId);

            var streetNameWasRegistered = Arrange(Generate.StreetNameWasRegistered.Select(e => e.WithId(id)));
            var provenance = new Provenance(Instant.FromDateTimeOffset(DateTimeOffset.Now), Application.CrabWstEditService, Reason.DecentralManagmentCrab, new Operator("test"), Modification.Update, Organisation.Municipality);

            ((ISetProvenance)streetNameWasRegistered).SetProvenance(provenance);

            var projection = new StreetNameVersionProjections();
            var resolver   = ConcurrentResolve.WhenEqualToHandlerMessageType(projection.Handlers);

            var metadata = new Dictionary <string, object>
            {
                [Provenance.ProvenanceMetadataKey] = JsonConvert.SerializeObject(provenance.ToDictionary()),
                [Envelope.PositionMetadataKey]     = 1L
            };

            await new ConnectedProjectionScenario <LegacyContext>(resolver)
            .Given(new Envelope <StreetNameWasRegistered>(new Envelope(streetNameWasRegistered, metadata)))
            .Verify(async context =>
            {
                var streetNameVersion = await context.StreetNameVersions
                                        .FirstAsync(a => a.StreetNameId == id);

                streetNameVersion.Should().NotBeNull();

                streetNameVersion.Reason.Should().Be(provenance.Reason);
                streetNameVersion.Application.Should().Be(provenance.Application);
                streetNameVersion.VersionTimestamp.Should().Be(provenance.Timestamp);
                streetNameVersion.Operator.Should().Be(provenance.Operator.ToString());
                streetNameVersion.Modification.Should().Be(provenance.Modification);
                streetNameVersion.Organisation.Should().Be(provenance.Organisation);

                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 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();
        }
Ejemplo n.º 13
0
 public static ProjectionScenario <MemoryCache> For(ProjectionHandler <MemoryCache>[] handlers)
 {
     return(new ProjectionScenario <MemoryCache>(
                ConcurrentResolve.WhenEqualToHandlerMessageType(handlers)
                ));
 }
Ejemplo n.º 14
0
 public void WhenEqualToHandlerMessageTypeHandlersCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ConcurrentResolve.WhenEqualToHandlerMessageType(null));
 }
Ejemplo n.º 15
0
        public void WhenAssignableToHandlerMessageTypeResolverThrowsWhenMessageIsNull()
        {
            var sut = ConcurrentResolve.WhenAssignableToHandlerMessageType(new SqlProjectionHandler[0]);

            Assert.Throws <ArgumentNullException>(() => sut(null));
        }
Ejemplo n.º 16
0
 public void WhenAssignableToHandlerMessageTypeHandlersCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           ConcurrentResolve.WhenAssignableToHandlerMessageType <object>(null));
 }
Ejemplo n.º 17
0
        public void WhenEqualToHandlerMessageTypeResolverThrowsWhenMessageIsNull()
        {
            var sut = ConcurrentResolve.WhenEqualToHandlerMessageType(new ConnectedProjectionHandler <object> [0]);

            Assert.Throws <ArgumentNullException>(() => sut(null));
        }