public async Task ParseResponseBodyAsync(System.IO.Stream responseStream)
        {
            using (StreamReader sr = new StreamReader(responseStream))
            {
                var content = await sr.ReadToEndAsync();
                if (content.Length > 0)
                {
                    var xDoc = XDocument.Parse(content);
                    var signedIdentifiers = new List<QueueSignedIdentifier>();

                    foreach (var identifierResponse in xDoc.Root.Elements().Where(e => e.Name.LocalName.Equals("SignedIdentifier")))
                    {
                        var identifier = new QueueSignedIdentifier();
                        identifier.AccessPolicy = new QueueAccessPolicy();

                        foreach (var element in identifierResponse.Elements())
                        {
                            switch (element.Name.LocalName) { 
                                case "Id":
                                    identifier.Id = element.Value;
                                    break;
                                case "AccessPolicy":
                                    foreach (var apElement in element.Elements())
                                    {
                                        switch (apElement.Name.LocalName) { 
                                            case "Permission":
                                                identifier.AccessPolicy.Permission = SharedAccessPermissionParse.ParseQueue(apElement.Value);
                                                break;
                                            case "Start":
                                                identifier.AccessPolicy.StartTime = DateParse.ParseUTC(apElement.Value);
                                                break;
                                            case "Expiry":
                                                identifier.AccessPolicy.Expiry = DateParse.ParseUTC(apElement.Value);
                                                break;
                                        }
                                    }
                                    break;
                            }
                        }

                        signedIdentifiers.Add(identifier);
                    }

                    SignedIdentifiers = new ReadOnlyCollection<QueueSignedIdentifier>(signedIdentifiers);
                }
            }
        }
        public async Task SetQueueACLAsync_ValidQueue_AddsPolicyToQueue()
        {
            IQueueServiceClient client = new QueueServiceClient(_accountSettings);
            var queueName = GenerateSampleQueueName();
            _util.CreateQueue(queueName);
            var expectedStartTime = _util.GetTruncatedUtcNow();
            var expectedIdentifier = new QueueSignedIdentifier()
            {
                Id = "abc-123",
                AccessPolicy = new QueueAccessPolicy()
                {
                    StartTime = expectedStartTime,
                    Expiry = expectedStartTime.AddHours(1),
                    Permission = QueueSharedAccessPermissions.Add
                }
            };

            await client.SetQueueACLAsync(queueName, new List<QueueSignedIdentifier>() { expectedIdentifier });

            var actual = _util.GetQueuePermissions(queueName);
            Assert.AreEqual(1, actual.SharedAccessPolicies.Count);
            _util.AssertIdentifierInSharedAccessPolicies(actual.SharedAccessPolicies, expectedIdentifier);
        }
        public async Task SetQueueACLAsync_NonExistentQueue_ThrowsQueueNotFoundException()
        {
            IQueueServiceClient client = new QueueServiceClient(_accountSettings);
            var queueName = GenerateSampleQueueName();
            var expectedStartTime = _util.GetTruncatedUtcNow();
            var expectedIdentifier = new QueueSignedIdentifier()
            {
                Id = "abc-123",
                AccessPolicy = new QueueAccessPolicy()
                {
                    StartTime = expectedStartTime,
                    Expiry = expectedStartTime.AddHours(1),
                    Permission = QueueSharedAccessPermissions.Add
                }
            };

            await client.SetQueueACLAsync(queueName, new List<QueueSignedIdentifier>() { expectedIdentifier });

            //expects exception
        }
 private void AssertIdentifierInSharedAccessPolicies(Microsoft.WindowsAzure.Storage.Queue.SharedAccessQueuePolicies sharedAccessPolicies, QueueSignedIdentifier expectedIdentifier)
 {
     var policy = sharedAccessPolicies.Where(i => i.Key.Equals(expectedIdentifier.Id, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
     Assert.IsNotNull(policy);
     Assert.AreEqual(expectedIdentifier.AccessPolicy.StartTime, policy.Value.SharedAccessStartTime.Value.UtcDateTime);
     Assert.AreEqual(expectedIdentifier.AccessPolicy.Expiry, policy.Value.SharedAccessExpiryTime.Value.UtcDateTime);
     Assert.IsTrue(policy.Value.Permissions.HasFlag(Microsoft.WindowsAzure.Storage.Queue.SharedAccessQueuePermissions.Add));
 }