Exemple #1
0
        public void UpgradeStream_RunsAllUpgrades()
        {
            IEventUpgrade[] eventUpgrades  = null;
            var             eventStream    = new[] { (IEventMessage <DomainAggregateEvent>)EventMessage.FromEvent(Substitute.ForPartsOf <DomainAggregateEvent>(), null) };
            var             eventStream1   = new[] { (IEventMessage <DomainAggregateEvent>)EventMessage.FromEvent(Substitute.ForPartsOf <DomainAggregateEvent>(), null) };
            var             eventStream2   = new[] { (IEventMessage <DomainAggregateEvent>)EventMessage.FromEvent(Substitute.ForPartsOf <DomainAggregateEvent>(), null) };
            var             eventStream3   = new[] { (IEventMessage <DomainAggregateEvent>)EventMessage.FromEvent(Substitute.ForPartsOf <DomainAggregateEvent>(), null) };
            var             streamMetadata = new Dictionary <string, string>();

            Func <IEventUpgrade[]> eventUpgradesFunc = () =>
            {
                eventUpgrades = new[]
                {
                    Substitute.For <IEventUpgrade>(),
                    Substitute.For <IEventUpgrade>()
                };

                eventUpgrades[0].UpgradeStream(eventStream, streamMetadata).Returns(eventStream1);
                eventUpgrades[1].UpgradeStream(eventStream1, streamMetadata).Returns(eventStream2);

                return(eventUpgrades);
            };

            sequenceNumbersUpgrade.UpgradeSequenceNumbers(eventStream2).Returns(eventStream3);

            sut = new EventStreamUpgrader(eventUpgradesFunc, sequenceNumbersUpgrade);
            var result = sut.UpgradeStream(eventStream, streamMetadata);

            result.Should().BeSameAs(eventStream3);
        }
Exemple #2
0
        public IEnumerable <IEventMessage <DomainAggregateEvent> > UpgradeStream(
            IEnumerable <IEventMessage <DomainAggregateEvent> > eventStream,
            IReadOnlyDictionary <string, string> eventStreamMetadata)
        {
            var eventUpgrades = eventUpgradesFunc();

            var result = eventStream;

            foreach (var eventUpgrade in eventUpgrades)
            {
                result = eventUpgrade.UpgradeStream(result, eventStreamMetadata);
            }

            result = sequenceNumbersUpgrade.UpgradeSequenceNumbers(result);

            return(result);
        }