コード例 #1
0
        /// <inheritdoc cref="IErrorPolicyChainBuilder.ThenStop" />
        public IErrorPolicyChainBuilder ThenStop(Action <StopConsumerErrorPolicy>?policyConfigurationAction = null)
        {
            var policy = new StopConsumerErrorPolicy();

            policyConfigurationAction?.Invoke(policy);
            _errorPolicies.Add(policy);
            return(this);
        }
コード例 #2
0
        public async Task HandleErrorAsync_Whatever_FalseReturned()
        {
            var policy   = new StopConsumerErrorPolicy().Build(_serviceProvider);
            var envelope = new InboundEnvelope(
                "hey oh!",
                new MemoryStream(),
                null,
                new TestOffset(),
                TestConsumerEndpoint.GetDefault(),
                TestConsumerEndpoint.GetDefault().Name);

            var result = await policy.HandleErrorAsync(
                ConsumerPipelineContextHelper.CreateSubstitute(envelope, _serviceProvider),
                new InvalidOperationException("test"));

            result.Should().BeFalse();
        }
コード例 #3
0
        public void CanHandle_Whatever_TrueReturned()
        {
            var policy   = new StopConsumerErrorPolicy().Build(_serviceProvider);
            var envelope = new InboundEnvelope(
                "hey oh!",
                new MemoryStream(),
                null,
                new TestOffset(),
                TestConsumerEndpoint.GetDefault(),
                TestConsumerEndpoint.GetDefault().Name);

            var canHandle = policy.CanHandle(
                ConsumerPipelineContextHelper.CreateSubstitute(envelope, _serviceProvider),
                new InvalidOperationException("test"));

            canHandle.Should().BeTrue();
        }
コード例 #4
0
        public async Task HandleErrorAsync_Whatever_TransactionNotCommittedNorAborted()
        {
            /* The consumer will be stopped and the transaction aborted by the consumer/behavior */

            var policy   = new StopConsumerErrorPolicy().Build(_serviceProvider);
            var envelope = new InboundEnvelope(
                "hey oh!",
                new MemoryStream(Encoding.UTF8.GetBytes("hey oh!")),
                null,
                new TestOffset(),
                new TestConsumerEndpoint("source-endpoint"),
                "source-endpoint");

            var transactionManager = Substitute.For <IConsumerTransactionManager>();

            await policy.HandleErrorAsync(
                ConsumerPipelineContextHelper.CreateSubstitute(envelope, _serviceProvider, transactionManager),
                new InvalidOperationException("test"));

            await transactionManager.ReceivedWithAnyArgs(0).RollbackAsync(Arg.Any <InvalidOperationException>());
        }