public void Apply_WhenNull_ReturnsNull() { // Arrange // Act // Assert Assert.Empty(_aggregate.Apply(_average, null)); }
public AggregateActor() { Behavior = new BehaviorQueue(Become); Behavior.Become(AwaitingCommandBehavior, nameof(AwaitingCommandBehavior)); PersistenceId = Self.Path.Name; Id = EntityActorName.Parse <TAggregate>(Self.Path.Name).Id; var aggregateExtensions = Context.System.GetAggregatesExtension(); var dependencies = aggregateExtensions.GetDependencies <TAggregate>(); Aggregate = dependencies.AggregateFactory.Build(); Recover <DomainEvent>(e => Aggregate.Apply(e)); }
private void ProcessingCommandBehavior() { Command <IReadOnlyCollection <IDomainEvent> >(domainEvents => { Log.Debug("command executed, starting to persist events"); if (!domainEvents.Any()) { Log.Warning("Trying to persist events but no events is presented. {@context}", ExecutionContext); return; } int messagesToPersistCount = domainEvents.Count; PersistAll(domainEvents, persistedEvent => { if (Aggregate.Version == persistedEvent.Version) { Aggregate.Apply(persistedEvent); } if (--messagesToPersistCount != 0) { return; } CompleteExecution(); }); }); //aggregate raised an error during command execution Command <Status.Failure>(f => { StopOnException(f.Cause); }); CommandAny(StashMessage); }
public Cart(CartId id) { _aggregate = new Aggregate(id.Value, new AggregateName(GetType().Name)); _aggregate.Apply(new NewCartStarted(id, new PurchaseTotal(0.0m))); }