public void TargetPropertyNotChangedOnUnsetObject_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("Data", "GetO", View, source);
            object value = new object();

            Behavior.Arg1 = value;
            Assert.AreEqual(value, View.Data);
            Behavior.Function = "GetUnsetValue";
            Assert.AreEqual(value, View.Data);
            IValueConverter converter = new BooleanToObjectConverter()
            {
                TrueValue  = 12d,
                FalseValue = DependencyProperty.UnsetValue
            };

            Behavior.Arg1 = false;
            Assert.AreEqual(value, View.Data);
            Behavior.Function = "GetB";
            Assert.AreEqual(false, View.Data);
            Behavior.Converter = converter;
            Assert.AreEqual(false, View.Data);
            Behavior.Arg1 = true;
            Assert.AreEqual(12d, View.Data);
        }
        public void CallSourceStaticMethod_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("Data", "GetA", View, source);
            Behavior.Arg1 = 0f;
            Assert.AreEqual(0f, View.Data);
        }
        public void SetTargetStaticProperty_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("StringStatic", "GetString", View, source);
            Assert.IsNull(MBBControl.StringStatic);
            Behavior.Arg1 = "some string";
            Assert.AreEqual("some string", MBBControl.StringStatic);
        }
        public void TargetPropertyChangedOnArgsChanged_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("DoubleData", "GetD", View, source);
            Behavior.Arg1 = 10d;
            Assert.AreEqual(10d, View.DoubleData);
            Behavior.Arg1 = 1d;
            Assert.AreEqual(1d, View.DoubleData);
        }
        public void PassParameterToConverter_Test()
        {
            var source = new MBBObject();
            DoubleToIntConverter converter = new DoubleToIntConverter();

            PrepareBehavior("Data", "GetA", View, source);
            Behavior.Converter          = converter;
            Behavior.ConverterParameter = 5;
            Behavior.Arg1 = 10;
            Assert.AreEqual(5, converter.Parameter);
        }
        public void TargetPropertyChangedOnConverterChanged_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("Data", "GetD", View, source);
            Behavior.Arg1 = 10d;
            Assert.AreEqual(10d, View.Data);
            Assert.IsTrue(View.Data is double);
            Behavior.Converter = new DoubleToIntConverter();
            Assert.AreEqual(10, View.Data);
            Assert.IsTrue(View.Data is int);
        }
        public void UseDataContextIfSourceNotSpecified_Test03()
        {
            var source = new MBBObject();
            FrameworkContentElement wce = new FrameworkContentElement();

            wce.DataContext = source;
            PrepareBehavior("Name", "GetString", null, null, false);
            Window.Content = wce;
            Behavior.Arg1  = "WCE_Test02";
            Interaction.GetBehaviors(wce).Add(Behavior);
            Assert.AreEqual("WCE_Test02", wce.Name);
        }
        public void DataContextShouldNotAffectBehaviorResultIfSourceSet_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("DoubleData", "GetD", View, source);
            Behavior.Arg1 = 10d;
            Assert.AreEqual(10d, View.DoubleData);
            View.DoubleData  = 0;
            View.DataContext = new MBBObject();
            Assert.AreEqual(0d, View.DoubleData);
            Behavior.Source = null;
            Assert.AreEqual(10d, View.DoubleData);
        }
        public void TargetPropertyNotChangedUntilBehaviorAttached_Test()
        {
            var source = new MBBObject();

            PrepareBehavior("IntData", "GetA", View, source, false);
            Assert.AreEqual(-1, View.IntData);
            Behavior.Arg1 = "10";
            Assert.AreEqual(-1, View.IntData);
            Behavior.Arg2 = 10d;
            Assert.AreEqual(-1, View.IntData);
            Interaction.GetBehaviors(View).Add(Behavior);
            Assert.AreEqual(2, View.IntData);
        }
        public void UseDefaultParamValueIfArgNotSet_Test()
        {
            var source = new MBBObject();
            DoubleToIntConverter converter = new DoubleToIntConverter();

            PrepareBehavior("IntData", "GetAD", View, source);
            Assert.AreEqual(10, View.IntData);
            Behavior.Arg1 = 12;
            Assert.AreEqual(12, View.IntData);
            Behavior.Arg1 = null;
            Assert.AreEqual(0, View.IntData);
            Binding binding = new Binding()
            {
                Path   = new PropertyPath("Data"),
                Source = View
            };

            Behavior.Arg1 = 12;
            BindingOperations.SetBinding(Behavior, FunctionBindingBehavior.Arg1Property, binding);
            Assert.AreEqual(0, View.IntData);
            View.Data = 15;
            Assert.AreEqual(15, View.IntData);
        }
 public void UseDataContextIfSourceNotSpecified_Test03() {
     var source = new MBBObject();
     FrameworkContentElement wce = new FrameworkContentElement();
     wce.DataContext = source;
     PrepareBehavior("Name", "GetString", null, null, false);
     Window.Content = wce;
     Behavior.Arg1 = "WCE_Test02";
     Interaction.GetBehaviors(wce).Add(Behavior);
     Assert.AreEqual("WCE_Test02", wce.Name);
 }
 public void TargetPropertyChangedOnArgsChanged_Test() {
     var source = new MBBObject();
     PrepareBehavior("DoubleData", "GetD", View, source);
     Behavior.Arg1 = 10d;
     Assert.AreEqual(10d, View.DoubleData);
     Behavior.Arg1 = 1d;
     Assert.AreEqual(1d, View.DoubleData);
 }
 public void TargetPropertyChangedOnConverterChanged_Test() {
     var source = new MBBObject();
     PrepareBehavior("Data", "GetD", View, source);
     Behavior.Arg1 = 10d;
     Assert.AreEqual(10d, View.Data);
     Assert.IsTrue(View.Data is double);
     Behavior.Converter = new DoubleToIntConverter();
     Assert.AreEqual(10, View.Data);
     Assert.IsTrue(View.Data is int);
 }
 public void PassParameterToConverter_Test() {
     var source = new MBBObject();
     DoubleToIntConverter converter = new DoubleToIntConverter();
     PrepareBehavior("Data", "GetA", View, source);
     Behavior.Converter = converter;
     Behavior.ConverterParameter = 5;
     Behavior.Arg1 = 10;
     Assert.AreEqual(5, converter.Parameter);
 }
 public void TargetPropertyNotChangedOnUnsetObject_Test() {
     var source = new MBBObject();
     PrepareBehavior("Data", "GetO", View, source);
     object value = new object();
     Behavior.Arg1 = value;
     Assert.AreEqual(value, View.Data);
     Behavior.Function = "GetUnsetValue";
     Assert.AreEqual(value, View.Data);
     IValueConverter converter = new BooleanToObjectConverter() {
         TrueValue = 12d,
         FalseValue = DependencyProperty.UnsetValue
     };
     Behavior.Arg1 = false;
     Assert.AreEqual(value, View.Data);
     Behavior.Function = "GetB";
     Assert.AreEqual(false, View.Data);
     Behavior.Converter = converter;
     Assert.AreEqual(false, View.Data);
     Behavior.Arg1 = true;
     Assert.AreEqual(12d, View.Data);
 }
 public void UseDefaultParamValueIfArgNotSet_Test() {
     var source = new MBBObject();
     DoubleToIntConverter converter = new DoubleToIntConverter();
     PrepareBehavior("IntData", "GetAD", View, source);
     Assert.AreEqual(10, View.IntData);
     Behavior.Arg1 = 12;
     Assert.AreEqual(12, View.IntData);
     Behavior.Arg1 = null;
     Assert.AreEqual(0, View.IntData);
     Binding binding = new Binding() {
         Path = new PropertyPath("Data"),
         Source = View
     };
     Behavior.Arg1 = 12;
     BindingOperations.SetBinding(Behavior, FunctionBindingBehavior.Arg1Property, binding);
     Assert.AreEqual(0, View.IntData);
     View.Data = 15;
     Assert.AreEqual(15, View.IntData);
 }
 public void CallSourceStaticMethod_Test() {
     var source = new MBBObject();
     PrepareBehavior("Data", "GetA", View, source);
     Behavior.Arg1 = 0f;
     Assert.AreEqual(0f, View.Data);
 }
 public void TargetPropertyNotChangedUntilBehaviorAttached_Test() {
     var source = new MBBObject();
     PrepareBehavior("IntData", "GetA", View, source, false);
     Assert.AreEqual(-1, View.IntData);
     Behavior.Arg1 = "10";
     Assert.AreEqual(-1, View.IntData);
     Behavior.Arg2 = 10d;
     Assert.AreEqual(-1, View.IntData);
     Interaction.GetBehaviors(View).Add(Behavior);
     Assert.AreEqual(2, View.IntData);
 }
 public void DataContextShouldNotAffectBehaviorResultIfSourceSet_Test() {
     var source = new MBBObject();
     PrepareBehavior("DoubleData", "GetD", View, source);
     Behavior.Arg1 = 10d;
     Assert.AreEqual(10d, View.DoubleData);
     View.DoubleData = 0;
     View.DataContext = new MBBObject();
     Assert.AreEqual(0d, View.DoubleData);
     Behavior.Source = null;
     Assert.AreEqual(10d, View.DoubleData);
 }
 public void SetTargetStaticProperty_Test() {
     var source = new MBBObject();
     PrepareBehavior("StringStatic", "GetString", View, source);
     Assert.IsNull(MBBControl.StringStatic);
     Behavior.Arg1 = "some string";
     Assert.AreEqual("some string", MBBControl.StringStatic);
 }