Added unit test for two way binding with conversion.

This commit is contained in:
Laurent Bugnion 2016-02-12 10:29:18 +01:00
Родитель b7495083f3
Коммит 9756cef936
3 изменённых файлов: 46 добавлений и 4 удалений

Просмотреть файл

@ -17,8 +17,8 @@ namespace GalaSoft.MvvmLight.Test.Binding
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class BindingAccountTest
{
private Binding<string, string> _binding1;
private Binding<string, string> _binding2;
private Helpers.Binding _binding1;
private Helpers.Binding _binding2;
public AccountViewModel Vm
{
@ -76,7 +76,7 @@ namespace GalaSoft.MvvmLight.Test.Binding
targetNullValue: "TargetNull");
Assert.AreEqual(AccountViewModel.EmptyText, Operation.Text);
Assert.AreEqual(_binding2.FallbackValue, ChildName.Text);
Assert.AreEqual(((Binding<string, string>)_binding2).FallbackValue, ChildName.Text);
Vm.SetAccount();

Просмотреть файл

@ -19,7 +19,7 @@ namespace GalaSoft.MvvmLight.Test.Binding
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class BindingTest
{
private Binding<string, string> _binding;
private Helpers.Binding _binding;
public TestViewModel VmSource
{
@ -365,5 +365,33 @@ namespace GalaSoft.MvvmLight.Test.Binding
_vmField.Model.MyProperty = "New value";
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
}
[Test]
public void Binding_SetTextBoxToTrueInTwoWayBinding_ShouldRemainLowCaps()
{
VmSource = new TestViewModel
{
Model = new TestModel()
};
VmTarget = new TestViewModel();
_binding = this.SetBinding(
() => VmSource.Model.MyProperty,
() => VmTarget.BoolProperty,
BindingMode.TwoWay);
Assert.AreEqual(null, VmSource.Model.MyProperty);
Assert.IsFalse(VmTarget.BoolProperty);
VmSource.Model.MyProperty = "true";
Assert.AreEqual("true", VmSource.Model.MyProperty);
Assert.IsTrue(VmTarget.BoolProperty);
VmTarget.BoolProperty = false;
Assert.IsFalse(VmTarget.BoolProperty);
Assert.AreEqual("False", VmSource.Model.MyProperty);
}
}
}

Просмотреть файл

@ -10,6 +10,8 @@ namespace GalaSoft.MvvmLight.Test.ViewModel
{
public const string ValueForCommand = "Command value";
private bool _boolProperty;
private DateTime _date;
private TestModel _model;
private TestViewModel _nested;
@ -20,6 +22,18 @@ namespace GalaSoft.MvvmLight.Test.ViewModel
private string _targetPropertyObservable;
private ICommand _testCommandImpl;
public bool BoolProperty
{
get
{
return _boolProperty;
}
set
{
Set(ref _boolProperty, value);
}
}
public DateTime Date
{
get