Exemplo n.º 1
0
            public void RetrieveCommandHandlerBasedOnCommandType()
            {
                var command   = new FakeCommand();
                var aggregate = new FakeAggregate();
                var envelope  = new CommandEnvelope(GuidStrategy.NewGuid(), command);
                var message   = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                HandlerRegistry.Setup(mock => mock.GetHandlerFor(command)).Returns(new CommandHandler(typeof(FakeAggregate), typeof(FakeCommand), AggregateStore.Object, (a, c) => { }));
                AggregateStore.Setup(mock => mock.Get(typeof(FakeAggregate), envelope.AggregateId)).Returns(aggregate);

                Processor.Process(message);

                HandlerRegistry.Verify(mock => mock.GetHandlerFor(command), Times.Once());
            }
Exemplo n.º 2
0
            public void WillTimeoutEventuallyIfCannotSave()
            {
                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 processor = new CommandProcessor(HandlerRegistry.Object, TransientErrorRegistry.Object, new CommandProcessorSettings {
                    RetryTimeout = TimeSpan.FromMilliseconds(20)
                });

                SystemTime.ClearOverride();

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

                Assert.Throws <TimeoutException>(() => processor.Process(message));
            }
Exemplo n.º 3
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));
            }