コード例 #1
0
        public async Task WriteMessageCreatesQueueMessageTest()
        {
            const string queueName = "newcategories";
            var          category  = Model.Create <Category>();
            var          expected  = category.Group + Environment.NewLine + category.Name;

            var target = new NewCategoryQueue(Config.Storage);

            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);
            var client         = storageAccount.CreateCloudQueueClient();
            var queue          = client.GetQueueReference(queueName);

            await target.WriteMessage(category, CancellationToken.None).ConfigureAwait(false);

            var queueItem = await queue.GetMessageAsync().ConfigureAwait(false);

            while (queueItem != null)
            {
                var actual = queueItem.AsString;

                if (actual == expected)
                {
                    // We found the item
                    return;
                }

                // Check the next queue item
                queueItem = await queue.GetMessageAsync().ConfigureAwait(false);
            }

            throw new InvalidOperationException("Expected queue item was not found.");
        }
コード例 #2
0
        public void WriteMessageThrowsExceptionWithNullCategoryTest()
        {
            var target = new NewCategoryQueue(Config.Storage);

            Func <Task> action = async() =>
                                 await target.WriteMessage(null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }