Example #1
0
            public void ReloadAggregateOnConcurrencyException()
            {
                var save      = 0;
                var command   = new FakeCommand();
                var aggregate = new FakeAggregate();
                var envelope  = new CommandEnvelope(GuidStrategy.NewGuid(), command);
                var message   = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);
                var ex        = new ConcurrencyException();

                HandlerRegistry.Setup(mock => mock.GetHandlerFor(command)).Returns(new CommandHandler(typeof(FakeAggregate), typeof(FakeCommand), AggregateStore.Object, (a, c) => ((FakeAggregate)a).Handle((FakeCommand)c)));
                AggregateStore.Setup(mock => mock.Get(typeof(FakeAggregate), envelope.AggregateId)).Returns(aggregate);
                AggregateStore.Setup(mock => mock.Save(aggregate, It.IsAny <CommandContext>())).Callback(() =>
                {
                    if (++save == 1)
                    {
                        throw ex;
                    }
                });

                Processor.Process(message);

                AggregateStore.Verify(mock => mock.Get(typeof(FakeAggregate), envelope.AggregateId), Times.Exactly(2));
            }