Пример #1
0
        public void MemberDescriptorFromMemberDescriptor()
        {
            var name          = nameof(MemberDescriptorFromNameAndAttributes);
            var attributes    = new Attribute[] { new MockAttribute1(), new MockAttribute2() };
            var oldDescriptor = new MockMemberDescriptor(name, attributes);

            var descriptor = new MockMemberDescriptor(oldDescriptor);

            Assert.Equal(attributes.OrderBy(a => a.GetHashCode()), descriptor.Attributes.Cast <Attribute>().OrderBy(a => a.GetHashCode()));
        }
Пример #2
0
        public void MemberDescriptorFromMemberDescriptor()
        {
            var name = nameof(MemberDescriptorFromNameAndAttributes);
            var attributes = new Attribute[] { new MockAttribute1(), new MockAttribute2() };
            var oldDescriptor = new MockMemberDescriptor(name, attributes);

            var descriptor = new MockMemberDescriptor(oldDescriptor);

            Assert.Equal(attributes.OrderBy(a => a.GetHashCode()), descriptor.Attributes.Cast<Attribute>().OrderBy(a => a.GetHashCode()));
        }
Пример #3
0
        public void DisplayNameWithAttribute()
        {
            var name        = "name";
            var displayName = "displayName";
            var attributes  = new Attribute[] { new DisplayNameAttribute(displayName) };

            var descriptor = new MockMemberDescriptor(name, attributes);

            Assert.Equal(name, descriptor.Name);
            Assert.Equal(displayName, descriptor.DisplayName);
        }
Пример #4
0
        public void DisplayNameWithAttribute()
        {
            var name = "name";
            var displayName = "displayName";
            var attributes = new Attribute[] { new DisplayNameAttribute(displayName) };

            var descriptor = new MockMemberDescriptor(name, attributes);

            Assert.Equal(name, descriptor.Name);
            Assert.Equal(displayName, descriptor.DisplayName);
        }
Пример #5
0
        public void MemberDescriptorFromNameAndAttributes()
        {
            AssertExtensions.Throws <ArgumentException>(null, () => new MockMemberDescriptor((string)null, new Attribute[0]));
            AssertExtensions.Throws <ArgumentException>(null, () => new MockMemberDescriptor("", new Attribute[0]));

            var name       = nameof(MemberDescriptorFromNameAndAttributes);
            var attributes = new Attribute[] { new MockAttribute1(), new MockAttribute2() };

            var descriptor = new MockMemberDescriptor(name, attributes);

            Assert.Equal(name, descriptor.Name);
            Assert.Equal(name, descriptor.DisplayName);

            Assert.Equal(attributes.OrderBy(a => a.GetHashCode()), descriptor.Attributes.Cast <Attribute>().OrderBy(a => a.GetHashCode()));
        }
Пример #6
0
        public void MemberDescriptorFromNameAndAttributes()
        {
            Assert.Throws<ArgumentException>(() => new MockMemberDescriptor((string)null, new Attribute[0]));
            Assert.Throws<ArgumentException>(() => new MockMemberDescriptor("", new Attribute[0]));

            var name = nameof(MemberDescriptorFromNameAndAttributes);
            var attributes = new Attribute[] { new MockAttribute1(), new MockAttribute2() };

            var descriptor = new MockMemberDescriptor(name, attributes);

            Assert.Equal(name, descriptor.Name);
            Assert.Equal(name, descriptor.DisplayName);

            Assert.Equal(attributes.OrderBy(a => a.GetHashCode()), descriptor.Attributes.Cast<Attribute>().OrderBy(a => a.GetHashCode()));
        }
Пример #7
0
        public void CopiedMemberDescriptorEqualsItsSource()
        {
            var attributes = new Attribute[]
            {
                new CategoryAttribute("category"),
                new DescriptionAttribute("description")
            };
            var firstDescriptor  = new MockMemberDescriptor(nameof(MemberDescriptor), attributes);
            var copiedDescriptor = new MockMemberDescriptor(firstDescriptor);

            // call getters to ensure their backing fields aren't null
            Assert.Equal(firstDescriptor.Category, copiedDescriptor.Category);
            Assert.Equal(firstDescriptor.Description, copiedDescriptor.Description);

            Assert.True(firstDescriptor.Equals(copiedDescriptor));
        }
Пример #8
0
        public void CopiedMemberDescriptorEqualsItsSource()
        {
            var attributes = new Attribute[]
            {
                new CategoryAttribute("category"),
                new DescriptionAttribute("description")
            };
            var firstDescriptor = new MockMemberDescriptor(nameof(MemberDescriptor), attributes);
            var copiedDescriptor = new MockMemberDescriptor(firstDescriptor);

            // call getters to ensure their backing fields aren't null
            Assert.Equal(firstDescriptor.Category, copiedDescriptor.Category);
            Assert.Equal(firstDescriptor.Description, copiedDescriptor.Description);

            Assert.True(firstDescriptor.Equals(copiedDescriptor));
        }
Пример #9
0
        public void CopiedMemberDescriptorEqualsItsSource()
        {
            string description = "MockCategory";
            var    attributes  = new Attribute[]
            {
                new CategoryAttribute(description),
                // setting Decription and Category the same as .NET Framework has a bug in the equals that compares them
                // instead of each other. In .NET 4.6.2 and greater this is no longer an issue but to make the test
                // work on all platforms just setting them to be the same.
                new DescriptionAttribute(description)
            };

            var firstDescriptor  = new MockMemberDescriptor(nameof(MemberDescriptor), attributes);
            var copiedDescriptor = new MockMemberDescriptor(firstDescriptor);

            // call getters to ensure their backing fields aren't null
            Assert.Equal(firstDescriptor.Category, copiedDescriptor.Category);
            Assert.Equal(firstDescriptor.Description, copiedDescriptor.Description);

            Assert.True(firstDescriptor.Equals(copiedDescriptor));
        }