Exemple #1
0
 public void LoadFromHistory(IEnumerable <object> events)
 {
     foreach (var @event in events)
     {
         AggregateUpdater.Update(this, @event);
         Version++;
     }
 }
Exemple #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);
            }
Exemple #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);
            }
Exemple #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());
            }
Exemple #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);
            }
Exemple #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);
            }