コード例 #1
0
 public void test_bind_no_properties()
 {
   var registry = new EmptyServiceRegistry();
   var instance = new PropertyBinder(registry);
   var sample = new SampleClass();
   instance.Bind(sample);
   Assert(sample.instance == null);
 }
コード例 #2
0
 public void test_bind_property()
 {
   var registry = new FixedServiceRegistry();
   var impl = new ImplA();
   registry.Bound[typeof(IDepA)] = impl;
   var instance = new PropertyBinder(registry);
   var sample = new SampleClass();
   instance.Bind(sample);
   Assert(sample.instance == impl);
 }
コード例 #3
0
        public void TestBindTo()
        {
            IPropertyBinder<ControlTestClass, string> binder = new PropertyBinder<ControlTestClass, string>(
                    z => z.Text,
                    (cls, action) => cls.TextChanged += (sender, args) => action());

            var instance = new ControlTestClass { Text = "First" };

            TestBindableProperty(instance, binder.BindTo(instance));

            binder = new PropertyBinder<ControlTestClass, int, string>(
                    z => z.Number,
                    (cls, action) => cls.NumberChanged += (sender, args) => action(),
                    new DataConverter<int, string>(Helper.ToText, Helper.ToInt32));

            instance = new ControlTestClass { Number = 1 };

            var property = binder.BindTo(instance);

            Assert.Equal("First", property.Value);
            Assert.Equal(instance.Number.ToText(), property.Value);

            instance.Number = 2;
            Assert.Equal("Second", property.Value);

            property.Value = "Third";
            Assert.Equal("Third", instance.Number.ToText());

            int numberChangedCount = 0;
            int propertyChangedCount = 0;
            instance.NumberChanged += (sender, args) => numberChangedCount++;
            property.PropertyChanged += (sender, args) =>
            {
                Assert.Equal("Number", args.PropertyName);
                propertyChangedCount++;
            };

            instance.Number = 4;
            Assert.Equal(1, numberChangedCount);
            Assert.Equal(1, propertyChangedCount);

            property.Value = "Fifth";
            Assert.Equal(2, numberChangedCount);
            Assert.Equal(2, propertyChangedCount);
        }
コード例 #4
0
ファイル: TestItem.cs プロジェクト: priceLiu/IntegrationTest
            public DataBinder(Type type, ParamCollection properties)
            {
                foreach (Param item in properties)
                {
                    try
                    {
                        PropertyInfo pi = type.GetProperty(item.Name, BindingFlags.Instance | BindingFlags.Public);
                        if (pi != null)
                        {
                            PropertyBinder pb = new PropertyBinder();
                            pb.Property = pi;
                            pb.Value = item.Value;
                            mProperties.Add(pb);
                        }
                    }
                    catch
                    {
                    }

                }
            }
コード例 #5
0
        public void TestCreateBinder()
        {
            var binder = new PropertyBinder<ControlTestClass, string>(
                z => z.Text,
                (cls, action) => cls.TextChanged += (sender, args) => action());
            Assert.NotNull(binder);
            Assert.NotNull(binder.Getter);
            Assert.True(binder.CanRead);
            Assert.NotNull(binder.Setter);
            Assert.True(binder.CanWrite);
            Assert.Equal("Text", binder.PropertyName);

            var rdBinder = new PropertyBinder<ControlTestClass, int>(z => z.ReadOnly);
            Assert.NotNull(rdBinder);
            Assert.NotNull(rdBinder.Getter);
            Assert.True(rdBinder.CanRead);
            Assert.Null(rdBinder.Setter);
            Assert.False(rdBinder.CanWrite);
            Assert.Equal("ReadOnly", rdBinder.PropertyName);
        }