public async Task When_Handling_A_Command_With_A_Command_Store_Enabled_Async()
        {
            await _commandProcessor.SendAsync(_command);

            // should_store_the_command_to_the_command_store
            _commandStore.GetAsync <MyCommand>(_command.Id).Result.Value.Should().Be(_command.Value);
        }
        public void When_Handling_A_Command_With_A_Command_Store_Enabled_Async()
        {
            AsyncContext.Run(async() => await _commandProcessor.SendAsync(_command));

            // should_store_the_command_to_the_command_store
            Assert.AreEqual(_command.Value, _commandStore.GetAsync <MyCommand>(_command.Id).Result.Value);
        }
        public async Task When_Writing_To_The_Command_StoreAsync()
        {
            await commandStore.AddAsync(_raisedCommand);

            _storedCommand = await commandStore.GetAsync <MyCommand>(_raisedCommand.Id);

            _storedCommand.Should().NotBeNull();
            _storedCommand.Value.Should().Be(_raisedCommand.Value);
            _storedCommand.Id.Should().Be(_raisedCommand.Id);
        }
        /// <summary>
        /// Awaitably logs the command we received to the command store.
        /// </summary>
        /// <param name="command">The command that we want to store.</param>
        /// <param name="cancellationToken">Allows the caller to cancel the pipeline if desired</param>
        /// <returns>The parameter to allow request handlers to be chained together in a pipeline</returns>
        public override async Task <T> HandleAsync(T command, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_onceOnly)
            {
                _logger.Value.DebugFormat("Checking if command {0} has already been seen", command.Id);
                //TODO: We should not use an infinite timeout here - how to configure
                var existingCommand = await _commandStore.GetAsync <T>(command.Id, -1, cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

                if (existingCommand.Id != Guid.Empty)
                {
                    _logger.Value.DebugFormat("Command {0} has already been seen", command.Id);
                    throw new OnceOnlyException($"A command with id {command.Id} has already been handled");
                }
            }

            _logger.Value.DebugFormat("Writing command {0} to the Command Store", command.Id);

            //TODO: We should not use an infinite timeout here - how to configure
            await _commandStore.AddAsync(command, -1, cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

            return(await base.HandleAsync(command, cancellationToken).ConfigureAwait(ContinueOnCapturedContext));
        }