예제 #1
0
        public void HasBeenModifiedNotSetAfterConstruction()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(7, controller, string.Empty, BindingAccess.Read);

            Assert.Equal(7, accessor.Value);
            Assert.False(accessor.HasBeenModified);
        }
예제 #2
0
        public void SimpleValueSet_ValueIsGettable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            accessor.Value = 5;
            Assert.Equal(5, accessor.Value);
        }
예제 #3
0
        public void BindingAccessRead()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(controller, string.Empty, BindingAccess.Read);

            Assert.Throws <InvalidOperationException>(() => accessor.Value = 5);
            Assert.False(accessor.HasBeenModified);
        }
예제 #4
0
        public void SimpleValueSet_HasBeenModifiedChanges()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            Assert.False(accessor.HasBeenModified);
            accessor.Value = 5;
            Assert.True(accessor.HasBeenModified);
        }
예제 #5
0
        public void ComplexValueSet_ValueIsGettable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var thing      = new DummyComplexProperty();
            var accessor   = new PropertyAccessor <DummyComplexProperty>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            accessor.Value = thing;
            Assert.Equal(thing, accessor.Value);
        }
예제 #6
0
        public void ComplexValueChanged_HasBeenModifiedChanges()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var thing      = new DummyComplexProperty();
            var accessor   = new PropertyAccessor <DummyComplexProperty>(thing, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            Assert.False(accessor.HasBeenModified);
            thing.HasBeenModified = true; //Simulate a change to the complex value
            Assert.True(accessor.HasBeenModified);
        }
예제 #7
0
        public void ComplexValueSet_HasBeenModifiedChanges()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var thing      = new DummyComplexProperty();
            var accessor   = new PropertyAccessor <DummyComplexProperty>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            Assert.False(accessor.HasBeenModified);
            accessor.Value = thing;
            Assert.True(accessor.HasBeenModified);
        }
예제 #8
0
        public void SetPropertyToExistingValueMarksItAsChanged()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            var existingValue = accessor.Value;

            accessor.SetValue(existingValue);
            Assert.True(accessor.HasBeenModified);
        }
예제 #9
0
        public void SimplePropertyReadOnlySet_ObjectIsNotWritable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(8, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;
            Assert.Throws <InvalidOperationException>(() => accessor.Value = 10);
            Assert.False(accessor.HasBeenModified);
        }
예제 #10
0
        public void SimplePropertyReadOnlySet_ObjectIsReadable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(8, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;
            Assert.True(accessor.IsReadOnly);
            Assert.Equal(8, accessor.Value);
        }
예제 #11
0
        public void ComplexPropertyReadOnlySet_ObjectIsReadable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var property   = new DummyComplexProperty();
            var accessor   = new PropertyAccessor <DummyComplexProperty>(property, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;
            Assert.True(accessor.IsReadOnly);
            Assert.True(accessor.Value.IsReadOnly);
            Assert.Equal(property, accessor.Value);
        }
예제 #12
0
        public void OverrideReadOnly_CanSetValue()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;
            Assert.True(accessor.IsReadOnly);
            Assert.Equal(0, accessor.Value);

            accessor.SetValue(1, overrideReadOnly: true);
            Assert.True(accessor.HasBeenModified);
            Assert.Equal(1, accessor.Value);
        }
예제 #13
0
        public void SimplePropertyReadOnlySetAndUnset_ObjectIsReadWritable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var accessor   = new PropertyAccessor <int>(8, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;

            //Un-set readonly
            accessor.IsReadOnly = false;
            Assert.False(accessor.IsReadOnly);
            accessor.Value = 10;
            Assert.Equal(10, accessor.Value);
            Assert.True(accessor.HasBeenModified);
        }
예제 #14
0
        public void ComplexPropertyReadOnlySetAndUnset_ObjectIsReadWritable()
        {
            var controller = new PropertyAccessController(BindingState.Bound);
            var property   = new DummyComplexProperty();
            var accessor   = new PropertyAccessor <DummyComplexProperty>(property, controller, string.Empty, BindingAccess.Read | BindingAccess.Write);

            //Set readonly
            accessor.IsReadOnly = true;

            //Un-set readonly
            accessor.IsReadOnly = false;
            Assert.False(accessor.Value.IsReadOnly);
            Assert.False(accessor.IsReadOnly);
            accessor.Value.HasBeenModified = true;
            Assert.True(accessor.HasBeenModified);
        }
예제 #15
0
        public void PropertyWithBindingAccessNone_ValueNotReadableOrWritable()
        {
            const string propertyName = "Foo";
            var          controller   = new PropertyAccessController(BindingState.Bound);
            var          accessor     = new PropertyAccessor <int>(controller, propertyName, BindingAccess.None);

            InvalidOperationException e = Assert.Throws <InvalidOperationException>(() => accessor.Value = 5);

            this.testOutputHelper.WriteLine(e.ToString());
            Assert.Contains(propertyName, e.Message);

            e = Assert.Throws <InvalidOperationException>(() => { int x = accessor.Value; });
            this.testOutputHelper.WriteLine(e.ToString());
            Assert.Contains(propertyName, e.Message);

            Assert.False(accessor.HasBeenModified);
        }