public void Null_IsForMember() { var property = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var memberSetter = BuilderUtils.GetMemberSetter <object, object>(property, (o, b, s) => null, true); Assert.DoesNotThrow(() => memberSetter.IsForMember(null, null, null)); }
public void Equality_SameObject_PropertyComparison() { var property1Property = typeof(GenericClassChild1).GetProperty("Property1"); var property1Member = BuilderUtils.GetMemberSetter <object, object>(property1Property, (o, b, s) => null, true); var property2Property = typeof(GenericClassChild1).GetProperty("Property1"); Assert.IsTrue(property1Member.IsForMember(property2Property, null, null)); }
public void InheritedProperty_ChildNotForParent() { var inheritedProperty = typeof(InheritsFromClassWithNullableDateTime).GetProperty("Property1"); var parentProperty = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var inheritedMember = BuilderUtils.GetMemberSetter <InheritsFromClassWithNullableDateTime, object>(inheritedProperty, (o, b, s) => null, true); Assert.IsFalse(inheritedMember.IsForMember(parentProperty, null, null)); }
public void Set_PrivateMember_DoesntThrowException() { var privateMember = typeof(SingleReadonlyClass).GetMember("PrivateField", BindingFlags.NonPublic | BindingFlags.Instance).First(); Assert.Throws <BuilderException>(() => new Builder().AfterConstructionOf( BuilderUtils.GetMemberSetter <object, int>(privateMember, null, false))); }
public void InheritedProperty_NotForSibling() { var child1Property = typeof(ClassChild1).GetProperty("Property1"); var child1PropertyMember = BuilderUtils.GetMemberSetter <ClassChild1, object>(child1Property, (o, b, s) => null, true); var child2Property = typeof(ClassChild2).GetProperty("Property1"); Assert.IsFalse(child1PropertyMember.IsForMember(child2Property, null, null)); }
public void InheritedProperty_ParentIsForChildren() { var parentProperty = typeof(GenericClassParent <int>).GetProperty("Property1"); var parentPropertyMember = BuilderUtils.GetMemberSetter <object, object>(parentProperty, (o, b, s) => null, true); var child1Property = typeof(GenericClassChild1).GetProperty("Property1"); var child2Property = typeof(GenericClassChild2).GetProperty("Property1"); Assert.IsTrue(parentPropertyMember.IsForMember(child1Property, null, null)); Assert.IsTrue(parentPropertyMember.IsForMember(child2Property, null, null)); }
public void InheritedProperty_PropertyDeclaredOnParent_NotUsedForChild() { var expectedDateTime = DateTime.Now; var member = new InheritsFromClassWithNullableDateTime(); Assert.IsNotNull(member); // Always true... this stops the warning about the variable never being used var inheritedProperty = typeof(InheritsFromClassWithNullableDateTime).GetProperty("Property1"); var parentProperty = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var parentMember = BuilderUtils.GetMemberSetter <ClassWithNullableDateTime, object>(parentProperty, (o, b, s) => expectedDateTime, false); Assert.IsFalse(parentMember.IsForMember(inheritedProperty, null, null)); }
public ITypedBuilder <TTarget> Set <TReturnType>(Expression <Func <TTarget, TReturnType> > expression, Func <TTarget, IBuilder, BuildSession, TReturnType> value) { if (expression == null) { throw new ArgumentNullException("expression"); } var member = expression.GetMemberInfo(); ValidateMember(member, value); _parent.AfterConstructionOf(BuilderUtils.GetMemberSetter(member, value, _allowInherited)); return(this); }
public void Set_ReadonlyMembers_ThrowsException_lp681214() { var typedBuilder = new Builder().For <SingleReadonlyClass>(); Assert.Throws <BuilderException>(() => typedBuilder.Set(x => x.GetOnlyProperty, 10)); Assert.Throws <BuilderException>(() => typedBuilder.Set(x => x.ReadonlyField, 10)); var constantMember = typeof(SingleReadonlyClass).GetMember("ConstantField").First(); Assert.Throws <BuilderException>(() => typedBuilder.AfterConstructionOf( BuilderUtils.GetMemberSetter <object, int>(constantMember, null, false))); }
public void Equality_SameObject_PropertyComparison() { var classWithNullable = new ClassWithNullableDateTime(); var expected = DateTime.Now; var property1Property = typeof(ClassWithNullableDateTime).GetProperty("Property1"); var property1Member = BuilderUtils.GetMemberSetter <object, object>(property1Property, (o, b, s) => expected, true); var property2Property = typeof(ClassWithNullableDateTime).GetProperty("Property1"); Assert.IsTrue(property1Member.IsForMember(property2Property, null, null)); property1Member.Set(classWithNullable, null, null); Assert.AreEqual(expected, classWithNullable.Property1); }
public void InheritedProperty_ParentIsForChildren() { const int number = 1; var child1 = new ClassChild1(); var child2 = new ClassChild2(); var parentProperty = typeof(ClassParent).GetProperty("Property1"); var parentPropertyMember = BuilderUtils.GetMemberSetter <object, object>(parentProperty, (o, b, s) => number, true); var child1Property = typeof(ClassChild1).GetProperty("Property1"); var child2Property = typeof(ClassChild2).GetProperty("Property1"); Assert.IsTrue(parentPropertyMember.IsForMember(child1Property, null, null)); Assert.IsTrue(parentPropertyMember.IsForMember(child2Property, null, null)); parentPropertyMember.Set(child1, null, null); Assert.AreEqual(number, child1.Property1); parentPropertyMember.Set(child2, null, null); Assert.AreEqual(number, child2.Property1); }