public void Parse_CombinedCode_ConvertsToMatchingFlagEnum()
        {
            var expectedPermission = QueueSharedAccessPermissions.Add | QueueSharedAccessPermissions.Read | QueueSharedAccessPermissions.Update | QueueSharedAccessPermissions.Write;

            var result = SharedAccessPermissionParse.ParseQueue("rwau");

            Assert.AreEqual(expectedPermission, result);
        }
        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 <BlobSignedIdentifier>();

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

                        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.ParseBlob(apElement.Value);
                                        break;

                                    case "Start":
                                        identifier.AccessPolicy.StartTime = Parsers.ParseUTCDate(apElement.Value);
                                        break;

                                    case "Expiry":
                                        identifier.AccessPolicy.Expiry = Parsers.ParseUTCDate(apElement.Value);
                                        break;
                                    }
                                }
                                break;
                            }
                        }

                        signedIdentifiers.Add(identifier);
                    }

                    SignedIdentifiers = new ReadOnlyCollection <BlobSignedIdentifier>(signedIdentifiers);
                }
            }
        }
        private byte[] PrepareContent(List <QueueSignedIdentifier> signedIdentifiers)
        {
            var sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<SignedIdentifiers>");

            foreach (var identifier in signedIdentifiers)
            {
                sb.AppendFormat("<SignedIdentifier><Id>{0}</Id><AccessPolicy><Start>{1:o}</Start><Expiry>{2:o}</Expiry><Permission>{3}</Permission></AccessPolicy></SignedIdentifier>",
                                identifier.Id,
                                identifier.AccessPolicy.StartTime,
                                identifier.AccessPolicy.Expiry,
                                SharedAccessPermissionParse.ConvertToString(identifier.AccessPolicy.Permission));
            }
            sb.Append("</SignedIdentifiers>");

            return(UTF8Encoding.UTF8.GetBytes(sb.ToString()));
        }
        public void ConvertToString_FlagEnum_ConvertsToStringWithMatchingCodes(QueueSharedAccessPermissions permission, string expectedCode)
        {
            var result = SharedAccessPermissionParse.ConvertToString(permission);

            Assert.AreEqual(expectedCode, result);
        }
        public void ConvertToString_IndividualEnum_ConvertsToMatchingLetter(QueueSharedAccessPermissions permission, string expectedCode)
        {
            var result = SharedAccessPermissionParse.ConvertToString(permission);

            Assert.AreEqual(expectedCode, result);
        }
        public void Parse_IndividualCode_ConvertsToMatchingEnum(string code, QueueSharedAccessPermissions expectedPermission)
        {
            var result = SharedAccessPermissionParse.ParseQueue(code);

            Assert.AreEqual(expectedPermission, result);
        }