Exemple #1
0
 protected void RegisterUncommitedEvents(params E[] events)
 {
     foreach (var @event in events)
     {
         UncommitedEvents.Add(@event);
     }
 }
Exemple #2
0
        public override Game ApplyEvent(GameEvent arg)
        {
            Game game = this;

            if (arg is TurnChanged turnChanged)
            {
                _turn = turnChanged.Turn;
                UncommitedEvents.Add(turnChanged);
            }
            if (arg is DiceRolled diceRolled)
            {
                if (!_rolledNumbers.Exists(x => x.Key.Equals(diceRolled.Player)))
                {
                    _rolledNumbers.Add(new KeyValuePair <PlayerId, int>(diceRolled.Player, diceRolled.RolledNumber));
                }

                UncommitedEvents.Add(diceRolled);
            }
            if (arg is TurnCountdownUpdated turnCountdownUpdated)
            {
                _turn.SecondsLeft = turnCountdownUpdated.SecondsLeft;
                UncommitedEvents.Add(turnCountdownUpdated);
            }
            if (arg is GameFinished gameFinished)
            {
                UncommitedEvents.Add(gameFinished);
                return(new FinishedGame(GameId, _players, gameFinished.Winners, UncommitedEvents));
            }
            if (arg is TurnTimedOut)
            {
                UncommitedEvents.Add(arg);
            }
            return(game);
        }
Exemple #3
0
 public override Game ApplyEvent(GameEvent arg)
 {
     if (arg is GameStarted gameStarted)
     {
         UncommitedEvents.Add(gameStarted);
         return(new RunningGame(GameId, gameStarted.Players, gameStarted.InitialTurn, UncommitedEvents));
     }
     return(this);
 }
Exemple #4
0
        protected void Delete(TDeleteEvent deleteEvent)
        {
            if (_isDeleted)
            {
                return;
            }

            var @event = deleteEvent;

            UncommitedEvents.Add(@event);
            Apply(@event);
        }
Exemple #5
0
        protected void Update(TUpdateEvent updateEvent)
        {
            var @event = updateEvent;

            if (_lastUpdate != null && @event.Equals(_lastUpdate))
            {
                return;
            }

            UncommitedEvents.Add(@event);
            Apply(@event);
        }
        public void Publish(UncommitedEvents events)
        {
            foreach (var eEvent in events.GetStream())
            {
                if (_eventStore.GetLastSequence(eEvent.AggregateId) >= eEvent.Sequence)
                {
                    throw new ConsistencyException(eEvent);
                }

                _eventStore.Save(eEvent);
                _dispatcher.Dispatch(eEvent);
            }
        }
Exemple #7
0
        public void throw_error_if_sequence_not_consistent_with_event_store()
        {
            var store    = new FakeEventStore();
            var eventBus = new EventBus(new EventDispatcher(), store);

            var uncommitedEvent = new UncommitedEvents();

            var guid = Guid.NewGuid();

            uncommitedEvent.Add(new TestDomainEvent(guid, 1));
            uncommitedEvent.Add(new TestDomainEvent(guid, 2));
            uncommitedEvent.Add(new TestDomainEvent(guid, 3));
            eventBus.Publish(uncommitedEvent);

            uncommitedEvent.Add(new TestDomainEvent(guid, 3));
            var publish = (Action)(() => eventBus.Publish(uncommitedEvent));

            publish.ShouldThrow <ConsistencyException>();
        }
Exemple #8
0
 public void MarkCommitted(E @event)
 {
     UncommitedEvents.Remove(@event);
 }