public void Should_not_handle_execution()
        {
            Func <Task> act = async() => await ServiceBusPolicy.Apply(ex => ex is ArgumentOutOfRangeException)
                              .WithMessage(_fixture.Msg)
                              .WithSender(_fixture.MessageSender)
                              .WithReceiver(_fixture.MessageReceiver)
                              .WithLockToken(_fixture.LockToken)
                              .RetryCount(2)
                              .OnException(async _ => { })
                              .ExecuteAsync(async() => throw new ArgumentNullException());

            act.Should().Throw <ArgumentNullException>();
        }
        public async Task Should_be_dead_lettered_when_total_reached_total_count()
        {
            var result = false;

            await ServiceBusPolicy.Apply()
            .WithMessage(_fixture.Msg)
            .WithSender(_fixture.MessageSender)
            .WithReceiver(_fixture.MessageReceiver)
            .WithLockToken(_fixture.LockToken)
            .RetryCount(0)
            .OnDeadLettering(async _ => result = true)
            .ExecuteAsync(async() => throw new Exception());

            result.Should().BeTrue();
        }
        public async Task Should_be_scheduled_by_interval_when_executied(int interval)
        {
            DateTimeOffset result = DateTimeOffset.Now;

            await ServiceBusPolicy.Apply()
            .WithMessage(_fixture.Msg)
            .WithSender(_fixture.MessageSender)
            .WithReceiver(_fixture.MessageReceiver)
            .WithLockToken(_fixture.LockToken)
            .RetryCount(2, interval)
            .OnScheduling(async(ex, scheduledTime) => result = scheduledTime)
            .ExecuteAsync(async() => throw new Exception());

            result.Second.Should().Be(DateTimeOffset.Now.AddSeconds(interval * 1).Second);
        }
        public async Task Should_handle_execution()
        {
            var exCount = 0;

            await ServiceBusPolicy.Apply()
            .WithMessage(_fixture.Msg)
            .WithSender(_fixture.MessageSender)
            .WithReceiver(_fixture.MessageReceiver)
            .WithLockToken(_fixture.LockToken)
            .RetryCount(2)
            .OnDeadLettering(async _ => { })
            .OnException(async _ => exCount++)
            .OnScheduling(async(_, __) => { })
            .ExecuteAsync(async() => await Delegates.DoNothing());

            exCount.Should().Be(0);
        }
        public static async Task Run(
            [ServiceBusTrigger("<your-topic-name>", "<your-sub-name>", Connection = "ServiceBusConnectionString")] Message message,
            MessageReceiver messageReceiver,
            string lockToken,
            [ServiceBus("<your-topic-name>", EntityType.Topic, Connection = "ServiceBusConnectionString")] MessageSender sender,
            ILogger log) =>

        await ServiceBusPolicy.Apply()
        .WithMessage(message)
        .WithSender(sender)
        .WithReceiver(messageReceiver)
        .WithLockToken(lockToken)
        .RetryCount(retryCount: 2, interval: 20)
        .OnDeadLettering(async _ => log.LogWarning("Deadlettering the msg"))
        .OnException(async ex => log.LogError(ex.Message))
        .OnScheduling(async(_, __) => log.LogWarning("Scheduling the msg"))
        .ExecuteAsync(async() =>
        {
            // ur code
            throw new System.InvalidOperationException();
        });