Exemple #1
0
        public void given_command_publisher_fails_SaveProcessManagerAndPublishCommands_invokes_exception_handler()
        {
            // Arrange
            var processManager = new FooProcessManager();
            CancellationToken cancellationToken = CancellationToken.None;
            Exception         exception         = new InvalidOperationException();
            ICommandPublisher commandPublisher  = Mock.Of <ICommandPublisher>();

            Mock.Get(commandPublisher)
            .Setup(x => x.FlushCommands(processManager.Id, cancellationToken))
            .ThrowsAsync(exception);

            ICommandPublisherExceptionHandler commandPublisherExceptionHandler = Mock.Of <ICommandPublisherExceptionHandler>();

            var sut = new SqlProcessManagerDataContext <FooProcessManager>(
                new FooProcessManagerDbContext(),
                new JsonMessageSerializer(),
                commandPublisher,
                commandPublisherExceptionHandler);

            // Act
            Func <Task> action = () =>
                                 sut.SaveProcessManagerAndPublishCommands(processManager, cancellationToken: cancellationToken);

            // Assert
            action.ShouldThrow <InvalidOperationException>().Which.Should().BeSameAs(exception);
            Mock.Get(commandPublisherExceptionHandler).Verify(
                x =>
                x.Handle(It.Is <CommandPublisherExceptionContext>(
                             p =>
                             p.ProcessManagerType == typeof(FooProcessManager) &&
                             p.ProcessManagerId == processManager.Id &&
                             p.Exception == exception)),
                Times.Once());
        }
Exemple #2
0
 public SqlProcessManagerDataContext(
     ProcessManagerDbContext dbContext,
     IMessageSerializer serializer,
     ICommandPublisher commandPublisher,
     ICommandPublisherExceptionHandler commandPublisherExceptionHandler)
 {
     _dbContext        = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _serializer       = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _commandPublisher = commandPublisher ?? throw new ArgumentNullException(nameof(commandPublisher));
     _commandPublisherExceptionHandler = commandPublisherExceptionHandler ?? throw new ArgumentNullException(nameof(commandPublisherExceptionHandler));
 }
Exemple #3
0
        public async Task Handle_relays_to_asynchronous_action_correctly()
        {
            ICommandPublisherExceptionHandler             handler = Mock.Of <ICommandPublisherExceptionHandler>();
            Func <CommandPublisherExceptionContext, Task> action  = handler.Handle;
            var sut     = new DelegatingCommandPublisherExceptionHandler(action);
            var fixture = new Fixture();
            CommandPublisherExceptionContext context = fixture.Create <CommandPublisherExceptionContext>();

            await sut.Handle(context);

            Mock.Get(handler).Verify(x => x.Handle(context), Times.Once());
        }
        public CompositeCommandPublisherExceptionHandler(params ICommandPublisherExceptionHandler[] handlers)
        {
            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            var handlerList = new List <ICommandPublisherExceptionHandler>(handlers);

            for (int i = 0; i < handlerList.Count; i++)
            {
                ICommandPublisherExceptionHandler handler = handlerList[i];
                if (handler == null)
                {
                    throw new ArgumentException(
                              $"{nameof(handlers)} cannot contain null.",
                              nameof(handlers));
                }
            }

            _handlers = handlerList;
        }