Exemple #1
0
        public async Task When_The_Message_Is_Already_In_The_Command_Store_Async()
        {
            await commandStore.AddAsync(_raisedCommand);

            //this shouldn't throw
            await commandStore.AddAsync(_raisedCommand);
        }
        /// <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 exists = await _commandStore.ExistsAsync <T>(command.Id, _contextKey, -1, cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

                if (exists && _onceOnlyAction is OnceOnlyAction.Throw)
                {
                    _logger.Value.DebugFormat("Command {0} has already been seen", command.Id);
                    throw new OnceOnlyException($"A command with id {command.Id} has already been handled");
                }

                if (exists && _onceOnlyAction is OnceOnlyAction.Warn)
                {
                    _logger.Value.WarnFormat("Command {0} has already been seen", command.Id);
                    return(command);
                }
            }

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

            T handledCommand = await base.HandleAsync(command, cancellationToken).ConfigureAwait(ContinueOnCapturedContext);

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

            return(handledCommand);
        }
        /// <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))
        {
            _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));
        }
        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);
        }