public async Task DoesNotAppendEventWhenLastEventIsFromSameDay()
        {
            var now                 = new DateTime(2019, 12, 25, 12, 00, 00);
            var utcNow              = now.ToUniversalTime();
            var clockProviderStub   = new ClockProviderStub(now);
            var inMemoryStreamStore = new InMemoryStreamStore(() => utcNow);
            var clockHasTicked      = new ClockHasTicked(new DateTime(2019, 12, 25, 11, 00, 00));

            var cancellationToken = CancellationToken.None;
            await inMemoryStreamStore.AppendToStream(
                streamId : new StreamId(ClockTickingService.ClockStreamId),
                expectedVersion : ExpectedVersion.Any,
                message : new NewStreamMessage(
                    messageId: Guid.NewGuid(),
                    type: _eventMapping.GetEventName(clockHasTicked.GetType()),
                    jsonData: JsonConvert.SerializeObject(clockHasTicked)),
                cancellationToken : cancellationToken);

            var sut = new ClockTickingService(inMemoryStreamStore, clockProviderStub);

            await sut.StartAsync(cancellationToken);

            var forwards = await inMemoryStreamStore.ReadAllForwards(Position.Start, Int32.MaxValue, true, cancellationToken);

            forwards.Messages.Should().HaveCount(1);
        }
        public async Task AppendsEventWhenStreamIsEmpty()
        {
            var now                 = new DateTime(2019, 12, 25, 12, 00, 00);
            var utcNow              = now.ToUniversalTime();
            var clockProviderStub   = new ClockProviderStub(now);
            var inMemoryStreamStore = new InMemoryStreamStore(() => utcNow);

            var sut = new ClockTickingService(inMemoryStreamStore, clockProviderStub);

            var cancellationToken = CancellationToken.None;
            await sut.StartAsync(cancellationToken);

            var forwards = await inMemoryStreamStore.ReadAllForwards(Position.Start, Int32.MaxValue, true, cancellationToken);

            forwards.Messages.Should().HaveCount(1);

            var message = forwards.Messages[0];

            message.StreamId.Should().Be(ClockTickingService.ClockStreamId);
            message.StreamVersion.Should().Be(StreamVersion.Start);

            var messageData = JsonConvert.DeserializeObject <ClockHasTicked>(await message.GetJsonData(cancellationToken));

            messageData.DateTime.Should().Be(now);
        }
예제 #3
0
        public Task WhenIpdcCodeWasSet()
        {
            var clockProviderStub = new ClockProviderStub(Today);

            var publicServiceId   = new PublicServiceId("DVR000000001");
            var publicServiceName = new PublicServiceName("Test");
            var events            = new object[]
            {
                new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                new IpdcCodeWasSet(publicServiceId, new IpdcCode("1234")),
            };

            return(new PublicServiceListProjections(clockProviderStub)
                   .Scenario()
                   .Given(events)
                   .Expect(new PublicServiceListItem
            {
                Name = publicServiceName,
                PublicServiceId = publicServiceId,
                CurrentLifeCycleStageType = null,
                CurrentLifeCycleStageId = null,
                CurrentLifeCycleStageEndsAt = null,
                IpdcCode = "1234"
            }));
        }
예제 #4
0
        public Task DoesNotSetNextLifeCycleStageWhenDayHasPassedWhenThatLifeCycleStageWasRemoved()
        {
            var clockProviderStub = new ClockProviderStub(Today);

            var publicServiceId   = new PublicServiceId("DVR000000001");
            var publicServiceName = new PublicServiceName("Test");
            var events            = new object[]
            {
                new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), LifeCycleStageType.Active, PeriodOverlappingWithToday),
                new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(2), LifeCycleStageType.PhasingOut, PeriodOverlappingWithTomorrow),
                new LifeCycleStageWasRemoved(publicServiceId, LifeCycleStageId.FromNumber(2)),
                new ClockHasTicked(Tomorrow),
            };

            return(new PublicServiceListProjections(clockProviderStub)
                   .Scenario()
                   .Given(events)
                   .Expect(new PublicServiceListItem
            {
                Name = publicServiceName,
                PublicServiceId = publicServiceId,
                CurrentLifeCycleStageType = null,
                CurrentLifeCycleStageId = null,
                CurrentLifeCycleStageEndsAt = null,
            }));
        }
예제 #5
0
        public Task DoesNotClearLifeCycleStageWhenAnotherLifeCycleStageNoLongerOverlapsWithToday()
        {
            var clockProviderStub = new ClockProviderStub(Today);

            var publicServiceId   = new PublicServiceId("DVR000000001");
            var publicServiceName = new PublicServiceName("Test");
            var events            = new object[]
            {
                new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), LifeCycleStageType.Active, PeriodOverlappingWithToday),
                new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(2), LifeCycleStageType.PhasingOut, PeriodOverlappingWithTomorrow),
                new PeriodOfLifeCycleStageWasChanged(publicServiceId, LifeCycleStageId.FromNumber(2), PeriodOverlappingWithYesterday),
            };

            return(new PublicServiceListProjections(clockProviderStub)
                   .Scenario()
                   .Given(events)
                   .Expect(new PublicServiceListItem
            {
                Name = publicServiceName,
                PublicServiceId = publicServiceId,
                CurrentLifeCycleStageType = "Active",
                CurrentLifeCycleStageId = 1,
                CurrentLifeCycleStageEndsAt = LocalDate.FromDateTime(Today),
            }));
        }
예제 #6
0
        public Task ShowsLifeCycleStageWhenLifeCycleStageWasAddedThatOverlapsWithToday()
        {
            var clockProviderStub = new ClockProviderStub(Today);

            var publicServiceId   = new PublicServiceId("DVR000000001");
            var publicServiceName = new PublicServiceName("Test");
            var events            = new object[]
            {
                new PublicServiceWasRegistered(publicServiceId, publicServiceName, PrivateZoneId.Unregistered),
                new StageWasAddedToLifeCycle(publicServiceId, LifeCycleStageId.FromNumber(1), LifeCycleStageType.Active, PeriodValidAlways),
            };

            return(new PublicServiceListProjections(clockProviderStub)
                   .Scenario()
                   .Given(events)
                   .Expect(new PublicServiceListItem
            {
                Name = publicServiceName,
                PublicServiceId = publicServiceId,
                CurrentLifeCycleStageType = "Active",
                CurrentLifeCycleStageId = 1,
            }));
        }