Beispiel #1
0
        public void CanHandle_WithMaxFailedAttempts_ExpectedResultReturned(
            int failedAttempts,
            bool expectedResult)
        {
            var envelope = new InboundEnvelope(
                new MemoryStream(),
                new[]
                {
                    new MessageHeader(
                        DefaultMessageHeaders.FailedAttempts,
                        failedAttempts.ToString(CultureInfo.InvariantCulture))
                },
                new TestOffset(),
                TestConsumerEndpoint.GetDefault(),
                TestConsumerEndpoint.GetDefault().Name);

            var policy = new TestErrorPolicy()
                .MaxFailedAttempts(3)
                .Build(Substitute.For<IServiceProvider>());

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

            canHandle.Should().Be(expectedResult);
        }
        public void ApplyTo_Exception_CanHandleReturnsExpectedResult(Exception exception, bool mustApply)
        {
            var policy = new TestErrorPolicy()
                         .ApplyTo <ArgumentException>()
                         .ApplyTo <InvalidCastException>();

            var canHandle = policy.CanHandle(new InboundMessage {
                Message = new TestEventOne(), FailedAttempts = 99
            }, exception);

            canHandle.Should().Be(mustApply);
        }
Beispiel #3
0
        public void ApplyTo_Exception_CanHandleReturnsExpectedResult(Exception exception, bool mustApply)
        {
            var policy = new TestErrorPolicy()
                         .ApplyTo <ArgumentException>()
                         .ApplyTo <InvalidCastException>();

            var canHandle = policy.CanHandle(
                new InboundMessage(
                    new byte[1],
                    new[] { new MessageHeader(MessageHeader.FailedAttemptsKey, "99") },
                    null, TestEndpoint.GetDefault(), true),
                exception);

            canHandle.Should().Be(mustApply);
        }
Beispiel #4
0
        public void CanHandle_WithApplyWhen_ExpectedResultReturned(
            IInboundEnvelope envelope,
            Exception exception,
            bool mustApply)
        {
            var policy = new TestErrorPolicy()
                         .ApplyWhen(
                (msg, ex) =>
                msg.Headers.GetValue <int>(DefaultMessageHeaders.FailedAttempts) <= 5 && ex.Message != "no")
                         .Build(Substitute.For <IServiceProvider>());

            var canHandle = policy.CanHandle(
                ConsumerPipelineContextHelper.CreateSubstitute(envelope),
                exception);

            canHandle.Should().Be(mustApply);
        }
Beispiel #5
0
        public void CanHandle_WithApplyTo_ExpectedResultReturned(Exception exception, bool mustApply)
        {
            var policy = new TestErrorPolicy()
                         .ApplyTo <ArgumentException>()
                         .ApplyTo <InvalidCastException>()
                         .Build(Substitute.For <IServiceProvider>());

            var canHandle = policy.CanHandle(
                ConsumerPipelineContextHelper.CreateSubstitute(
                    new InboundEnvelope(
                        new MemoryStream(),
                        new[] { new MessageHeader(DefaultMessageHeaders.FailedAttempts, "99") },
                        new TestOffset(),
                        TestConsumerEndpoint.GetDefault(),
                        TestConsumerEndpoint.GetDefault().Name)),
                exception);

            canHandle.Should().Be(mustApply);
        }