コード例 #1
0
        public void AddRange_Uris_Success()
        {
            Uri[] values    = new Uri[] { new Uri("http://microsoft.com") };
            var   attribute = new DirectoryAttribute();

            attribute.AddRange(values);
            Assert.Equal(1, attribute.Count);
            Assert.Equal(values, attribute.Cast <Uri>());
        }
コード例 #2
0
        public void AddRange_ByteArrays_Success()
        {
            byte[][] values    = new byte[][] { new byte[] { 1, 2, 3 }, new byte[0] };
            var      attribute = new DirectoryAttribute();

            attribute.AddRange(values);
            Assert.Equal(2, attribute.Count);
            Assert.Equal(values, attribute.Cast <byte[]>());
        }
コード例 #3
0
        public void AddRange_Strings_Success()
        {
            string[] values    = new string[] { "value1", "value2" };
            var      attribute = new DirectoryAttribute();

            attribute.AddRange(values);
            Assert.Equal(2, attribute.Count);
            Assert.Equal(values, attribute.Cast <string>());
        }
コード例 #4
0
        public void Ctor_Name_Values()
        {
            object[] values = new object[] { "value", new byte[] { 1, 2, 3 }, new Uri("http://microsoft.com") };

            var attribute = new DirectoryAttribute("Name", values);

            Assert.Equal("Name", attribute.Name);
            Assert.Equal(3, attribute.Count);
            Assert.Equal(values, attribute.Cast <object>());
        }
コード例 #5
0
        private static string FormatDirectoryAttribute(DirectoryAttribute directoryAttribute)
        {
            if (directoryAttribute != null)
            {
                if (directoryAttribute.Count > 1)
                {
                    var type = directoryAttribute[0].GetType();

                    if (type == typeof(string))
                    {
#if NET35
                        return(string.Format(AttributeFormat, directoryAttribute.Name,
                                             string.Join(" ", directoryAttribute.Cast <string>().ToArray())));
#else
                        return(string.Format(AttributeFormat, directoryAttribute.Name,
                                             string.Join(" ", directoryAttribute.Cast <string>())));
#endif
                    }
                    if (type == typeof(byte[]))
                    {
#if NET35
                        return(string.Format(AttributeFormat, directoryAttribute.Name,
                                             string.Join(" ", directoryAttribute.Cast <byte[]>().Select(b => b.ToStringOctet()).ToArray())));
#else
                        return(string.Format(AttributeFormat, directoryAttribute.Name,
                                             string.Join(" ", directoryAttribute.Cast <byte[]>().Select(b => b.ToStringOctet()))));
#endif
                    }
                }

                var value = directoryAttribute.Count == 1 ? directoryAttribute[0] : string.Empty;

                if (value is byte[])
                {
                    return(string.Format(AttributeFormat, directoryAttribute.Name, (value as byte[]).ToStringOctet()));
                }

                return(string.Format(AttributeFormat, directoryAttribute.Name, value));
            }

            return(string.Empty);
        }
コード例 #6
0
        public void Insert_MultipleTypes_Success()
        {
            var attribute = new DirectoryAttribute {
                "value2"
            };

            attribute.Insert(0, "value1");
            attribute.Insert(1, new byte[] { 1, 2, 3 });
            attribute.Insert(3, new Uri("http://microsoft.com"));

            Assert.Equal(new object[] { "value1", new byte[] { 1, 2, 3 }, "value2", new Uri("http://microsoft.com") }, attribute.Cast <object>());
        }
コード例 #7
0
        public void Add_MultipleTypes_Success()
        {
            var attribute = new DirectoryAttribute {
                "value", new byte[] { 1, 2, 3 }, new Uri("http://microsoft.com")
            };

            Assert.Equal(3, attribute.Count);
            Assert.Equal(new object[] { "value", new byte[] { 1, 2, 3 }, new Uri("http://microsoft.com") }, attribute.Cast <object>());
        }