public void FromExpression_CanGetMetadataFromCustomizedSubtype() { var instance1 = new CustomizedSubtype(); var instance2 = new CustomizedSubtype(); var baseType = typeof(CustomizedSubtype); // instance property inherits type customization { var instancePropertyExpressions = instance2.InstanceProperty1Expressions().ToList(); //var baseInstanceProperty = baseType.GetProperty(nameof(CustomizedSubtype.InstanceProperty1), BindingFlags.Instance | BindingFlags.Public); var actual = SettingMetadata.FromExpression(instancePropertyExpressions.Last()); AreEqual(baseType, actual.Type); AreSame(instance2, actual.Instance); //AreEqual(baseInstanceProperty, actual.Member); AreEqual("InstanceProperty1xx", actual.MemberName); AreEqual("Prefix1", actual.Prefix); AreEqual("CustomizedType2", actual.TypeName); AreEqual("Provider1", actual.ProviderName); AreEqual(SettingNameStrength.Low, actual.SettingNameStrength); AreEqual(PrefixHandling.Enable, actual.PrefixHandling); } }
public void AssertFoo() { var expression1 = ((Expression <Func <object> >)(() => Foo)); var expression2 = ((Expression <Func <object> >)(() => Foo)); var settingMetadata = SettingMetadata.FromExpression(expression2); var settingName = SettingName.FromMetadata(settingMetadata, null); Assert.AreEqual("Reusable.Tests.SmartConfig.Reflection+TestClass1.Foo", settingName); }
public void AssertFoo() { var expression1 = ((Expression <Func <object> >)(() => Foo)); var expression2 = ((Expression <Func <object> >)(() => Foo)); var settingMetadata = SettingMetadata.FromExpression(expression2); //var settingName = (string)SettingRequestFactory.CreateSettingRequest(settingMetadata, null); //Assert.AreEqual("Reusable.Tests.SmartConfig.Reflection+TestClass1.Foo", settingName); }
public void GetSettingName_Instance_FullName() { var testClass1 = new TestClass1(); var testClass2 = new TestClass2(); var expression1 = ((Expression <Func <object> >)(() => testClass1.Foo)); var expression2 = ((Expression <Func <object> >)(() => testClass2.Foo)); var settingMetadata = SettingMetadata.FromExpression(expression2); var settingName = SettingName.FromMetadata(settingMetadata, null); Assert.AreEqual("Reusable.Tests.SmartConfig.Reflection+TestClass2.Foo", settingName); }
public void GetSettingName_Instance_FullName() { var testClass1 = new TestClass1(); var testClass2 = new TestClass2(); var expression1 = ((Expression <Func <object> >)(() => testClass1.Foo)); var expression2 = ((Expression <Func <object> >)(() => testClass2.Foo)); var settingMetadata = SettingMetadata.FromExpression(expression2); var settingName = (string)UriConverter.Convert <SettingIdentifier>(SettingRequestFactory.CreateSettingRequest(settingMetadata, null)); Assert.AreEqual("Reusable.Tests.SmartConfig.Reflection+TestClass2.Foo", settingName); }
public void FromExpression_CanGetMetadataFromBasicType() { var instance1 = new BasicType(); var instance2 = new BasicType(); var baseType = typeof(BasicType); // instance property as is { var instancePropertyExpressions = instance2.InstancePropertyExpressions().ToList(); var baseInstanceProperty = typeof(BasicType).GetProperty(nameof(BasicType.InstanceProperty), BindingFlags.Instance | BindingFlags.Public); var actual = SettingMetadata.FromExpression(instancePropertyExpressions.Last()); AreSame(instance2, actual.Instance); AreEqual(baseInstanceProperty, actual.Member); AreEqual(nameof(BasicType.InstanceProperty), actual.MemberName); AssertDefault(actual); } // static property as is { var staticPropertyExpressions = instance2.StaticPropertyExpressions().ToList(); var baseStaticProperty = typeof(BasicType).GetProperty(nameof(BasicType.StaticProperty), BindingFlags.Static | BindingFlags.Public); var actual = SettingMetadata.FromExpression(staticPropertyExpressions.Last()); IsNull(actual.Instance); AreEqual(baseStaticProperty, actual.Member); AreEqual(nameof(BasicType.StaticProperty), actual.MemberName); AssertDefault(actual); } // instance field as is { var instanceFieldExpressions = instance2.InstanceFieldExpressions().ToList(); var baseInstanceField = typeof(BasicType).GetField("_instanceField", BindingFlags.Instance | BindingFlags.NonPublic); var actual = SettingMetadata.FromExpression(instanceFieldExpressions.Last(), nonPublic: true); AreSame(instance2, actual.Instance); AreEqual(baseInstanceField, actual.Member); AreEqual("_instanceField", actual.MemberName); AssertDefault(actual); } // static field as is { var staticFieldExpressions = instance2.StaticFieldExpressions().ToList(); var baseStaticField = typeof(BasicType).GetField("_staticField", BindingFlags.Static | BindingFlags.NonPublic); var actual = SettingMetadata.FromExpression(staticFieldExpressions.Last(), nonPublic: true); IsNull(actual.Instance); AreEqual(baseStaticField, actual.Member); AreEqual("_staticField", actual.MemberName); AssertDefault(actual); } void AssertDefault(SettingMetadata actual) { // These cases are common to all tests. AreEqual(baseType, actual.Type); IsNull(actual.Prefix); AreEqual(Namespace, actual.Namespace); AreEqual(baseType.Name, actual.TypeName); IsTrue(actual.Validations.Empty()); IsNull(actual.DefaultValue); IsNull(actual.ProviderName); AreEqual(SettingNameStrength.Inherit, actual.SettingNameStrength); AreEqual(PrefixHandling.Inherit, actual.PrefixHandling); } }
public void FromExpression_CanGetMetadataFromCustomizedType() { var instance1 = new CustomizedType(); var instance2 = new CustomizedType(); var baseType = typeof(CustomizedType); // instance property inherits type customization { var instancePropertyExpressions = instance2.InstanceProperty1Expressions().ToList(); var baseInstanceProperty = baseType.GetProperty(nameof(CustomizedType.InstanceProperty1), BindingFlags.Instance | BindingFlags.Public); var actual = SettingMetadata.FromExpression(instancePropertyExpressions.Last()); AreEqual(baseType, actual.Type); AreSame(instance2, actual.Instance); AreEqual(baseInstanceProperty, actual.Member); AreEqual("InstanceProperty1x", actual.MemberName); AssertDefault(actual); } // instance property overrides type customization { var instancePropertyExpressions = instance2.InstanceProperty2Expressions().ToList(); var baseInstanceProperty = baseType.GetProperty(nameof(CustomizedType.InstanceProperty2), BindingFlags.Instance | BindingFlags.Public); var actual = SettingMetadata.FromExpression(instancePropertyExpressions.Last()); AreEqual(baseType, actual.Type); AreSame(instance2, actual.Instance); AreEqual(baseInstanceProperty, actual.Member); AreEqual("InstanceProperty2x", actual.MemberName); //AssertDefault(actual); AreEqual("Prefix2", actual.Prefix); AreEqual("BaseClass2", actual.TypeName); AreEqual("Provider2", actual.ProviderName); AreEqual(SettingNameStrength.High, actual.SettingNameStrength); AreEqual(PrefixHandling.Enable, actual.PrefixHandling); } // static property inherits type customization { var staticPropertyExpressions = instance2.StaticPropertyExpressions().ToList(); var baseStaticProperty = baseType.GetProperty(nameof(CustomizedType.StaticProperty1), BindingFlags.Static | BindingFlags.Public); var actual = SettingMetadata.FromExpression(staticPropertyExpressions.Last()); IsNull(actual.Instance); AreEqual(baseStaticProperty, actual.Member); AreEqual("StaticProperty1x", actual.MemberName); AssertDefault(actual); } void AssertDefault(SettingMetadata actual) { // These cases are common to all tests. AreEqual(Namespace, actual.Namespace); IsTrue(actual.Validations.Empty()); IsNull(actual.DefaultValue); AreEqual("Prefix1", actual.Prefix); AreEqual("BaseClass2", actual.TypeName); AreEqual("Provider1", actual.ProviderName); AreEqual(SettingNameStrength.Low, actual.SettingNameStrength); AreEqual(PrefixHandling.Enable, actual.PrefixHandling); } }