예제 #1
0
 public void Apply_WhenNull_ReturnsNull()
 {
     // Arrange
     // Act
     // Assert
     Assert.Empty(_aggregate.Apply(_average, null));
 }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
 public Cart(CartId id)
 {
     _aggregate = new Aggregate(id.Value, new AggregateName(GetType().Name));
     _aggregate.Apply(new NewCartStarted(id, new PurchaseTotal(0.0m)));
 }