Fixing an issue in the Binding when using a binding with a source
but without a target (for Command binding). Adding unit tests for Binding Value and ValueChanged.
This commit is contained in:
Родитель
5f183bad19
Коммит
4d174aea9d
|
@ -173,6 +173,27 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
BindingMode mode = BindingMode.Default,
|
||||
TSource fallbackValue = default(TSource),
|
||||
TSource targetNullValue = default(TSource))
|
||||
: this(
|
||||
source,
|
||||
sourcePropertyExpression,
|
||||
null,
|
||||
target,
|
||||
targetPropertyExpression,
|
||||
mode,
|
||||
fallbackValue,
|
||||
targetNullValue)
|
||||
{
|
||||
}
|
||||
|
||||
internal Binding(
|
||||
object source,
|
||||
Expression<Func<TSource>> sourcePropertyExpression,
|
||||
bool? resolveTopField,
|
||||
object target = null,
|
||||
Expression<Func<TTarget>> targetPropertyExpression = null,
|
||||
BindingMode mode = BindingMode.Default,
|
||||
TSource fallbackValue = default(TSource),
|
||||
TSource targetNullValue = default(TSource))
|
||||
{
|
||||
Mode = mode;
|
||||
FallbackValue = fallbackValue;
|
||||
|
@ -190,7 +211,9 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
TopSource.Target,
|
||||
TopTarget.Target,
|
||||
mode,
|
||||
target == null && targetPropertyExpression != null);
|
||||
resolveTopField == null
|
||||
? (target == null && targetPropertyExpression != null)
|
||||
: resolveTopField.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -249,10 +272,7 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
public override void ForceUpdateValueFromSourceToTarget()
|
||||
{
|
||||
if (_onSourceUpdate == null
|
||||
&& (_propertyTarget == null
|
||||
|| !_propertyTarget.IsAlive
|
||||
|| _propertyTarget.Target == null
|
||||
|| _propertySource == null
|
||||
&& (_propertySource == null
|
||||
|| !_propertySource.IsAlive
|
||||
|| _propertySource.Target == null))
|
||||
{
|
||||
|
@ -1271,14 +1291,10 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
internal class ObjectSwappedEventListener : IWeakEventListener
|
||||
{
|
||||
private readonly WeakReference _bindingReference;
|
||||
private readonly WeakReference _instanceReference;
|
||||
|
||||
public WeakReference InstanceReference
|
||||
{
|
||||
get
|
||||
{
|
||||
return _instanceReference;
|
||||
}
|
||||
get;
|
||||
}
|
||||
|
||||
public ObjectSwappedEventListener(
|
||||
|
@ -1286,14 +1302,14 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
INotifyPropertyChanged instance)
|
||||
{
|
||||
_bindingReference = new WeakReference(binding);
|
||||
_instanceReference = new WeakReference(instance);
|
||||
InstanceReference = new WeakReference(instance);
|
||||
}
|
||||
|
||||
public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
|
||||
{
|
||||
var propArgs = e as PropertyChangedEventArgs;
|
||||
|
||||
if (_instanceReference.Target == sender
|
||||
if (InstanceReference.Target == sender
|
||||
&& propArgs != null
|
||||
&& _bindingReference != null
|
||||
&& _bindingReference.IsAlive
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
return new Binding<TSource, TTarget>(
|
||||
source,
|
||||
sourcePropertyExpression,
|
||||
null,
|
||||
target,
|
||||
targetPropertyExpression,
|
||||
mode,
|
||||
|
@ -110,6 +111,7 @@ namespace GalaSoft.MvvmLight.Helpers
|
|||
return new Binding<TSource, TSource>(
|
||||
source,
|
||||
sourcePropertyExpression,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
mode,
|
||||
|
|
|
@ -310,5 +310,294 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _targetPrivate.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
Target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivatePropertyTwoWay_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,
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivateFieldTwoWay_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,
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
Target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPrivateFieldTwoWay_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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,35 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTargetPrivate,
|
||||
() => _vmTargetPrivate.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, _vmTargetPrivate.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
_vmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
|
@ -82,6 +111,35 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTargetPrivate,
|
||||
() => VmTargetPrivate.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTargetPrivate.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
VmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicField_NoError()
|
||||
{
|
||||
|
@ -107,6 +165,35 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTarget,
|
||||
() => _vmTarget.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, _vmTarget.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
_vmTarget.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicProperty_NoError()
|
||||
{
|
||||
|
@ -132,6 +219,35 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
VmTarget.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithVar_NoError()
|
||||
{
|
||||
|
@ -157,6 +273,35 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithVarTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var vmTarget = new TestViewModel();
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
vmTarget,
|
||||
() => vmTarget.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, vmTarget.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, vmTarget.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
vmTarget.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateField_NoError()
|
||||
{
|
||||
|
@ -180,6 +325,33 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTargetPrivate.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, _vmTargetPrivate.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
_vmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
|
@ -203,6 +375,33 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTargetPrivate.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTargetPrivate.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
VmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicField_NoError()
|
||||
{
|
||||
|
@ -226,6 +425,33 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTarget.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, _vmTarget.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
_vmTarget.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicProperty_NoError()
|
||||
{
|
||||
|
@ -248,5 +474,32 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetPropertyObservable,
|
||||
BindingMode.TwoWay);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetPropertyObservable);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.TargetPropertyObservable);
|
||||
newValue += "Suffix";
|
||||
VmTarget.TargetPropertyObservable = newValue;
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,733 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
|
||||
#elif __IOS__
|
||||
using GalaSoft.MvvmLight.Test.Controls;
|
||||
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingValueChangedFromSourceControlTest
|
||||
{
|
||||
private Helpers.Binding _binding;
|
||||
|
||||
#if ANDROID
|
||||
public EditText _source;
|
||||
private EditText _sourcePrivate;
|
||||
|
||||
public EditText Source
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private EditText SourcePrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#elif __IOS__
|
||||
public UITextViewEx _source;
|
||||
private UITextViewEx _sourcePrivate;
|
||||
|
||||
public UITextViewEx Source
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private UITextViewEx SourcePrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#endif
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPrivateProperty_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
SourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
SourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
SourcePrivate,
|
||||
() => SourcePrivate.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPublicField_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPrivateField_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_sourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_sourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_sourcePrivate,
|
||||
() => _sourcePrivate.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithVar_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
var source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
var 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPublicProperty_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
Source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => Source.Text,
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPrivateProperty_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
SourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
SourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => SourcePrivate.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPublicField_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _source.Text,
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPrivateField_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_sourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_sourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _sourcePrivate.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPublicPropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
Source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPrivatePropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
SourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
SourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
SourcePrivate,
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPublicFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_NewBindingWithPrivateFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_sourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_sourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_sourcePrivate,
|
||||
() => _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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPublicPropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
Source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPublicFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
#if ANDROID
|
||||
_source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var valueChangedFired = false;
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChangedControl_SetBindingWithPrivateFieldAndNoTarget_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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,743 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingValueChangedFromSourceTest
|
||||
{
|
||||
public TestViewModel _vmSource;
|
||||
private Helpers.Binding _binding;
|
||||
private TestViewModel _vmSourcePrivate;
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private TestViewModel VmSourcePrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPrivateField_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_vmSourcePrivate,
|
||||
() => _vmSourcePrivate.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
_vmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPrivateFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_vmSourcePrivate,
|
||||
() => _vmSourcePrivate.Model.MyProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
_vmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPrivateProperty_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSourcePrivate,
|
||||
() => VmSourcePrivate.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
VmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPrivatePropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSourcePrivate,
|
||||
() => VmSourcePrivate.Model.MyProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
VmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPublicField_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_vmSource,
|
||||
() => _vmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPublicFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
_vmSource,
|
||||
() => _vmSource.Model.MyProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPublicProperty_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithPublicPropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithVar_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
var vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
vmSource,
|
||||
() => vmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_NewBindingWithVarAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
var vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
vmSource,
|
||||
() => vmSource.Model.MyProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPrivateField_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _vmSourcePrivate.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
_vmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPrivateFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _vmSourcePrivate.Model.MyProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
_vmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPrivateProperty_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSourcePrivate.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
VmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPrivatePropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSourcePrivate.Model.MyProperty);
|
||||
|
||||
_binding = bindingGeneric;
|
||||
|
||||
_binding.ValueChanged += (s, e) =>
|
||||
{
|
||||
valueChangedFired = true;
|
||||
};
|
||||
|
||||
Assert.IsFalse(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
VmSourcePrivate.Model.MyProperty,
|
||||
bindingGeneric.Value);
|
||||
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPublicField_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _vmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPublicFieldAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => _vmSource.Model.MyProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPublicProperty_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingValueChanged_SetBindingWithPublicPropertyAndNoTarget_ValueChangedFires()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty);
|
||||
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,566 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
|
||||
#elif __IOS__
|
||||
using GalaSoft.MvvmLight.Test.Controls;
|
||||
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingValueChangedFromTargetControlTest
|
||||
{
|
||||
private Helpers.Binding _binding;
|
||||
|
||||
#if ANDROID
|
||||
public EditText _target;
|
||||
private EditText _targetPrivate;
|
||||
|
||||
private EditText TargetPrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public EditText Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#elif __IOS__
|
||||
public UITextViewEx _target;
|
||||
private UITextViewEx _targetPrivate;
|
||||
|
||||
public UITextViewEx Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private UITextViewEx TargetPrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#endif
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
TargetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
TargetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
TargetPrivate,
|
||||
() => TargetPrivate.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";
|
||||
TargetPrivate.Text = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPublicFieldTwoWay_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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_targetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_targetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_targetPrivate,
|
||||
() => _targetPrivate.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";
|
||||
_targetPrivate.Text = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithVarTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
var target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
var 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicPropertyTwoWay_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 = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => 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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
TargetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
TargetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => TargetPrivate.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";
|
||||
TargetPrivate.Text = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicFieldTwoWay_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 = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_targetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_targetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _targetPrivate.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";
|
||||
_targetPrivate.Text = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,504 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingValueChangedFromTargetTest
|
||||
{
|
||||
public TestViewModel _vmTarget;
|
||||
private Helpers.Binding _binding;
|
||||
private TestViewModel _vmTargetPrivate;
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private TestViewModel VmTargetPrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTargetPrivate,
|
||||
() => _vmTargetPrivate.TargetPropertyObservable,
|
||||
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";
|
||||
_vmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTargetPrivate,
|
||||
() => VmTargetPrivate.TargetPropertyObservable,
|
||||
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";
|
||||
VmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTarget,
|
||||
() => _vmTarget.TargetPropertyObservable,
|
||||
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";
|
||||
_vmTarget.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetPropertyObservable,
|
||||
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";
|
||||
VmTarget.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithVarTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var vmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = new Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
vmTarget,
|
||||
() => vmTarget.TargetPropertyObservable,
|
||||
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";
|
||||
vmTarget.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTargetPrivate.TargetPropertyObservable,
|
||||
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";
|
||||
_vmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivatePropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTargetPrivate.TargetPropertyObservable,
|
||||
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";
|
||||
VmTargetPrivate.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicFieldTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTarget.TargetPropertyObservable,
|
||||
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";
|
||||
_vmTarget.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicPropertyTwoWay_NoError()
|
||||
{
|
||||
var valueChangedFired = false;
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var bindingGeneric = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetPropertyObservable,
|
||||
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";
|
||||
VmTarget.TargetPropertyObservable = newValue;
|
||||
|
||||
Assert.IsTrue(valueChangedFired);
|
||||
Assert.AreEqual(
|
||||
newValue,
|
||||
bindingGeneric.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -87,11 +87,15 @@
|
|||
</Compile>
|
||||
<Compile Include="Binding\BindingAccountTest.cs" />
|
||||
<Compile Include="Binding\BindingDeepPathTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromTargetControlTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromTargetTest.cs" />
|
||||
<Compile Include="Binding\BindingTargetTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromSourceControlTest.cs" />
|
||||
<Compile Include="Binding\BindingSourceControlTest.cs" />
|
||||
<Compile Include="Binding\BindingTargetControlTest.cs" />
|
||||
<Compile Include="Binding\BindingTargetTest.cs" />
|
||||
<Compile Include="Binding\BindingSourceTest.cs" />
|
||||
<Compile Include="Binding\BindingTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromSourceTest.cs" />
|
||||
<Compile Include="Binding\ConverterTest.cs" />
|
||||
<Compile Include="Binding\SetCommandTest.cs" />
|
||||
<Compile Include="Binding\ObserveEventImplicitTest.cs" />
|
||||
|
|
|
@ -1,6 +1,30 @@
|
|||
|
||||
#if __IOS__
|
||||
using Foundation;
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.ViewModel
|
||||
{
|
||||
public class TestItem
|
||||
{
|
||||
public TestItem(string title)
|
||||
{
|
||||
Title = title;
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
// For tests only
|
||||
public NSIndexPath RowIndexPath
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ namespace GalaSoft.MvvmLight.Test.ViewModel
|
|||
private string _propertyValue;
|
||||
private RelayCommand<string> _setPropertyCommand;
|
||||
private RelayCommand _setPropertyWithoutValueCommand;
|
||||
|
||||
private string _targetPropertyObservable;
|
||||
private ICommand _testCommandImpl;
|
||||
|
||||
public DateTime Date
|
||||
|
@ -98,6 +100,18 @@ namespace GalaSoft.MvvmLight.Test.ViewModel
|
|||
set;
|
||||
}
|
||||
|
||||
public string TargetPropertyObservable
|
||||
{
|
||||
get
|
||||
{
|
||||
return _targetPropertyObservable;
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(ref _targetPropertyObservable, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand TestCommandImpl
|
||||
{
|
||||
get
|
||||
|
|
|
@ -141,6 +141,18 @@
|
|||
<Compile Include="..\AndroidTestApp\Binding\BindingTest.cs">
|
||||
<Link>Binding\BindingTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingValueChangedFromSourceControlTest.cs">
|
||||
<Link>Binding\BindingValueChangedFromSourceControlTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingValueChangedFromSourceTest.cs">
|
||||
<Link>Binding\BindingValueChangedFromSourceTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingValueChangedFromTargetControlTest.cs">
|
||||
<Link>Binding\BindingValueChangedFromTargetControlTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingValueChangedFromTargetTest.cs">
|
||||
<Link>Binding\BindingValueChangedFromTargetTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\ConverterTest.cs">
|
||||
<Link>Binding\ConverterTest.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -54,7 +54,10 @@ namespace GalaSoft.MvvmLight.Test.ObservableTable
|
|||
[Test]
|
||||
public void ObservableTableViewController_WithListAndSetReuseId()
|
||||
{
|
||||
Vm = GetViewModel();
|
||||
Vm = new TestViewModel
|
||||
{
|
||||
ItemsCollection = new ObservableCollection<TestItem>()
|
||||
};
|
||||
|
||||
const string reuseId = "1234";
|
||||
|
||||
|
@ -65,6 +68,8 @@ namespace GalaSoft.MvvmLight.Test.ObservableTable
|
|||
|
||||
private void BindCell(UITableViewCell cell, TestItem item, NSIndexPath path)
|
||||
{
|
||||
item.RowIndexPath = path;
|
||||
cell.TextLabel.Text = item.Title;
|
||||
}
|
||||
|
||||
private UITableViewCell CreateCell(NSString reuseId)
|
||||
|
@ -78,18 +83,17 @@ namespace GalaSoft.MvvmLight.Test.ObservableTable
|
|||
{
|
||||
ItemsCollection = new ObservableCollection<TestItem>
|
||||
{
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem("123"),
|
||||
new TestItem("234"),
|
||||
new TestItem("345"),
|
||||
new TestItem("456"),
|
||||
},
|
||||
|
||||
ItemsList = new List<TestItem>
|
||||
{
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem(),
|
||||
new TestItem("123"),
|
||||
new TestItem("234"),
|
||||
new TestItem("345"),
|
||||
new TestItem("456"),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче