Exemplo n.º 1
0
 public void LoadFromHistory(IEnumerable <object> events)
 {
     foreach (var @event in events)
     {
         AggregateUpdater.Update(this, @event);
         Version++;
     }
 }
Exemplo n.º 2
0
            public void CanApplyEventIfApplyMethodOptionalAndNotDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(OptionalApplyAggregate) });

                var updater   = new AggregateUpdater(typeLocator.Object);
                var aggregate = new OptionalApplyAggregate();
                var e         = new FakeEvent();

                updater.Apply(e, aggregate);
            }
Exemplo n.º 3
0
            public void ThrowMappingExceptionIfApplyMethodRequiredAndNotDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(RequiredApplyAggregate) });

                var e         = new FakeEvent();
                var aggregate = new RequiredApplyAggregate();
                var updater   = new AggregateUpdater(typeLocator.Object);
                var ex        = Assert.Throws <MappingException>(() => updater.Apply(e, aggregate));

                Assert.Equal(Exceptions.AggregateApplyMethodNotFound.FormatWith(typeof(RequiredApplyAggregate), typeof(FakeEvent)), ex.Message);
            }
Exemplo n.º 4
0
            public void CustomMappingStrategyUsedWhenExplicitStrategyDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new[] { typeof(ExplicitStrategyAggregate) });

                var updater   = new AggregateUpdater(typeLocator.Object);
                var aggregate = new ExplicitStrategyAggregate();
                var e         = new FakeEvent();

                updater.Apply(e, aggregate);

                Assert.Same(e, aggregate.AppliedEvents.Single());
            }
Exemplo n.º 5
0
            public void AggregateMustHaveAtLeastOneKnownApplyMethod()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny <Func <Type, Boolean> >())).Returns(new Type[0]);

                var updater   = new AggregateUpdater(typeLocator.Object);
                var aggregate = new ImplicitStrategyAggregate();
                var e         = new FakeEvent();

                var ex = Assert.Throws <MappingException>(() => updater.Apply(e, aggregate));

                Assert.Equal(Exceptions.AggregateTypeUndiscovered.FormatWith(typeof(ImplicitStrategyAggregate)), ex.Message);
            }
            public void AggregateMustHaveAtLeastOneKnownApplyMethod()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new Type[0]);

                var updater = new AggregateUpdater(typeLocator.Object);
                var aggregate = new ImplicitStrategyAggregate();
                var e = new FakeEvent();

                var ex = Assert.Throws<MappingException>(() => updater.Apply(e, aggregate));

                Assert.Equal(Exceptions.AggregateTypeUndiscovered.FormatWith(typeof(ImplicitStrategyAggregate)), ex.Message);
            }
Exemplo n.º 7
0
 protected void Apply(object @event)
 {
     _uncommittedEvents.Add(@event);
     AggregateUpdater.Update(this, @event);
     Version++;
 }
            public void CustomMappingStrategyUsedWhenExplicitStrategyDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(ExplicitStrategyAggregate) });

                var updater = new AggregateUpdater(typeLocator.Object);
                var aggregate = new ExplicitStrategyAggregate();
                var e = new FakeEvent();

                updater.Apply(e, aggregate);

                Assert.Same(e, aggregate.AppliedEvents.Single());
            }
            public void ThrowMappingExceptionIfApplyMethodRequiredAndNotDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(RequiredApplyAggregate) });

                var e = new FakeEvent();
                var aggregate = new RequiredApplyAggregate();
                var updater = new AggregateUpdater(typeLocator.Object);
                var ex = Assert.Throws<MappingException>(() => updater.Apply(e, aggregate));

                Assert.Equal(Exceptions.AggregateApplyMethodNotFound.FormatWith(typeof(RequiredApplyAggregate), typeof(FakeEvent)), ex.Message);
            }
            public void CanApplyEventIfApplyMethodOptionalAndNotDefined()
            {
                typeLocator.Setup(mock => mock.GetTypes(It.IsAny<Func<Type, Boolean>>())).Returns(new[] { typeof(OptionalApplyAggregate) });

                var updater = new AggregateUpdater(typeLocator.Object);
                var aggregate = new OptionalApplyAggregate();
                var e = new FakeEvent();

                updater.Apply(e, aggregate);
            }