コード例 #1
0
        public void ALifeCycleStagePeriodOverlapsWhenItsBeginFallsBetweenTheOtherLifeCycleStagePeriodsBeginAndEnd()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2015, 01, 01)), new ValidTo(new LocalDate(2017, 01, 01)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 01)), new ValidTo(new LocalDate(2018, 01, 01)));

            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
コード例 #2
0
        public void ALifeCycleStagePeriodDoesNotOverlapWhenTheOtherLifeCycleStagePeriodsStartsAfterItsEndLifeCycleStagePeriod()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2015, 01, 01)), new ValidTo(new LocalDate(2016, 01, 01)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 02)), new ValidTo(new LocalDate(2017, 01, 01)));

            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeFalse();
        }
コード例 #3
0
        public void ALifeCycleStagePeriodDoesNotOverlapWhenItHasNoStartAndItsStartIsAfterTheOtherLifeCycleStagePeriodsStart()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo(new LocalDate(2015, 01, 01)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 02)), new ValidTo(new LocalDate(2017, 12, 31)));

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeFalse();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeFalse();
        }
コード例 #4
0
        public void ALifeCycleStagePeriodOverlapsWhenItHasNoEndAndItsStartIsBeforeTheOtherLifeCycleStagePeriodsStart()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2015, 01, 01)), new ValidTo());
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 02)), new ValidTo(new LocalDate(2017, 01, 01)));

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeTrue();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
コード例 #5
0
        public void AlmostGivingUp()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo(new LocalDate(2000, 1, 1)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(1900, 1, 1)), new ValidTo(new LocalDate(2010, 1, 1)));

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeTrue();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
コード例 #6
0
        public void StillNot()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo(new LocalDate(2000, 1, 1)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2010, 1, 1)), new ValidTo());

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeFalse();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeFalse();
        }
コード例 #7
0
        public void SomeoneStillDidntBelieveMe()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo());
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo());

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeTrue();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
コード例 #8
0
        public void LifeCycleStagePeriodsOverlapWhenTheyHaveTheSameBeginAndTheSameEnd()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 01)), new ValidTo(new LocalDate(2017, 01, 01)));
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 01)), new ValidTo(new LocalDate(2017, 01, 01)));

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeTrue();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
コード例 #9
0
        public void SomeoneDidNotBelieveMe()
        {
            var lifeCycleStagePeriod1 = new LifeCycleStagePeriod(new ValidFrom(), new ValidTo());
            var lifeCycleStagePeriod2 = new LifeCycleStagePeriod(new ValidFrom(new LocalDate(2016, 01, 02)), new ValidTo(new LocalDate(2017, 01, 01)));

            lifeCycleStagePeriod1.OverlapsWith(lifeCycleStagePeriod2).Should().BeTrue();
            lifeCycleStagePeriod2.OverlapsWith(lifeCycleStagePeriod1).Should().BeTrue();
        }
        public PublicServiceListProjections(IClockProvider clockProvider)
        {
            When <Envelope <PublicServiceWasRegistered> >(async(context, message, ct) =>
            {
                var publicServiceListItem = new PublicServiceListItem
                {
                    PublicServiceId = message.Message.PublicServiceId,
                    Name            = message.Message.Name,
                    Removed         = false
                };

                await context
                .PublicServiceList
                .AddAsync(publicServiceListItem, ct);
            });

            When <Envelope <PublicServiceWasRenamed> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.Name = message.Message.NewName;
            });

            When <Envelope <CompetentAuthorityWasAssigned> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.CompetentAuthorityCode = message.Message.CompetentAuthorityCode;
                publicServiceListItem.CompetentAuthorityName = message.Message.CompetentAuthorityName;
            });

            When <Envelope <OrafinExportPropertyWasSet> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.ExportToOrafin = message.Message.ExportToOrafin;
            });

            When <Envelope <PublicServiceWasRemoved> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.Removed = true;
            });

            When <Envelope <StageWasAddedToLifeCycle> >(async(context, message, ct) =>
            {
                await AddLifeCycleStage(message, context, ct);

                var period = new LifeCycleStagePeriod(
                    new ValidFrom(message.Message.From),
                    new ValidTo(message.Message.To));

                if (!period.OverlapsWith(clockProvider.Today))
                {
                    return;
                }

                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.CurrentLifeCycleStageType   = message.Message.LifeCycleStageType;
                publicServiceListItem.CurrentLifeCycleStageId     = message.Message.LifeCycleStageId;
                publicServiceListItem.CurrentLifeCycleStageEndsAt = message.Message.To;
            });

            When <Envelope <PeriodOfLifeCycleStageWasChanged> >(async(context, message, ct) =>
            {
                var publicServiceLifeCycleItem = await FindPublicServiceLifeCycleItemOrNull(
                    context,
                    message.Message.PublicServiceId,
                    message.Message.LifeCycleStageId,
                    ct);

                publicServiceLifeCycleItem.From = message.Message.From;
                publicServiceLifeCycleItem.To   = message.Message.To;

                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                var period = new LifeCycleStagePeriod(new ValidFrom(message.Message.From), new ValidTo(message.Message.To));
                if (period.OverlapsWith(clockProvider.Today))
                {
                    publicServiceListItem.CurrentLifeCycleStageId     = message.Message.LifeCycleStageId;
                    publicServiceListItem.CurrentLifeCycleStageType   = publicServiceLifeCycleItem.LifeCycleStageType;
                    publicServiceListItem.CurrentLifeCycleStageEndsAt = message.Message.To;
                }
                else if (publicServiceListItem.CurrentLifeCycleStageId == message.Message.LifeCycleStageId &&
                         !period.OverlapsWith(clockProvider.Today))
                {
                    publicServiceListItem.CurrentLifeCycleStageId     = null;
                    publicServiceListItem.CurrentLifeCycleStageType   = null;
                    publicServiceListItem.CurrentLifeCycleStageEndsAt = null;
                }
            });

            When <Envelope <LifeCycleStageWasRemoved> >(async(context, message, ct) =>
            {
                var publicServiceLifeCycleItem = await FindPublicServiceLifeCycleItemOrNull(
                    context,
                    message.Message.PublicServiceId,
                    message.Message.LifeCycleStageId,
                    ct);

                // TODO: does this work properly in catch up mode? Implementing soft-delete might solve this indirectly
                context.LifeCycleStagesForPublicServiceList.Remove(publicServiceLifeCycleItem);

                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                if (publicServiceListItem.CurrentLifeCycleStageId == publicServiceLifeCycleItem.LifeCycleStageId)
                {
                    publicServiceListItem.CurrentLifeCycleStageId     = null;
                    publicServiceListItem.CurrentLifeCycleStageType   = null;
                    publicServiceListItem.CurrentLifeCycleStageEndsAt = null;
                }
            });

            When <Envelope <IpdcCodeWasSet> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.IpdcCode = message.Message.IpdcCode;
            });

            When <Envelope <LegislativeDocumentIdWasSet> >(async(context, message, ct) =>
            {
                var publicServiceListItem = await FindPublicService(
                    context,
                    message.Message.PublicServiceId,
                    ct);

                publicServiceListItem.LegislativeDocumentId = message.Message.LegislativeDocumentId;
            });

            When <Envelope <ClockHasTicked> >(async(context, message, ct) =>
            {
                var date      = LocalDate.FromDateTime(message.Message.DateTime);
                var dateAsInt = date.ToInt();

                // TODO: This needs to query on both local and db
                foreach (var publicServiceListItem in context.PublicServiceList.Where(item => item.CurrentLifeCycleStageEndsAtAsInt != null && item.CurrentLifeCycleStageEndsAtAsInt < dateAsInt))
                {
                    await UpdateCurrentLifeCycleStage(context, publicServiceListItem, date, ct);
                }
            });
        }