public void Handle(CompleteOrder message)
        {
            var order = repository.GetById<BaristaOrder>(message.Id);

            int committedVersion = message.OriginalVersion;

            order.CompletePreparation(committedVersion++);

            repository.Save(order);
        }
Ejemplo n.º 2
0
        public void Should_raise_prepared_event_when_barista_completes_preparation()
        {
            var id = Guid.NewGuid();
            var handler = new BaristaOrderCommandHandlers(repository);
            var e = new OrderPlaced(id, Guid.NewGuid(), 1);
            var eventHandler = new CashierOrderEventHandler(repository);
            eventHandler.Apply(e);

            var order = repository.GetById<BaristaOrder>(id);
            Assert.False(order.IsCompleted);

            var command = new CompleteOrder(id, order.Version);
            handler.Handle(command);

            order = repository.GetById<BaristaOrder>(id);
            Assert.True(order.IsCompleted);
        }
Ejemplo n.º 3
0
        public IHttpActionResult Post(Guid id, CompletePreparationCommand cmd)
        {
            try
            {
                var command = new CompleteOrder(id, cmd.Version);
                handler.Handle(command);

                return Ok();
            }
            catch (AggregateNotFoundException)
            {
                return NotFound();
            }
            catch (AggregateDeletedException)
            {
                return Conflict();
            }
        }