Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void Property_is_exposed()
        {
            var tc           = new TestClass();
            var propertyInfo = PropertyMutator <TestClass> .GetPropertyFromExpression(t => t.TestProp);

            var mutator = PropertyMutator <TestClass> .FromAssignment(propertyInfo, 0);

            Assert.AreSame(propertyInfo, mutator.Property);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        public void Proparty_name_is_the_same_as_in_code()
        {
            var tc           = new TestClass();
            var propertyInfo = PropertyMutator <TestClass> .GetPropertyFromExpression(t => t.TestProp);

            var mutator = PropertyMutator <TestClass> .FromAssignment(propertyInfo, 0);

            Assert.AreEqual(nameof(TestClass.TestProp), mutator.PropertyName);
        }