public async Task Reuses_CloudQueue_ForSameQueueName_OnConcurentCalls() { // prepare const string queueName = "test-queue-1"; ConcurrentBag <CloudQueue> queueBag = new ConcurrentBag <CloudQueue>(); int count = 10; List <Task> tasks = new List <Task>(); for (int i = 0; i < count; i++) { tasks.Add(Task.Run(async() => queueBag.Add(await _cloudQueueFactory.GetCloudQueue(queueName)))); } // execute await Task.WhenAll(tasks); // check // 10 queues created Assert.Equal(10, queueBag.Count); // all queues have the same name foreach (var q in queueBag) { Assert.Equal(queueName, q.Name); } // all queues are the same object var firstQueue = queueBag.First(); foreach (var q in queueBag) { Assert.True(object.ReferenceEquals(firstQueue, q)); } // .CreateIfNotExistsAsync() is invoked exactly once _cloudQueueClientMock.Received(1).GetQueueReference(Arg.Any <string>()); firstQueue.Received(1).CreateIfNotExistsAsync(); }