public void GetCloudQueue_HandlesInvalidQueueName()
        {
            // Act
            var ex = Assert.Throws <InvalidOperationException>(() => _manager.GetCloudQueue("UseDevelopmentStorage=true;", "I n v a l i d / N a m e"));

            // Assert
            Assert.StartsWith("Could not initialize connection to Microsoft Azure Storage: The requested URI does not represent any resource on the server. ", ex.Message);
        }
        /// <summary>
        /// Intended for unit test purposes
        /// </summary>
        internal AzureWebHookDequeueManager(string connectionString, ILogger logger, TimeSpan pollingFrequency, TimeSpan messageTimeout, int maxAttempts, HttpClient httpClient, IStorageManager storageManager, WebHookSender sender)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (pollingFrequency <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(pollingFrequency));
            }
            if (messageTimeout <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(messageTimeout));
            }

            _logger           = logger;
            _pollingFrequency = pollingFrequency;
            _messageTimeout   = messageTimeout;
            _maxAttempts      = maxAttempts;

            _httpClient     = httpClient ?? new HttpClient();
            _storageManager = storageManager ?? new StorageManager(logger);
            _sender         = sender ?? new QueuedSender(this, logger);

            _queue = _storageManager.GetCloudQueue(connectionString, AzureWebHookSender.WebHookQueue);
        }
Пример #3
0
        /// <inheritdoc />
        public async Task SendWebHookWorkItemsAsync(IEnumerable <WebHookWorkItem> workItems)
        {
            if (workItems == null)
            {
                throw new ArgumentNullException(nameof(workItems));
            }

            // Serialize WebHook requests and convert to queue messages
            IEnumerable <CloudQueueMessage> messages = null;

            try
            {
                messages = workItems.Select(item =>
                {
                    string content            = JsonConvert.SerializeObject(item, _serializerSettings);
                    CloudQueueMessage message = new CloudQueueMessage(content);
                    return(message);
                }).ToArray();
            }
            catch (Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.AzureSender_SerializeFailure, ex.Message);
                _logger.Error(msg, ex);
                throw new InvalidOperationException(msg);
            }

            // Insert queue messages into queue.
            CloudQueue queue = _manager.GetCloudQueue(_connectionString, WebHookQueue);
            await _manager.AddMessagesAsync(queue, messages);
        }
Пример #4
0
        /// <summary>
        /// Intended for unit test purposes
        /// </summary>
        internal AzureWebHookDequeueManager(string connectionString, ILogger logger, TimeSpan pollingFrequency, TimeSpan messageTimeout, int maxAttempts, HttpClient httpClient, IStorageManager storageManager)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (pollingFrequency <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("pollingFrequency");
            }
            if (messageTimeout <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("messageTimeout");
            }

            _logger = logger;
            _pollingFrequency = pollingFrequency;
            _messageTimeout = messageTimeout;
            _maxAttempts = maxAttempts;

            _httpClient = httpClient ?? new HttpClient();
            _storageManager = storageManager ?? new StorageManager(logger);

            _queue = _storageManager.GetCloudQueue(connectionString, AzureWebHookSender.WebHookQueue);
            _sender = new QueuedSender(this, logger);
        }