Ejemplo n.º 1
0
        public void Should_be_able_to_trim_sequence_number_tail()
        {
            var aggregation = new ProjectionAggregation(100);

            var projection1 =
                new Projection("projection-1", 10, Environment.MachineName, AppDomain.CurrentDomain.BaseDirectory)
                .AddEventHandler(this);
            var projection2 =
                new Projection("projection-2", 15, Environment.MachineName, AppDomain.CurrentDomain.BaseDirectory)
                .AddEventHandler(this);

            aggregation.Add(projection1);
            aggregation.Add(projection2);

            Assert.That(aggregation.SequenceNumberTail, Is.EqualTo(10));
            Assert.That(aggregation.TrimSequenceNumberTail(), Is.EqualTo(10));

            projection1.Process(new EventEnvelope {
                AssemblyQualifiedName = typeof(object).AssemblyQualifiedName
            }, new object(), new PrimitiveEvent {
                SequenceNumber = 12
            }, new CancellationToken(false));

            Assert.That(aggregation.SequenceNumberTail, Is.EqualTo(10));
            Assert.That(aggregation.TrimSequenceNumberTail(), Is.EqualTo(12));
            Assert.That(aggregation.SequenceNumberTail, Is.EqualTo(12));

            projection1.Process(new EventEnvelope {
                AssemblyQualifiedName = typeof(object).AssemblyQualifiedName
            }, new object(), new PrimitiveEvent {
                SequenceNumber = 18
            }, new CancellationToken(false));

            Assert.That(aggregation.SequenceNumberTail, Is.EqualTo(12));
            Assert.That(aggregation.TrimSequenceNumberTail(), Is.EqualTo(15));
            Assert.That(aggregation.SequenceNumberTail, Is.EqualTo(15));
        }
        public void Should_be_able_to_use_provider()
        {
            var projection = new Projection("projection", 15, Environment.MachineName, AppDomain.CurrentDomain.BaseDirectory);

            projection.AddEventHandler(this);

            var eventProcessor        = new Mock <IEventProcessor>();
            var projectionAggregation = new ProjectionAggregation(100);

            projectionAggregation.Add(projection);

            eventProcessor.Setup(m => m.GetProjectionAggregation(It.IsAny <Guid>())).Returns(projectionAggregation);

            var configuration = new Mock <IEventStoreConfiguration>();
            var provider      = new ProjectionEventProvider(configuration.Object, eventProcessor.Object, GetRepository());

            ProjectionEvent projectionEvent;

            var eventEnvelope = new EventEnvelope
            {
                AssemblyQualifiedName = typeof(TestEvent).AssemblyQualifiedName
            };

            Assert.That(projectionAggregation.IsEmpty, Is.True);

            for (var i = 0; i < 10; i++)
            {
                projectionEvent = provider.Get(projection);

                Assert.That(projectionEvent, Is.Not.Null);
                Assert.That(projectionAggregation.IsEmpty, Is.False);

                projection.Process(eventEnvelope, new TestEvent(), projectionEvent.PrimitiveEvent, this);

                projectionAggregation.ProcessSequenceNumberTail();
            }

            projectionEvent = provider.Get(projection);

            Assert.That(projectionEvent.HasPrimitiveEvent, Is.False);
            Assert.That(projectionAggregation.IsEmpty, Is.True);
        }