예제 #1
0
 public void ProjectOneDocumentNotFound(IDocument <Guid> document, TestProjection projection)
 {
     this.Given(_ => RepositoryContains(document))
     .When(_ => ProjectOne(document.GetType(), d => d.Version.Equals(-1), p => new TestProjection
     {
         Id      = p.Id,
         Version = p.Version
     }))
     .Then(_ => DocumentNotProjected())
     .BDDfy();
 }
예제 #2
0
        public void Build_WithCertainDependencyLifetimeScopeFactory_ShouldGetPassedToProjectorInstance()
        {
            var projection = new TestProjection("A");
            var builder    = new ProjectorBuilder <string, FakeMessageEnvelope>();

            builder.Register(projection).SetDependencyLifetimeScopeFactory(_factoryMock.Object);

            var projector = builder.Build <TestNextSequenceNumberRepository>();

            Assert.That(projector.DependencyLifetimeScopeFactory, Is.EqualTo(_factoryMock.Object));
        }
            public void Should_add_using_only_projection_property_name()
            {
                // Arrange
                var message = new TestMessage {MappedByName = 10};
                var projection = new TestProjection {MappedByName = 10};
                var builder = new AddNewProjectionStrategyArguments<TestMessage, TestProjection>();
                builder.Add(p => p.MappedByName);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(20, projection.MappedByName);
            }
            public void Should_decrement_projection()
            {
                // Arrange
                var message = new TestMessage();
                var projection = new TestProjection {ProjectionProperty = 5};
                var builder = new AddNewProjectionStrategyArguments<TestMessage, TestProjection>();
                builder.Decrement(p => p.ProjectionProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(4, projection.ProjectionProperty);
            }
            public void Should_add_to_projection()
            {
                // Arrange
                var message = new TestMessage {MessageProperty = 5};
                var projection = new TestProjection {ProjectionProperty = 5};
                var builder = new AddNewProjectionStrategyArguments<TestMessage, TestProjection>();
                builder.Add(p => p.ProjectionProperty, e => e.MessageProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(10, projection.ProjectionProperty);
            }
            public void Should_do_lambda_expression()
            {
                // Arrange
                var message = new TestMessage {MessageProperty = 5};
                var projection = new TestProjection {ProjectionProperty = 5};
                var builder = new AddNewProjectionStrategyArguments<TestMessage, TestProjection>();
                builder.Do((e, p) => p.ProjectionProperty = p.ProjectionProperty*e.MessageProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(25, projection.ProjectionProperty);
            }
예제 #7
0
            public void Init()
            {
                var message = new TestMessage
                {
                    ValueInt32 = 777,
                    ValueInt64 = 888
                };

                _targetProjection = new TestProjection();
                _targetProvider   = new TestProvider(_targetProjection);
                var persistenceFactory = new TestProvidersFactory(_targetProvider);

                new TestHandler(persistenceFactory).Handle(message);
            }
예제 #8
0
            public void Should_set_to_projection()
            {
                // Arrange
                var message    = new TestMessage();
                var projection = new TestProjection();
                var builder    = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Set(p => p.ProjectionProperty, 555);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(555, projection.ProjectionProperty);
            }
예제 #9
0
 protected async Task ProjectOne(Type type, Expression <Func <IDocument <Guid>, bool> > predicate,
                                 Expression <Func <IDocument <Guid>, TestProjection> > projection)
 {
     if (type.IsATypeOf(typeof(Parent)))
     {
         _projection = await _unitOfWork.ProjectOneAsync <Parent, TestProjection>(predicate, projection);
     }
     if (type.IsATypeOf(typeof(Child)))
     {
         _projection = await _unitOfWork.ProjectOneAsync <Child, TestProjection>(predicate, projection);
     }
     if (type.IsATypeOf(typeof(Event)))
     {
         _projection = await _unitOfWork.ProjectOneAsync <Event, TestProjection>(predicate, projection);
     }
 }
예제 #10
0
            public void Should_map_to_projection()
            {
                // Arrange
                var message = new TestMessage {
                    MessageProperty = 777
                };
                var projection = new TestProjection();
                var builder    = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Map(p => p.ProjectionProperty, e => e.MessageProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(message.MessageProperty, projection.ProjectionProperty);
            }
예제 #11
0
            public void Should_map_using_only_projection_property_name()
            {
                // Arrange
                var message = new TestMessage {
                    MappedByName = 555
                };
                var projection = new TestProjection();
                var builder    = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Map(p => p.MappedByName);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(message.MappedByName, projection.MappedByName);
            }
예제 #12
0
            public void Should_decrement_projection()
            {
                // Arrange
                var message    = new TestMessage();
                var projection = new TestProjection {
                    ProjectionProperty = 5
                };
                var builder = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Decrement(p => p.ProjectionProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(4, projection.ProjectionProperty);
            }
예제 #13
0
        public void Handle_TwoDifferentMessages_ShouldCallCorrectHandlerWithCorrectArguments()
        {
            var           connectionMock    = new Mock <FakeConnection>();
            Func <object> connectionFactory = () => connectionMock.Object;
            var           token             = new CancellationToken();
            var           messageA          = new RegisteredMessageA();
            var           messageB          = new RegisteredMessageB();
            var           messageEnvelopeA  = new FakeMessageEnvelope(1, messageA);
            var           messageEnvelopeB  = new FakeMessageEnvelope(2, messageB);

            IProjection <string, FakeMessageEnvelope> projection = new TestProjection("A");

            projection.Handle(connectionFactory, messageEnvelopeA, token);
            projection.Handle(connectionFactory, messageEnvelopeB, token);

            connectionMock.Verify(x => x.UpdateA(messageEnvelopeA, messageA), Times.Once);
            connectionMock.Verify(x => x.UpdateB(messageEnvelopeB, messageB, token), Times.Once);
        }
예제 #14
0
            public void Should_do_lambda_expression()
            {
                // Arrange
                var message = new TestMessage {
                    MessageProperty = 5
                };
                var projection = new TestProjection {
                    ProjectionProperty = 5
                };
                var builder = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Do((e, p) => p.ProjectionProperty = p.ProjectionProperty * e.MessageProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(25, projection.ProjectionProperty);
            }
예제 #15
0
            public void Should_substract_from_projection()
            {
                // Arrange
                var message = new TestMessage {
                    MessageProperty = 5
                };
                var projection = new TestProjection {
                    ProjectionProperty = 15
                };
                var builder = new AddNewProjectionStrategyArguments <TestMessage, TestProjection>();

                builder.Substract(p => p.ProjectionProperty, e => e.MessageProperty);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(10, projection.ProjectionProperty);
            }
            public void Should_substract_from_projection()
            {
                // Arrange
                var @event = new TestEvent {EventProperty = 5};
                var projection = new TestProjection {ProjectionProperty = 15};
                var builder = new AddNewProjectionStrategyArguments<TestEvent, TestProjection>();
                builder.Substract(p => p.ProjectionProperty, e => e.EventProperty);

                // Act
                builder.Mappers.Map(@event, projection);

                // Assert
                Assert.AreEqual(10, projection.ProjectionProperty);
            }
예제 #17
0
 public TestProjectionBuilder()
 {
     _projection = new TestProjection();
 }
예제 #18
0
 protected void DocumentProjected(TestProjection expected) =>
 _projection.Should().BeEquivalentTo(expected);
            public void Should_increment_projection()
            {
                // Arrange
                var @event = new TestEvent();
                var projection = new TestProjection {ProjectionProperty = 5};
                var builder = new AddNewProjectionStrategyArguments<TestEvent, TestProjection>();
                builder.Increment(p => p.ProjectionProperty);

                // Act
                builder.Mappers.Map(@event, projection);

                // Assert
                Assert.AreEqual(6, projection.ProjectionProperty);
            }
            public void Should_set_to_projection()
            {
                // Arrange
                var message = new TestMessage();
                var projection = new TestProjection();
                var builder = new AddNewProjectionStrategyArguments<TestMessage, TestProjection>();
                builder.Set(p => p.ProjectionProperty, 555);

                // Act
                builder.Mappers.Map(message, projection);

                // Assert
                Assert.AreEqual(555, projection.ProjectionProperty);
            }
            public void Should_substract_using_only_projection_property_name()
            {
                // Arrange
                var @event = new TestEvent {MappedByName = 5};
                var projection = new TestProjection {MappedByName = 15};
                var builder = new AddNewProjectionStrategyArguments<TestEvent, TestProjection>();
                builder.Substract(p => p.MappedByName);

                // Act
                builder.Mappers.Map(@event, projection);

                // Assert
                Assert.AreEqual(10, projection.MappedByName);
            }
            public void Should_map_to_projection()
            {
                // Arrange
                var @event = new TestEvent {EventProperty = 777};
                var projection = new TestProjection();
                var builder = new AddNewProjectionStrategyArguments<TestEvent, TestProjection>();
                builder.Map(p => p.ProjectionProperty, e => e.EventProperty);

                // Act
                builder.Mappers.Map(@event, projection);

                // Assert
                Assert.AreEqual(@event.EventProperty, projection.ProjectionProperty);
            }
예제 #23
0
 public TestProvider(TestProjection readProjection)
 {
     ReadProjection = readProjection;
 }