示例#1
0
        public void PropertyHelper_RefStructProperties()
        {
            // Arrange
            var obj = new RefStructProperties();

            // Act + Assert
            var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(obj.GetType().GetTypeInfo()));

            Assert2.Equal("Prop5", helper.Name);
        }
示例#2
0
        public void PropertyHelper_DoesNotFindStaticProperties()
        {
            // Arrange
            var anonymous = new Static();

            // Act + Assert
            var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()));

            Assert2.Equal("Prop5", helper.Name);
        }
示例#3
0
        public void PropertyHelper_DoesNotChangeUnderscores()
        {
            // Arrange
            var anonymous = new { bar_baz2 = "foo" };

            // Act + Assert
            var helper = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()));

            Assert2.Equal("bar_baz2", helper.Name);
        }
示例#4
0
        //[Theory]
        //[MemberData(nameof(IgnoreCaseTestData))]
        private void ObjectToDictionary_IgnoresPropertyCase_Theory(object testObject,
                                                                   KeyValuePair <string, object> expectedEntry)
        {
            // Act
            var result = PropertyHelper.ObjectToDictionary(testObject);

            // Assert
            var entry = Assert2.Single(result);

            Assert2.Equal(expectedEntry, entry);
        }
示例#5
0
        public void PropertyHelper_UnwrapsNullableTypes()
        {
            // Arrange
            var myType = typeof(MyStruct?);

            // Act
            var properties = PropertyHelper.GetPropertyAccessors(myType);

            // Assert
            var property = Assert2.Single(properties);

            Assert2.Equal("Foo", property.Name);
        }
示例#6
0
        public void PropertyHelper_ReturnsCachedPropertyHelper()
        {
            // Arrange
            var anonymous = new { foo = "bar" };

            // Act
            var helpers1 = PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo());
            var helpers2 = PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo());

            // Assert
            Assert2.Single(helpers1);
            Assert2.Same(helpers1, helpers2);
            Assert2.Same(helpers1[0], helpers2[0]);
        }
示例#7
0
        public void PropertyHelper_WorksForStruct()
        {
            // Arrange
            var anonymous = new MyProperties();

            anonymous.IntProp    = 3;
            anonymous.StringProp = "Five";

            // Act + Assert
            var helper1 = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()).Where(prop => prop.Name == "IntProp"));
            var helper2 = Assert2.Single(PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()).Where(prop => prop.Name == "StringProp"));

            Assert2.Equal(3, helper1.GetValue(anonymous));
            Assert2.Equal("Five", helper2.GetValue(anonymous));
        }
示例#8
0
        public void PropertyHelper_ForDerived_WithVirtual()
        {
            // Arrange
            var derived = new DerivedClassWithOverride {
                PropA = "propAValue", PropB = "propBValue"
            };

            // Act
            var helpers = PropertyHelper.GetPropertyAccessors(derived.GetType().GetTypeInfo()).ToArray();

            // Assert
            Assert2.NotNull(helpers);
            Assert2.Equal(2, helpers.Length);

            var propAHelper = Assert2.Single(helpers.Where(h => h.Name == "PropA"));
            var propBHelper = Assert2.Single(helpers.Where(h => h.Name == "PropB"));

            Assert2.Equal("OverridenpropAValue", propAHelper.GetValue(derived));
            Assert2.Equal("propBValue", propBHelper.GetValue(derived));
        }