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