public void BindingValueChangedControl_SetBindingWithPrivatePropertyAndNoTarget_ValueChangedFires()
        {
#if ANDROID
            SourcePrivate = new EditText(Application.Context);
#elif __IOS__
            SourcePrivate = new UITextViewEx();
#endif

            var valueChangedFired = false;

            var bindingGeneric = this.SetBinding(
                () => SourcePrivate.Text);

            _binding = bindingGeneric;

            _binding.ValueChanged += (s, e) =>
            {
                valueChangedFired = true;
            };

            Assert.IsFalse(valueChangedFired);
            Assert.AreEqual(
                SourcePrivate.Text,
                bindingGeneric.Value);

            var newValue = DateTime.Now.Ticks.ToString();
            SourcePrivate.Text = newValue;

            Assert.IsTrue(valueChangedFired);
            Assert.AreEqual(
                newValue,
                bindingGeneric.Value);
        }
Ejemplo n.º 2
0
        public void Binding_TwoWayFromViewModelToEditTextWithUpdateTrigger_BindingGetsUpdated()
        {
            var vm = new TestViewModel
            {
                Model = new TestModel()
            };

            var control1 = new UITextViewEx();

            _binding = new Binding <string, string>(
                vm,
                () => vm.Model.StringProperty,
                control1,
                () => control1.Text,
                BindingMode.TwoWay)
                       .UpdateTargetTrigger();

            Assert.AreEqual(null, vm.Model.StringProperty);
            Assert.AreEqual(string.Empty, control1.Text);
            var value = DateTime.Now.Ticks.ToString();

            vm.Model.StringProperty = value;
            Assert.AreEqual(value, vm.Model.StringProperty);
            Assert.AreEqual(vm.Model.StringProperty, control1.Text);

            value        += "Suffix";
            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.AreEqual(control1.Text, vm.Model.StringProperty);
        }
        public void BindingValueChangedControl_NewBindingWithVarAndNoTarget_ValueChangedFires()
        {
#if ANDROID
            var source = new EditText(Application.Context);
#elif __IOS__
            var source = new UITextViewEx();
#endif

            var valueChangedFired = false;

            var bindingGeneric = new Binding <string, string>(
                source,
                () => source.Text);

            _binding = bindingGeneric;

            _binding.ValueChanged += (s, e) =>
            {
                valueChangedFired = true;
            };

            Assert.IsFalse(valueChangedFired);
            Assert.AreEqual(
                source.Text,
                bindingGeneric.Value);

            var newValue = DateTime.Now.Ticks.ToString();
            source.Text = newValue;

            Assert.IsTrue(valueChangedFired);
            Assert.AreEqual(
                newValue,
                bindingGeneric.Value);
        }
Ejemplo n.º 4
0
        public void BindingConverter_ConvertDateTimeTwoWayToText_NoError()
        {
            var now = DateTime.Now;

            Vm = new TestViewModel
            {
                Date = now
            };

#if ANDROID
            Text = new EditText(Application.Context);
#elif __IOS__
            Text = new UITextViewEx();
#endif

            this.SetBinding(
                () => Vm.Date,
                () => Text.Text,
                BindingMode.TwoWay)
            .ConvertSourceToTarget(d => d.Date.ToShortDateString())
            .ConvertTargetToSource(d => DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture));

            Assert.AreEqual(now, Vm.Date);
            Assert.AreEqual(now.ToShortDateString(), Text.Text);
            Vm.Date += TimeSpan.FromDays(3);
            Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);

            var newDateString = "13/04/1971";
            var newDate       = new DateTime(1971, 4, 13);
            Text.Text = newDateString;

            Assert.AreEqual(newDateString, Text.Text);
            Assert.AreEqual(newDate, Vm.Date);
        }
Ejemplo n.º 5
0
        public void BindingConverter_ConvertBackFromMinDate_NoError()
        {
            Vm = new TestViewModel();

#if ANDROID
            Text = new EditText(Application.Context);
#elif __IOS__
            Text = new UITextViewEx();
#endif

            this.SetBinding(
                () => Vm.Date,
                () => Text.Text,
                BindingMode.TwoWay)
            .ConvertSourceToTarget(d => d.Date.ToShortDateString())
            .ConvertTargetToSource(d => DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture));

            Assert.AreEqual(DateTime.MinValue, Vm.Date);
            Assert.AreEqual(DateTime.MinValue.ToShortDateString(), Text.Text);

            var newDateString = "01/01/000"; // Invalid date string
            Text.Text = newDateString;

            Assert.AreEqual(newDateString, Text.Text);
            Assert.AreEqual(DateTime.MinValue, Vm.Date);

            newDateString = "01/01/0002"; // Valid date string
            Text.Text     = newDateString;

            Assert.AreEqual(newDateString, Text.Text);
            Assert.AreEqual(new DateTime(2, 1, 1), Vm.Date);
        }
Ejemplo n.º 6
0
        public void BindingConverter_ConvertDateTimeToText_NoError()
        {
            var now = DateTime.Now;

            Vm = new TestViewModel
            {
                Date = now
            };

#if ANDROID
            Text = new EditText(Application.Context);
#elif __IOS__
            Text = new UITextViewEx();
#endif

            this.SetBinding(
                () => Vm.Date,
                () => Text.Text)
            .ConvertSourceToTarget(d => d.Date.ToShortDateString());

            Assert.AreEqual(now, Vm.Date);
            Assert.AreEqual(now.ToShortDateString(), Text.Text);

            Vm.Date += TimeSpan.FromDays(3);

            Assert.AreEqual((now + TimeSpan.FromDays(3)).ToShortDateString(), Text.Text);
        }
Ejemplo n.º 7
0
        public void Binding_TwoWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated()
        {
            var vm = new TestViewModel
            {
                Model = new TestModel()
            };

            var control1 = new UITextViewEx();

            _binding = new Binding <string, string>(
                control1,
                () => control1.Text,
                vm,
                () => vm.Model.StringProperty,
                BindingMode.TwoWay)
                       .ObserveSourceEvent(UpdateTriggerMode.PropertyChanged);

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.AreEqual(control1.Text, vm.Model.StringProperty);
            var value = DateTime.Now.Ticks.ToString();

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.AreEqual(control1.Text, vm.Model.StringProperty);

            value += "Suffix";
            vm.Model.StringProperty = value;
            Assert.AreEqual(value, vm.Model.StringProperty);
            Assert.AreEqual(vm.Model.StringProperty, control1.Text);
        }
Ejemplo n.º 8
0
        public void BindingTargetControl_SetBindingWithPublicProperty_NoError()
        {
            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    StringProperty = "Initial value"
                }
            };

#if ANDROID
            Target = new EditText(Application.Context);
#elif __IOS__
            Target = new UITextViewEx();
#endif

            _binding = this.SetBinding(
                () => VmSource.Model.StringProperty,
                () => Target.Text);

            Assert.AreEqual(VmSource.Model.StringProperty, Target.Text);
            var newValue = DateTime.Now.Ticks.ToString();
            VmSource.Model.StringProperty = newValue;
            Assert.AreEqual(VmSource.Model.StringProperty, Target.Text);
        }
Ejemplo n.º 9
0
        public void Binding_TwoWayFromEditTextToEditTextWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UITextViewEx();

            _binding = new Binding <string, string>(
                control1,
                () => control1.Text,
                control2,
                () => control2.Text,
                BindingMode.TwoWay)
                       .UpdateSourceTrigger()
                       .UpdateTargetTrigger();

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.AreEqual(control1.Text, control2.Text);
            var value = DateTime.Now.Ticks.ToString();

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.AreEqual(control1.Text, control2.Text);

            value        += "Suffix";
            control2.Text = value;
            Assert.AreEqual(value, control2.Text);
            Assert.AreEqual(control2.Text, control1.Text);
        }
Ejemplo n.º 10
0
        public void Binding_TwoWayFromEditTextToCheckBoxWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UISwitchEx();

            _binding = new Binding <string, bool>(
                control1,
                () => control1.Text,
                control2,
                () => control2.On,
                BindingMode.TwoWay)
                       .UpdateSourceTrigger()
                       .UpdateTargetTrigger();

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.IsFalse(control2.On);
            var value = "True";

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.IsTrue(control2.On);

            control2.On = false;
            Assert.IsFalse(control2.On);
            Assert.AreEqual("False", control1.Text);
        }
Ejemplo n.º 11
0
        public void BindingTargetControl_NewBindingWithPrivateProperty_NoError()
        {
            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    MyProperty = "Initial value"
                }
            };

#if ANDROID
            TargetPrivate = new EditText(Application.Context);
#elif __IOS__
            TargetPrivate = new UITextViewEx();
#endif

            _binding = new Binding <string, string>(
                VmSource,
                () => VmSource.Model.MyProperty,
                TargetPrivate,
                () => TargetPrivate.Text);

            Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
            var newValue = DateTime.Now.Ticks.ToString();
            VmSource.Model.MyProperty = newValue;
            Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
        }
Ejemplo n.º 12
0
        public void BindingTargetControl_SetBindingWithPrivatePropertyTwoWay_NoError()
        {
            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    MyProperty = "Initial value"
                }
            };

#if ANDROID
            TargetPrivate = new EditText(Application.Context);
#elif __IOS__
            TargetPrivate = new UITextViewEx();
#endif

            _binding = this.SetBinding(
                () => VmSource.Model.MyProperty,
                () => TargetPrivate.Text,
                BindingMode.TwoWay);

            Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
            var newValue = DateTime.Now.Ticks.ToString();
            VmSource.Model.MyProperty = newValue;
            Assert.AreEqual(newValue, TargetPrivate.Text);
            newValue          += "Suffix";
            TargetPrivate.Text = newValue;
            Assert.AreEqual(newValue, VmSource.Model.MyProperty);
        }
Ejemplo n.º 13
0
        public void BindingTargetControl_NewBindingWithVarTwoWay_NoError()
        {
            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    MyProperty = "Initial value"
                }
            };

#if ANDROID
            var target = new EditText(Application.Context);
#elif __IOS__
            var target = new UITextViewEx();
#endif

            _binding = new Binding <string, string>(
                VmSource,
                () => VmSource.Model.MyProperty,
                target,
                () => target.Text,
                BindingMode.TwoWay);

            Assert.AreEqual(VmSource.Model.MyProperty, target.Text);
            var newValue = DateTime.Now.Ticks.ToString();
            VmSource.Model.MyProperty = newValue;
            Assert.AreEqual(newValue, target.Text);
            newValue   += "Suffix";
            target.Text = newValue;
            Assert.AreEqual(newValue, VmSource.Model.MyProperty);
        }
Ejemplo n.º 14
0
        public void Binding_TwoWayFromCheckBoxToEditTextWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UISwitchEx();

            _binding = new Binding <bool, string>(
                control2,
                () => control2.On,
                control1,
                () => control1.Text,
                BindingMode.TwoWay)
                       .ObserveSourceEvent(UpdateTriggerMode.PropertyChanged)
                       .ObserveTargetEvent(UpdateTriggerMode.PropertyChanged);

            Assert.AreEqual("False", control1.Text);
            Assert.IsFalse(control2.On);
            control2.On = true;
            Assert.AreEqual("True", control1.Text);
            Assert.IsTrue(control2.On);

            var value = "False";

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.IsFalse(control2.On);
        }
Ejemplo n.º 15
0
        public void BindingTargetControl_NewBindingWithPublicPropertyTwoWay_NoError()
        {
            var valueChangedFired = false;

            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    MyProperty = "Initial value"
                }
            };

#if ANDROID
            Target = new EditText(Application.Context);
#elif __IOS__
            Target = new UITextViewEx();
#endif

            var bindingGeneric = new Binding <string, string>(
                VmSource,
                () => VmSource.Model.MyProperty,
                Target,
                () => Target.Text,
                BindingMode.TwoWay);

            _binding = bindingGeneric;

            _binding.ValueChanged += (s, e) =>
            {
                valueChangedFired = true;
            };

            Assert.IsFalse(valueChangedFired);
            Assert.AreEqual(
                VmSource.Model.MyProperty,
                bindingGeneric.Value);

            var newValue = DateTime.Now.Ticks.ToString();
            VmSource.Model.MyProperty = newValue;

            Assert.IsTrue(valueChangedFired);
            Assert.AreEqual(
                newValue,
                bindingGeneric.Value);

            valueChangedFired = false;

            newValue   += "Suffix";
            Target.Text = newValue;

            Assert.IsTrue(valueChangedFired);
            Assert.AreEqual(
                newValue,
                bindingGeneric.Value);
        }
        public void Binding_OneWayFromCheckBoxToEditTextWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UISwitchEx();

            _binding = new Binding <bool, string>(
                control2,
                () => control2.On,
                control1,
                () => control1.Text);

            Assert.AreEqual("False", control1.Text);
            Assert.IsFalse(control2.On);
            control2.On = true;
            Assert.AreEqual("True", control1.Text);
            Assert.IsTrue(control2.On);
        }
        public void Binding_OneWayFromEditTextToEditTextWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UITextViewEx();

            _binding = new Binding <string, string>(
                control1,
                () => control1.Text,
                control2,
                () => control2.Text);

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.AreEqual(control1.Text, control2.Text);
            var value = DateTime.Now.Ticks.ToString();

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.AreEqual(control1.Text, control2.Text);
        }
        public void BindingSourceControl_SetBindingWithPrivateProperty_NoError()
        {
#if ANDROID
            SourcePrivate = new EditText(Application.Context);
#elif __IOS__
            SourcePrivate = new UITextViewEx();
#endif

            VmTarget = new TestViewModel();

            _binding = this.SetBinding(
                () => SourcePrivate.Text,
                () => VmTarget.TargetProperty);

            Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
            var newValue2 = DateTime.Now.Ticks.ToString();
            SourcePrivate.Text = newValue2;
            Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
        }
Ejemplo n.º 19
0
        public void Binding_OneWayFromEditTextToCheckBoxWithUpdateTrigger_BindingGetsUpdated()
        {
            var control1 = new UITextViewEx();
            var control2 = new UISwitchEx();

            _binding = new Binding <string, bool>(
                control1,
                () => control1.Text,
                control2,
                () => control2.On)
                       .ObserveSourceEvent(UpdateTriggerMode.PropertyChanged);

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.IsFalse(control2.On);
            var value = "True";

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.IsTrue(control2.On);
        }
        public void BindingSourceControl_NewBindingWithPublicProperty_NoError()
        {
#if ANDROID
            Source = new EditText(Application.Context);
#elif __IOS__
            Source = new UITextViewEx();
#endif

            VmTarget = new TestViewModel();

            _binding = new Binding <string, string>(
                Source,
                () => Source.Text,
                VmTarget,
                () => VmTarget.TargetProperty);

            Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
            var newValue = DateTime.Now.Ticks.ToString();
            Source.Text = newValue;
            Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
        }
        public void BindingValueChangedControl_NewBindingWithPublicProperty_ValueChangedFires()
        {
#if ANDROID
            Source = new EditText(Application.Context);
#elif __IOS__
            Source = new UITextViewEx();
#endif

            var valueChangedFired = false;

            VmTarget = new TestViewModel();

            var bindingGeneric = new Binding <string, string>(
                Source,
                () => Source.Text,
                VmTarget,
                () => VmTarget.TargetProperty);

            _binding = bindingGeneric;

            _binding.ValueChanged += (s, e) =>
            {
                valueChangedFired = true;
            };

            Assert.IsFalse(valueChangedFired);
            Assert.AreEqual(
                Source.Text,
                bindingGeneric.Value);

            var newValue = DateTime.Now.Ticks.ToString();
            Source.Text = newValue;

            Assert.IsTrue(valueChangedFired);
            Assert.AreEqual(
                newValue,
                bindingGeneric.Value);
        }
        public void Binding_OneWayFromEditTextToViewModelWithUpdateTrigger_BindingGetsUpdated()
        {
            var vm = new TestViewModel
            {
                Model = new TestModel()
            };

            var control1 = new UITextViewEx();

            _binding = new Binding <string, string>(
                control1,
                () => control1.Text,
                vm,
                () => vm.Model.MyProperty);

            Assert.AreEqual(string.Empty, control1.Text);
            Assert.AreEqual(control1.Text, vm.Model.MyProperty);
            var value = DateTime.Now.Ticks.ToString();

            control1.Text = value;
            Assert.AreEqual(value, control1.Text);
            Assert.AreEqual(control1.Text, vm.Model.MyProperty);
        }
Ejemplo n.º 23
0
        public void Binding_OneWayFromViewModelToEditText_BindingGetsUpdated()
        {
            var vm = new TestViewModel
            {
                Model = new TestModel()
            };

            var control1 = new UITextViewEx();

            _binding = new Binding <string, string>(
                vm,
                () => vm.Model.StringProperty,
                control1,
                () => control1.Text);

            Assert.AreEqual(null, vm.Model.StringProperty);
            Assert.AreEqual(string.Empty, control1.Text);
            var value = DateTime.Now.Ticks.ToString();

            vm.Model.StringProperty = value;
            Assert.AreEqual(value, vm.Model.StringProperty);
            Assert.AreEqual(vm.Model.StringProperty, control1.Text);
        }
Ejemplo n.º 24
0
        public void Binding_SetBindingWithPrivateField_ShouldCreateBinding()
        {
            // Just for comparison
            var vm = new TestViewModel
            {
                Model = new TestModel
                {
                    StringProperty = "Initial value for local var"
                }
            };

#if ANDROID
            var textBox = new EditText(Application.Context);
#elif __IOS__
            var textBox = new UITextViewEx();
#endif

            _binding = new Binding <string, string>(
                vm,
                () => vm.Model.StringProperty,
                textBox,
                () => textBox.Text);

            Assert.IsNotNull(_binding);
            Assert.AreEqual(textBox.Text, vm.Model.StringProperty);
            vm.Model.StringProperty = "New value";
            Assert.AreEqual(textBox.Text, vm.Model.StringProperty);

            _vmField = new TestViewModel
            {
                Model = new TestModel
                {
                    StringProperty = "Initial value for field"
                }
            };

            _binding = new Binding <string, string>(
                _vmField,
                () => _vmField.Model.StringProperty,
                textBox,
                () => textBox.Text);

            Assert.IsNotNull(_binding);
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);
            _vmField.Model.StringProperty = "New value";
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);

            VmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    StringProperty = "Initial value for public property"
                }
            };

#if ANDROID
            TextBox = new EditText(Application.Context);
#elif __IOS__
            TextBox = new UITextViewEx();
#endif

            _binding = this.SetBinding(
                () => VmSource.Model.StringProperty,
                () => TextBox.Text);

            Assert.IsNotNull(_binding);
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);
            _vmField.Model.StringProperty = "New value";
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);

            _vmField.Model.StringProperty = "Initial value for field again";

            _binding = this.SetBinding(
                () => _vmField.Model.StringProperty,
                () => TextBox.Text);

            Assert.IsNotNull(_binding);
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);
            _vmField.Model.StringProperty = "New value";
            Assert.AreEqual(textBox.Text, _vmField.Model.StringProperty);
        }