public void DataContainerBase_SetBinding_MustBindOneWay()
        {
            const string PROP_NAME = "IntProperty";
            const int    VALUE     = 42;
            const int    NEW_VALUE = 14;

            IPropertyContainer pc = PropertyContainerBuilder.Create()
                                    .Property(PROP_NAME, VALUE)
                                    .Build();

            var bindingTarget = new BindingTestObject();

            Assert.NotEqual(VALUE, bindingTarget.IntProperty);

            pc.SetBinding(PROP_NAME, () => bindingTarget.IntProperty, BindingMode.OneWay);

            Assert.Equal(VALUE, bindingTarget.IntProperty);

            pc.SetValue(PROP_NAME, NEW_VALUE);

            Assert.Equal(NEW_VALUE, bindingTarget.IntProperty);

            bindingTarget.IntProperty = 32;

            int propertyValue = 0;

            pc.GetValue(PROP_NAME, ref propertyValue);

            pc.RemoveBinding(PROP_NAME, () => bindingTarget.IntProperty);

            Assert.NotEqual(32, propertyValue);
            Assert.Equal(NEW_VALUE, propertyValue);
        }
        public void IDataContainer_Merge_ShouldUpdateCategoryDescriptionAndDisplayName()
        {
            IDataContainer A = PropertyContainerBuilder.Create("A")
                               .Property("A", 1)
                               .Property("B", 2)
                               .Property("C", 26)
                               .Build();

            IDataContainer B = PropertyContainerBuilder.Create("B")
                               .Property("A", 2, b => b
                                         .SetDisplayName("PropertyA")
                                         .SetDescription("PropertyA")
                                         .SetCategory("Category"))
                               .Property("B", 3, b => b
                                         .SetDisplayName("PropertyB")
                                         .SetDescription("PropertyB")
                                         .SetCategory("Category"))
                               .Property("C", 4, b => b
                                         .SetDisplayName("PropertyC")
                                         .SetDescription("PropertyC")
                                         .SetCategory("Category"))
                               .Build();

            bool result = A.Merge(B);

            foreach (var item in A.OfType <PropertyObject>())
            {
                Assert.Equal($"Property{item.Name}", item.DisplayName);
                Assert.Equal($"Property{item.Name}", item.Description);
                Assert.Equal("Category", item.Category);
            }

            Assert.True(result);
        }
        public void DataContainerBase_Get_MustReturnDefaultIfNotPresent()
        {
            const string PROP_NAME = "IntProperty";

            DataContainerBase property = (DataContainerBase)PropertyContainerBuilder.Create()
                                         .Property(PROP_NAME, 42)
                                         .Build();

            int  prop             = 0;
            bool containsProperty = property.GetValue("blah", ref prop);

            Assert.False(containsProperty);
            Assert.Equal(default, prop);
        public void IDataContainer_Merge_ReturnsFalseIfNoChange()
        {
            IDataContainer A = PropertyContainerBuilder.Create("A")
                               .Property("A", 1)
                               .Property("B", 2)
                               .Property("C", 26)
                               .Build();

            IDataContainer B = PropertyContainerBuilder.Create("B")
                               .Property("A", 1)
                               .Property("B", 2)
                               .Property("C", 26)
                               .Build();

            Assert.False(A.Merge(B));
        }
        public void DataContainerBase_Get_MustGetCorrectValue()
        {
            const string PROP_NAME = "IntProperty";

            DataContainerBase property = (DataContainerBase)PropertyContainerBuilder.Create()
                                         .Property(PROP_NAME, 42)
                                         .Build();

            int  prop             = 0;
            bool containsProperty = property.GetValue(PROP_NAME, ref prop);

            Assert.True(containsProperty);
            Assert.NotEqual(0, prop);
            Assert.Equal(42, prop);

            int prop2 = property.GetValue <int>(PROP_NAME);

            Assert.NotEqual(0, prop2);
            Assert.Equal(42, prop2);
        }
Ejemplo n.º 6
0
        public MainWindow()
        {
            InitializeComponent();

            SelectedItem = PropertyContainerBuilder.Create("Shape")
                           .Color("Fill", "#000000", p => p
                                  .SetCategory("Visualization")
                                  .SetDescription("Fill color of shape")
                                  .SetDisplayName("Background"))
                           .Color("Stroke", "#000000", p => p
                                  .SetCategory("Visualization")
                                  .SetDescription("Border color of shape")
                                  .SetDisplayName("Border"))
                           .Number("StrokeThickness", 3.0, p => p
                                   .SetCategory("Visualization")
                                   .SetDescription("Border thickness of shape")
                                   .SetDisplayName("Border Thickness"))
                           .Number("Height", 200.0, p => p
                                   .SetCategory("Definition")
                                   .SetDescription("Height of shape"))
                           .Number("Width", 200.0, p => p
                                   .SetCategory("Definition")
                                   .SetDescription("Width of shape"))
                           .Number("X", 50.0, p => p
                                   .SetCategory("Definition")
                                   .SetDescription("X-Coordinate of top left point"))
                           .Number("Y", 50.0, p => p
                                   .SetCategory("Definition")
                                   .SetDescription("Y-Coordinate of top left point"))
                           .Build();


            SelectedItem.PropertyChanged += SelectedItem_PropertyChanged;

            formsGrid.SelectedObject = SelectedItem;
        }