public void Can_modify_readonly_auto_properties() { var original = new TestClass(); var newRecord = new TestClass(); var autoPropertyInfo = PropertyMutator <TestClass> .GetPropertyFromExpression(t => t.ReadonlyAutoObject); newRecord = new TestClass(); Assert.IsNull(newRecord.ReadonlyAutoObject); Assert.DoesNotThrow(() => PropertyMutator <TestClass> .FromAssignment(autoPropertyInfo, new object()).ApplyMutation(original, newRecord)); Assert.IsNotNull(newRecord.ReadonlyAutoObject); newRecord = new TestClass(); Assert.IsNull(newRecord.ReadonlyAutoObject); Assert.DoesNotThrow(() => PropertyMutator <TestClass> .FromTransform(autoPropertyInfo, r => new object()).ApplyMutation(original, newRecord)); Assert.IsNotNull(newRecord.ReadonlyAutoObject); newRecord = new TestClass(); Assert.IsNull(newRecord.ReadonlyAutoObject); Assert.DoesNotThrow(() => PropertyMutator <TestClass> .FromAssignment(autoPropertyInfo.Name, new object()).ApplyMutation(original, newRecord)); Assert.IsNotNull(newRecord.ReadonlyAutoObject); newRecord = new TestClass(); Assert.IsNull(newRecord.ReadonlyAutoObject); Assert.DoesNotThrow(() => PropertyMutator <TestClass> .FromTransform(autoPropertyInfo.Name, r => new object()).ApplyMutation(original, newRecord)); Assert.IsNotNull(newRecord.ReadonlyAutoObject); }
public void Throws_if_property_does_not_have_setter() { var notSetterProperyInfo = PropertyMutator <TestClass> .GetPropertyFromExpression(t => t.NoSetter); Assert.Throws <ArgumentException>(() => PropertyMutator <TestClass> .FromAssignment(notSetterProperyInfo, DateTimeOffset.MaxValue)); Assert.Throws <ArgumentException>(() => PropertyMutator <TestClass> .FromTransform(notSetterProperyInfo, r => DateTimeOffset.MaxValue)); Assert.Throws <ArgumentException>(() => PropertyMutator <TestClass> .FromAssignment(notSetterProperyInfo.Name, DateTimeOffset.MaxValue)); Assert.Throws <ArgumentException>(() => PropertyMutator <TestClass> .FromTransform(notSetterProperyInfo.Name, r => DateTimeOffset.MaxValue)); }