BaseBindingManager keeps track of all registered bindings and represents an entry point for the binding and unbinding process.
상속: BaseBindingContainer
예제 #1
0
        public void UnhandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            Inventor           st  = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            st.Inventions = new string[] { "Invention One", "Invention Two" };

            dbm.AddBinding("pob", "DOB");

            try
            {
                dbm.BindTargetToSource(st, st, null);
                Assert.Fail("Binding date to custom Place type should throw an exception.");
            }
            catch (TypeMismatchException)
            {}

            // binding state is not remembered with ValidationErrors=null!
            try
            {
                dbm.BindSourceToTarget(st, st, null);
                Assert.Fail("Binding custom Place to date type should throw an exception.");
            }
            catch (TypeMismatchException)
            {}
        }
예제 #2
0
 public void SetUp()
 {
     mgr = new BaseBindingManager();
     mgr.AddBinding("['name']", "Name");
     mgr.AddBinding("['dob']", "DOB");
     mgr.AddBinding("['dateofgraduation']", "DateOfGraduation");
     mgr.AddBinding("['inventions']", "Inventions");
     mgr.AddBinding("['cityOfBirth']", "PlaceOfBirth.City");
     mgr.AddBinding("['countryOfBirth']", "PlaceOfBirth.Country");
 }
 public void SetUp()
 {
     mgr = new BaseBindingManager();
     mgr.AddBinding("['name']", "Name");
     mgr.AddBinding("['dob']", "DOB");
     mgr.AddBinding("['dateofgraduation']", "DateOfGraduation");
     mgr.AddBinding("['inventions']", "Inventions");
     mgr.AddBinding("['cityOfBirth']", "PlaceOfBirth.City");
     mgr.AddBinding("['countryOfBirth']", "PlaceOfBirth.Country");
 }
예제 #4
0
        public void DirectionTargetToSource()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            Inventor           source = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Hashtable          target = new Hashtable();

            dbm.AddBinding("Name", "['name']", BindingDirection.TargetToSource);
            dbm.BindSourceToTarget(source, target, null);
            Assert.IsNull(target["name"]);

            target["name"] = "Mihajlo Pupin";
            dbm.BindTargetToSource(source, target, null);
            Assert.AreEqual("Mihajlo Pupin", source.Name);
        }
예제 #5
0
        public void BindNullValuesWithFormatter()
        {
            Hashtable source;
            Inventor  target;

            target = new Inventor();
            source = new Hashtable();

            // this is legal (dog is nullable)
            BaseBindingManager mgr = new BaseBindingManager();

            mgr.AddBinding("['dateofgraduation']", "DateOfGraduation", new HasTextFilteringFormatter(null, null));

            source["dateofgraduation"] = string.Empty;
            target.DateOfGraduation    = DateTime.Now;
            mgr.BindSourceToTarget(source, target, null);
            Assert.IsNull(target.DateOfGraduation);
        }
예제 #6
0
        public void HandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            IValidationErrors  errors = new ValidationErrors();
            Inventor           st     = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            st.Inventions = new string[] { "Invention One", "Invention Two" };

            SimpleExpressionBinding binding = new SimpleExpressionBinding("pob", "DOB");

            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindTargetToSource(st, st, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindSourceToTarget(st, st, errors);
            Assert.AreEqual(new DateTime(1856, 7, 9), st.DOB);
        }
예제 #7
0
        public void UnhandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            Hashtable          source = new Hashtable();

            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            dbm.AddBinding("['boolValue']", "DOB");

            try
            {
                dbm.BindSourceToTarget(source, target, null);
                Assert.Fail("Binding boolean to date should throw an exception.");
            }
            catch (TypeMismatchException)
            {}

            // binding state is not remembered with ValidationErrors=null!
            dbm.BindTargetToSource(source, target, null);
            Assert.AreEqual(target.DOB, source["boolValue"]);
        }
예제 #8
0
        public void BindNullValues()
        {
            Hashtable source;
            Inventor  target;

            target = new Inventor();
            source = new Hashtable();

            // this is legal (dog is nullable)
            BaseBindingManager mgr = new BaseBindingManager();

            mgr.AddBinding("['dateofgraduation']", "DateOfGraduation");

            source["dateofgraduation"] = null;
            target.DateOfGraduation    = DateTime.Now;
            mgr.BindSourceToTarget(source, target, null);
            Assert.IsNull(target.DateOfGraduation);

            source["dateofgraduation"] = DateTime.Now;
            mgr.BindTargetToSource(source, target, null);
            Assert.IsNull(source["dateofgraduation"]);
        }
예제 #9
0
        public void HandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm    = new BaseBindingManager();
            IValidationErrors  errors = new ValidationErrors();
            Hashtable          source = new Hashtable();

            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            SimpleExpressionBinding binding = new SimpleExpressionBinding("['boolValue']", "DOB");

            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindSourceToTarget(source, target, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindTargetToSource(source, target, errors);
            Assert.AreEqual(false, source["boolValue"]);
        }
        public void HandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            IValidationErrors errors = new ValidationErrors();
            Inventor st = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            st.Inventions = new string[] {"Invention One", "Invention Two"};

            SimpleExpressionBinding binding = new SimpleExpressionBinding("pob", "DOB");
            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindTargetToSource(st, st, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindSourceToTarget(st, st, errors);
            Assert.AreEqual(new DateTime(1856, 7, 9), st.DOB);
        }
        public void DirectionTargetToSource()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            Inventor source = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            Hashtable target = new Hashtable();
            
            dbm.AddBinding("Name", "['name']", BindingDirection.TargetToSource);
            dbm.BindSourceToTarget(source, target, null);
            Assert.IsNull(target["name"]);

            target["name"] = "Mihajlo Pupin";
            dbm.BindTargetToSource(source, target, null);
            Assert.AreEqual("Mihajlo Pupin", source.Name);
        }
        public void HandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            IValidationErrors errors = new ValidationErrors();
            Hashtable source = new Hashtable();
            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            SimpleExpressionBinding binding = new SimpleExpressionBinding("['boolValue']", "DOB");
            binding.SetErrorMessage("error", "errors");
            dbm.AddBinding(binding);

            dbm.BindSourceToTarget(source, target, errors);
            Assert.IsFalse(binding.IsValid(errors));
            Assert.IsFalse(errors.IsEmpty);
            Assert.AreEqual(1, errors.GetErrors("errors").Count);

            // make sure that the old value doesn't override current invalid value
            dbm.BindTargetToSource(source, target, errors);
            Assert.AreEqual(false, source["boolValue"]);
        }
        public void UnhandledTypeConversionExceptionTargetToSource()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            Inventor st = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            st.Inventions = new string[] {"Invention One", "Invention Two"};

            dbm.AddBinding("pob", "DOB");

            try
            {
                dbm.BindTargetToSource(st, st, null);
                Assert.Fail("Binding date to custom Place type should throw an exception.");
            }
            catch (TypeMismatchException)
            {}

            // binding state is not remembered with ValidationErrors=null!
            try
            {
                dbm.BindSourceToTarget(st, st, null);
                Assert.Fail("Binding custom Place to date type should throw an exception.");
            }
            catch (TypeMismatchException)
            {}
        }
        public void UnhandledTypeConversionExceptionSourceToTarget()
        {
            BaseBindingManager dbm = new BaseBindingManager();
            Hashtable source = new Hashtable();
            source["boolValue"] = false;
            Inventor target = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            
            dbm.AddBinding("['boolValue']", "DOB");

            try
            {
                dbm.BindSourceToTarget(source, target, null);
                Assert.Fail("Binding boolean to date should throw an exception.");
            }
            catch (TypeMismatchException)
            {}

            // binding state is not remembered with ValidationErrors=null!
            dbm.BindTargetToSource(source, target, null);
            Assert.AreEqual(target.DOB, source["boolValue"]);
        }
        public void BindNullValuesWithFormatter()
        {
            Hashtable source;
            Inventor target;

            target = new Inventor();
            source = new Hashtable();

            // this is legal (dog is nullable)
            BaseBindingManager mgr = new BaseBindingManager();
            mgr.AddBinding("['dateofgraduation']", "DateOfGraduation", new HasTextFilteringFormatter(null, null));

            source["dateofgraduation"] = string.Empty;
            target.DateOfGraduation = DateTime.Now;
            mgr.BindSourceToTarget(source, target, null);
            Assert.IsNull(target.DateOfGraduation);
        }
        public void BindNullValues()
        {
            Hashtable source;
            Inventor target;

            target = new Inventor();
            source = new Hashtable();

            // this is legal (dog is nullable)
            BaseBindingManager mgr = new BaseBindingManager();
            mgr.AddBinding("['dateofgraduation']", "DateOfGraduation");

            source["dateofgraduation"] = null;
            target.DateOfGraduation = DateTime.Now;
            mgr.BindSourceToTarget(source, target, null);
            Assert.IsNull(target.DateOfGraduation);

            source["dateofgraduation"] = DateTime.Now;
            mgr.BindTargetToSource(source, target, null);
            Assert.IsNull(source["dateofgraduation"]);
        }