public QueueListenerTests()
        {
            CloudQueue queue = new CloudQueue(new Uri("https://test.queue.core.windows.net/testqueue"));
            Mock<IStorageQueue> mockQueue = new Mock<IStorageQueue>(MockBehavior.Strict);
            mockQueue.Setup(p => p.SdkObject).Returns(queue);

            _mockTriggerExecutor = new Mock<ITriggerExecutor<IStorageQueueMessage>>(MockBehavior.Strict);
            Mock<IDelayStrategy> mockDelayStrategy = new Mock<IDelayStrategy>(MockBehavior.Strict);
            Mock<IBackgroundExceptionDispatcher> mockExceptionDispatcher = new Mock<IBackgroundExceptionDispatcher>(MockBehavior.Strict);
            TextWriter log = new StringWriter();
            Mock<IQueueProcessorFactory> mockQueueProcessorFactory = new Mock<IQueueProcessorFactory>(MockBehavior.Strict);
            JobHostQueuesConfiguration queuesConfig = new JobHostQueuesConfiguration();
            QueueProcessorFactoryContext context = new QueueProcessorFactoryContext(queue, log, queuesConfig);

            _mockQueueProcessor = new Mock<QueueProcessor>(MockBehavior.Strict, context);
            JobHostQueuesConfiguration queueConfig = new JobHostQueuesConfiguration
            {
                MaxDequeueCount = 5,
                QueueProcessorFactory = mockQueueProcessorFactory.Object
            };

            mockQueueProcessorFactory.Setup(p => p.Create(It.IsAny<QueueProcessorFactoryContext>())).Returns(_mockQueueProcessor.Object);

            _listener = new QueueListener(mockQueue.Object, null, _mockTriggerExecutor.Object, mockDelayStrategy.Object, mockExceptionDispatcher.Object, log, null, queueConfig);

            CloudQueueMessage cloudMessage = new CloudQueueMessage("TestMessage");
            _storageMessage = new StorageQueueMessage(cloudMessage);
        }
 /// <inheritdoc/>
 public virtual QueueProcessor Create(QueueProcessorFactoryContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     return new QueueProcessor(context);
 }
 public FakeQueueProcessor(QueueProcessorFactoryContext context, IStorageAccount storageAccount) :
     base(context)
 {
     // map the queue names from the context to fake queues
     IStorageQueueClient client = storageAccount.CreateQueueClient();
     _queue = client.GetQueueReference(context.Queue.Name);
     if(context.PoisonQueue != null)
     {
         _poisonQueue = client.GetQueueReference(context.PoisonQueue.Name);
     }
 }
        /// <summary>
        /// Constructs a new instance
        /// </summary>
        /// <param name="context">The factory context.</param>
        public QueueProcessor(QueueProcessorFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _queue = context.Queue;
            _poisonQueue = context.PoisonQueue;
            _log = context.Log;
            _maxDequeueCount = context.MaxDequeueCount;
            BatchSize = context.BatchSize;
            NewBatchThreshold = context.NewBatchThreshold;
        }
        public void Constructor_DefaultsValues()
        {
            CloudQueue queue = new CloudQueue(new Uri("https://test.queue.core.windows.net/testqueue"));
            CloudQueue poisonQueue = new CloudQueue(new Uri("https://test.queue.core.windows.net/poisonqueue"));
            TextWriter log = new StringWriter();
            JobHostQueuesConfiguration queuesConfig = new JobHostQueuesConfiguration();

            QueueProcessorFactoryContext context = new QueueProcessorFactoryContext(queue, log, queuesConfig, poisonQueue);

            Assert.Same(queue, context.Queue);
            Assert.Same(log, context.Log);
            Assert.Same(poisonQueue, context.PoisonQueue);

            Assert.Equal(queuesConfig.BatchSize, context.BatchSize);
            Assert.Equal(queuesConfig.NewBatchThreshold, context.NewBatchThreshold);
            Assert.Equal(queuesConfig.MaxDequeueCount, context.MaxDequeueCount);
        }
            public QueueProcessor Create(QueueProcessorFactoryContext context)
            {
                // demonstrates how the Queue.ServiceClient options can be configured
                context.Queue.ServiceClient.DefaultRequestOptions.ServerTimeout = TimeSpan.FromSeconds(30);

                // demonstrates how queue options can be customized
                context.Queue.EncodeMessage = true;

                if (context.Queue.Name == "initialorder")
                {
                    // demonstrates how batch processing behavior can be customized
                    // per queue (as opposed to the global settings that apply to ALL queues)
                    context.BatchSize = 30;
                    context.NewBatchThreshold = 100;

                    return new CustomQueueProcessor(context);
                }

                // return the default processor
                return new QueueProcessor(context);
            }
 public CustomQueueProcessor(QueueProcessorFactoryContext context) : base(context)
 {
     Context = context;
 }
 public QueueProcessor Create(QueueProcessorFactoryContext context)
 {
     return new CustomQueueProcessor(context);
 }
 public override QueueProcessor Create(QueueProcessorFactoryContext context)
 {
     return new FakeQueueProcessor(context, _storageAccount);
 }