public void ClassWithProtectedProperties_ProtectedAccessorsShouldNotBeAvailable() { // Arrange: // const string altogetherProtectedProperty = "ImAltogetherProtected"; // Not expected to be available either as a source or destination property. const string propertyWithProtectedGetter = "MyGetterIsProtected"; var propertyWithProtectedSetter = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.MySetterIsProtected).Name; var altogetherAccessibleProperty = MemberExpressions.GetMemberInfo <ClassWithProtectedProperties>(c => c.ImAltogetherAccessible).Name; var expectedSourcePropertyNames = new[] { propertyWithProtectedSetter, altogetherAccessibleProperty }; var expectedDestinationProperyNames = new[] { propertyWithProtectedGetter, altogetherAccessibleProperty }; // Act: var mappingCollection = new MappingCollection <ClassWithProtectedProperties, ClassWithProtectedProperties, object>(null); var availableSourcePropertyNames = mappingCollection.Unmapped.Source.Select(sourceMember => sourceMember.Name).ToArray(); var availableDestinationPropertyNames = mappingCollection.Unmapped.Destination.Select(destMember => destMember.Name).ToArray(); // Assert: Array.Sort(expectedSourcePropertyNames); Array.Sort(availableSourcePropertyNames); Assert.AreEqual(expectedSourcePropertyNames, availableSourcePropertyNames); Array.Sort(expectedDestinationProperyNames); Array.Sort(availableDestinationPropertyNames); Assert.AreEqual(expectedDestinationProperyNames, availableDestinationPropertyNames); }
public void GetMemberInfo_DeepMemberChain_WithCast() { var memberInfo = MemberExpressions.GetMemberInfo <DeepClass>(c => ((string)c.String).Length); Assert.IsNotNull(memberInfo); Assert.AreEqual(MemberExpressions.GetMemberInfo <string>(c => c.Length), memberInfo); }
public void GetMemberInfo_LambdaExpression_Basic() { var info = (PropertyInfo)MemberExpressions.GetMemberInfo((ClassParent c) => c.Property1); Assert.AreEqual(typeof(ClassParent), info.ReflectedType); Assert.AreEqual(typeof(int), info.PropertyType); }
public void GetMemberInfo_ClassParent_SimpleField1() { var info = (FieldInfo)MemberExpressions.GetMemberInfo <ClassParent>(c => c.Field1); Assert.IsNotNull(info); Assert.AreEqual(typeof(ClassParent), info.ReflectedType); Assert.AreEqual("Field1", info.Name); }
public void GetMemberInfo_InheritedMember_ReturnsInheritingClassType() { var instance = new ClassChild1(); const int number = 10; var info = (PropertyInfo)MemberExpressions.GetMemberInfo <ClassChild1>(c => c.Property1); Assert.AreEqual(typeof(ClassChild1), info.ReflectedType); info.SetValue(instance, number, null); Assert.AreEqual(number, instance.Property1); }
public void Create_SimpleType_NamedMember() { var session = new BuildSession(null, null, new Random(0)); var obj = new SimpleType(); session.PushObject(new ObjectBuildRecord(typeof(SimpleType), obj, true)); session.PushMember(MemberExpressions.GetMemberInfo <SimpleType>(c => c.NamedMember)); Assert.AreEqual("NamedMember0", Generator.CreateRecord(typeof(string), null, session).Object); Assert.AreEqual("NamedMember1", Generator.CreateRecord(typeof(string), null, session).Object); Assert.AreEqual("NamedMember2", Generator.CreateRecord(typeof(string), null, session).Object); }
public void GetMemberChain_DeepMemberChain_WithCast() { var memberInfo = MemberExpressions.GetExpressionChain <DeepClass>(c => ((string)c.String).Length); var expected = new[] { MemberExpressions.GetMemberInfo <DeepClass>(c => c.String), MemberExpressions.GetMemberInfo <string>(c => c.Length) }; Assert.IsNotNull(memberInfo); Assert.AreEqual(expected, memberInfo); }
public void GetMemberInfo_InheritedMember_NewProperty_BaseStillAccessible() { var instance = new SpecificInterface(); const int number = 10; var info = (PropertyInfo)MemberExpressions.GetMemberInfo <IGeneralInterface>(c => c.Property1); Assert.AreEqual(typeof(IGeneralInterface), info.ReflectedType); Assert.AreEqual(typeof(object), info.PropertyType); info.SetValue(instance, number, null); Assert.AreEqual(number, instance.Property1); }
public void ResolveSource_MappingCollection_ReturnsNullIfNoMemberFound() { var searchMember = MemberExpressions.GetMemberInfo <ClassWithSeveralPropertiesDest>(c => c.Property2); var members = new[] { MemberExpressions.GetMemberInfo <ClassWithSeveralPropertiesDest>(c => c.Property1), MemberExpressions.GetMemberInfo <ClassWithSeveralPropertiesDest>(c => c.Property3) }; var mappingCollection = new Mock <IMappingCollection <object, object, object> >(); mappingCollection.Setup(m => m.MemberResolvers).Returns(new PriorityList <IMemberResolver> { new IgnoreCaseNameMatcher() }); mappingCollection.Setup(m => m.Unmapped.Source).Returns(members); Assert.IsNull(mappingCollection.Object.ResolveSource(searchMember)); }
public IMappingCollection <TFrom, TTo, TContext> Ignore <TMemberType>(Expression <Func <TTo, TMemberType> > expression) { return(IgnoreMember(MemberExpressions.GetMemberInfo(expression))); }
public void GetMemberInfo_NonGeneric_NullMember_ThrowsException() { Assert.Throws <ArgumentNullException>(() => MemberExpressions.GetMemberInfo(null)); }
public void GetMemberInfo_NonPropertyOrFieldType_ThrowsException() { Assert.Throws <MemberExpressionException>(() => MemberExpressions.GetMemberInfo <DeepClass>(c => c.String.Length + 1)); }
public void GetAccessor_Property() { var accessor = MemberExpressions.GetMemberInfo <NormalPropertiesAndFields>(c => c.ValidProperty).GetAccessor(); Assert.IsInstanceOf <PropertyAccessor <NormalPropertiesAndFields, int> >(accessor); }
public void GetAccessor_Field() { var accessor = MemberExpressions.GetMemberInfo <NormalPropertiesAndFields>(c => c.ValidField).GetAccessor(); Assert.IsInstanceOf <FieldAccessor>(accessor); }
public void ReturnType_Property() { Assert.AreEqual(typeof(string), MemberExpressions.GetMemberInfo <DemoClass>(c => c.Property).ReturnType()); }
public void ReturnType_Field() { Assert.AreEqual(typeof(int), MemberExpressions.GetMemberInfo <DemoClass>(c => c.Field).ReturnType()); }