Adding unit tests for Binding in Android and iOS
This commit is contained in:
Родитель
af6d43a785
Коммит
8c303b19ab
|
@ -0,0 +1,120 @@
|
|||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
#elif __IOS__
|
||||
using UIKit;
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
public class BindingAccountTest
|
||||
{
|
||||
private Binding<string, string> _binding1;
|
||||
private Binding<string, string> _binding2;
|
||||
|
||||
public AccountViewModel Vm
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
#if ANDROID
|
||||
public EditText Operation
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public EditText ChildName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#elif __IOS__
|
||||
public UITextView Operation
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public UITextView ChildName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void Binding_Test1_Error()
|
||||
{
|
||||
Vm = new AccountViewModel();
|
||||
|
||||
#if ANDROID
|
||||
Operation = new EditText(Application.Context);
|
||||
ChildName = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Operation = new UITextView();
|
||||
ChildName = new UITextView();
|
||||
#endif
|
||||
|
||||
_binding1 = this.SetBinding(
|
||||
() => Vm.FormattedOperation,
|
||||
() => Operation.Text);
|
||||
|
||||
_binding2 = this.SetBinding(
|
||||
() => Vm.AccountDetails.Name,
|
||||
() => ChildName.Text,
|
||||
fallbackValue: "Fallback",
|
||||
targetNullValue: "TargetNull");
|
||||
|
||||
Assert.AreEqual(AccountViewModel.EmptyText, Operation.Text);
|
||||
Assert.AreEqual(_binding2.FallbackValue, ChildName.Text);
|
||||
|
||||
Vm.SetAccount();
|
||||
|
||||
Assert.AreEqual(
|
||||
AccountViewModel.NotEmptyText + Vm.AccountDetails.Balance + Vm.Amount,
|
||||
Operation.Text);
|
||||
Assert.AreEqual(Vm.AccountDetails.Name, ChildName.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Binding_Test2_Works()
|
||||
{
|
||||
Vm = new AccountViewModel();
|
||||
|
||||
#if ANDROID
|
||||
Operation = new EditText(Application.Context);
|
||||
ChildName = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Operation = new UITextView();
|
||||
ChildName = new UITextView();
|
||||
#endif
|
||||
|
||||
_binding1 = this.SetBinding(
|
||||
() => Vm.FormattedOperation,
|
||||
() => Operation.Text);
|
||||
|
||||
_binding2 = this.SetBinding(
|
||||
() => Vm.AccountDetailsName,
|
||||
() => ChildName.Text,
|
||||
fallbackValue: "Fallback",
|
||||
targetNullValue: "TargetNull");
|
||||
|
||||
Assert.AreEqual(AccountViewModel.EmptyText, Operation.Text);
|
||||
Assert.AreEqual(AccountViewModel.EmptyText, ChildName.Text);
|
||||
|
||||
Vm.SetAccount();
|
||||
|
||||
Assert.AreEqual(
|
||||
AccountViewModel.NotEmptyText + Vm.AccountDetails.Balance + Vm.Amount,
|
||||
Operation.Text);
|
||||
Assert.AreEqual(Vm.AccountDetails.Name, ChildName.Text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingDeepPathTest
|
||||
{
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepSourceSetPath_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Nested.Nested.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Nested.Nested.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Nested.Nested.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Nested.Nested.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepSourceExistingPathGraduallySettingPath_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel();
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
const string fallback = "This is the fallback";
|
||||
const string targetNull = "Target is null";
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Nested.Nested.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty,
|
||||
fallbackValue: fallback,
|
||||
targetNullValue: targetNull);
|
||||
|
||||
Assert.AreEqual(fallback, VmTarget.TargetProperty);
|
||||
VmSource.Nested = new TestViewModel();
|
||||
Assert.AreEqual(fallback, VmTarget.TargetProperty);
|
||||
VmSource.Nested.Nested = new TestViewModel();
|
||||
Assert.AreEqual(fallback, VmTarget.TargetProperty);
|
||||
VmSource.Nested.Nested.Model = new TestModel();
|
||||
Assert.AreEqual(targetNull, VmTarget.TargetProperty);
|
||||
var initialValue = "Initial value";
|
||||
VmSource.Nested.Nested.Model.MyProperty = initialValue;
|
||||
Assert.AreEqual(initialValue, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Nested.Nested.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepSourceExistingPathChangingObjects_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Nested.Nested.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Nested.Nested.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Nested.Nested.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Nested.Nested.Model.MyProperty, VmTarget.TargetProperty);
|
||||
|
||||
const string value2 = "Value 2";
|
||||
|
||||
VmSource.Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = value2
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Assert.AreEqual(value2, VmTarget.TargetProperty);
|
||||
|
||||
const string value3 = "Value 3";
|
||||
|
||||
VmSource.Nested.Nested = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = value3
|
||||
}
|
||||
};
|
||||
|
||||
Assert.AreEqual(value3, VmTarget.TargetProperty);
|
||||
|
||||
const string value4 = "Value 4";
|
||||
|
||||
VmSource.Nested.Nested.Model = new TestModel
|
||||
{
|
||||
MyProperty = value4
|
||||
};
|
||||
|
||||
Assert.AreEqual(value4, VmTarget.TargetProperty);
|
||||
|
||||
const string value5 = "Value 5";
|
||||
|
||||
VmSource.Nested.Nested.Model.MyProperty = value5;
|
||||
|
||||
Assert.AreEqual(value5, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepTargetSetPath_NoError()
|
||||
{
|
||||
VmTarget = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepTargetExistingPathGraduallySettingPath_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
VmTarget.Nested = new TestViewModel();
|
||||
VmTarget.Nested.Nested = new TestViewModel();
|
||||
VmTarget.Nested.Nested.Nested = new TestViewModel();
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingDeepPath_DeepTargetExistingPathChangingObjects_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
VmTarget.Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel()
|
||||
}
|
||||
};
|
||||
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
VmTarget.Nested.Nested = new TestViewModel
|
||||
{
|
||||
Nested = new TestViewModel()
|
||||
};
|
||||
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
|
||||
VmTarget.Nested.Nested.Nested = new TestViewModel();
|
||||
|
||||
Assert.AreEqual(newValue, VmTarget.Nested.Nested.Nested.TargetProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.Controls;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
#elif __IOS__
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingSourceControlTest
|
||||
{
|
||||
#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 BindingSourceControl_NewBindingWithPublicProperty_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
Source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
Source,
|
||||
() => Source.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
Source.Text = newValue;
|
||||
Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_NewBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
SourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
SourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
SourcePrivate,
|
||||
() => SourcePrivate.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
|
||||
var newValue2 = DateTime.Now.Ticks.ToString();
|
||||
SourcePrivate.Text = newValue2;
|
||||
Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_NewBindingWithPublicField_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
_source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
_source,
|
||||
() => _source.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_source.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_source.Text = newValue;
|
||||
Assert.AreEqual(_source.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_NewBindingWithPrivateField_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
_sourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_sourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
_sourcePrivate,
|
||||
() => _sourcePrivate.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_sourcePrivate.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_sourcePrivate.Text = newValue;
|
||||
Assert.AreEqual(_sourcePrivate.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_NewBindingWithVar_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
var source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
var source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
source,
|
||||
() => source.Text,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(source.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
source.Text = newValue;
|
||||
Assert.AreEqual(source.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_SetBindingWithPublicProperty_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
Source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => Source.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
Source.Text = newValue;
|
||||
Assert.AreEqual(Source.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_SetBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
SourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
SourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => SourcePrivate.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
|
||||
var newValue2 = DateTime.Now.Ticks.ToString();
|
||||
SourcePrivate.Text = newValue2;
|
||||
Assert.AreEqual(SourcePrivate.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_SetBindingWithPublicField_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
_source = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_source = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => _source.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_source.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_source.Text = newValue;
|
||||
Assert.AreEqual(_source.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSourceControl_SetBindingWithPrivateField_NoError()
|
||||
{
|
||||
#if ANDROID
|
||||
_sourcePrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_sourcePrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => _sourcePrivate.Text,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_sourcePrivate.Text, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_sourcePrivate.Text = newValue;
|
||||
Assert.AreEqual(_sourcePrivate.Text, VmTarget.TargetProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,276 @@
|
|||
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 BindingSourceTest
|
||||
{
|
||||
public TestViewModel _vmSource;
|
||||
private TestViewModel _vmSourcePrivate;
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private TestViewModel VmSourcePrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_NewBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_NewBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
// For comparison only
|
||||
|
||||
var vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var vmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
vmSource,
|
||||
() => vmSource.Model.MyProperty,
|
||||
vmTarget,
|
||||
() => vmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
var newValue1 = DateTime.Now.Ticks.ToString();
|
||||
vmSource.Model.MyProperty = newValue1;
|
||||
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
|
||||
// Actual test
|
||||
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
binding = new Helpers.Binding<string, string>(
|
||||
VmSourcePrivate,
|
||||
() => VmSourcePrivate.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue2 = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue2;
|
||||
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_NewBindingWithPublicField_NoError()
|
||||
{
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
_vmSource,
|
||||
() => _vmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(_vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_NewBindingWithPrivateField_NoError()
|
||||
{
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
_vmSourcePrivate,
|
||||
() => _vmSourcePrivate.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_vmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(_vmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_NewBindingWithVar_NoError()
|
||||
{
|
||||
var vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
vmSource,
|
||||
() => vmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
vmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_SetBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_SetBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
VmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSourcePrivate.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue2 = DateTime.Now.Ticks.ToString();
|
||||
VmSourcePrivate.Model.MyProperty = newValue2;
|
||||
Assert.AreEqual(VmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_SetBindingWithPublicField_NoError()
|
||||
{
|
||||
_vmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => _vmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(_vmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingSource_SetBindingWithPrivateField_NoError()
|
||||
{
|
||||
_vmSourcePrivate = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => _vmSourcePrivate.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(_vmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
_vmSourcePrivate.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(_vmSourcePrivate.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,311 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.Controls;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
#elif __IOS__
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingTargetControlTest
|
||||
{
|
||||
#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_NewBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
Target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
Target,
|
||||
() => Target.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, Target.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, Target.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
TargetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
TargetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
TargetPrivate,
|
||||
() => TargetPrivate.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPublicField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_target,
|
||||
() => _target.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _target.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _target.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithPrivateField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_targetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_targetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_targetPrivate,
|
||||
() => _targetPrivate.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _targetPrivate.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _targetPrivate.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_NewBindingWithVar_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
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
target,
|
||||
() => target.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, target.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, target.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
Target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
Target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => Target.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, Target.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, Target.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
TargetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
TargetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => TargetPrivate.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, TargetPrivate.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPublicField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_target = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_target = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _target.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _target.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _target.Text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTargetControl_SetBindingWithPrivateField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
_targetPrivate = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
_targetPrivate = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _targetPrivate.Text);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _targetPrivate.Text);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _targetPrivate.Text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
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 BindingTargetTest
|
||||
{
|
||||
public TestViewModel _vmTarget;
|
||||
private TestViewModel _vmTargetPrivate;
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private TestViewModel VmTargetPrivate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTarget,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
VmTargetPrivate,
|
||||
() => VmTargetPrivate.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPublicField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTarget,
|
||||
() => _vmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithPrivateField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
_vmTargetPrivate,
|
||||
() => _vmTargetPrivate.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_NewBindingWithVar_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
var vmTarget = new TestViewModel();
|
||||
|
||||
var binding = new Helpers.Binding<string, string>(
|
||||
VmSource,
|
||||
() => VmSource.Model.MyProperty,
|
||||
vmTarget,
|
||||
() => vmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateProperty_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTargetPrivate = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTargetPrivate.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTargetPrivate.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPublicField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTarget = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BindingTarget_SetBindingWithPrivateField_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
_vmTargetPrivate = new TestViewModel();
|
||||
|
||||
var binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => _vmTargetPrivate.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
var newValue = DateTime.Now.Ticks.ToString();
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, _vmTargetPrivate.TargetProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,17 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.Controls;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
#if ANDROID
|
||||
using Android.App;
|
||||
using Android.Widget;
|
||||
#elif __IOS__
|
||||
using UIKit;
|
||||
#endif
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
|
@ -89,10 +97,7 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void
|
||||
Binding_MultipleLevelsOfNullWithConverter_ShouldCallConverterWithNullThenTargetNullValueButNotFallbackValue(
|
||||
|
||||
)
|
||||
public void Binding_MultipleLevelsOfNullWithConverter_ShouldCallConverterWithNullThenTargetNullValueButNotFallbackValue()
|
||||
{
|
||||
var vmSource = new TestViewModel();
|
||||
var vmTarget = new TestViewModel();
|
||||
|
@ -257,5 +262,104 @@ namespace GalaSoft.MvvmLight.Test.Binding
|
|||
|
||||
Assert.AreEqual(vmSource.Model.MyProperty, vmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
private TestViewModel _vmField;
|
||||
|
||||
#if ANDROID
|
||||
public EditText TextBox
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#elif __IOS__
|
||||
public UITextView TextBox
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void Binding_SetBindingWithPrivateField_ShouldCreateBinding()
|
||||
{
|
||||
// Just for comparison
|
||||
var vm = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value for local var"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
var textBox = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
var textBox = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
vm,
|
||||
() => vm.Model.MyProperty,
|
||||
textBox,
|
||||
() => textBox.Text);
|
||||
|
||||
Assert.IsNotNull(_binding);
|
||||
Assert.AreEqual(textBox.Text, vm.Model.MyProperty);
|
||||
vm.Model.MyProperty = "New value";
|
||||
Assert.AreEqual(textBox.Text, vm.Model.MyProperty);
|
||||
|
||||
_vmField = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value for field"
|
||||
}
|
||||
};
|
||||
|
||||
_binding = new Binding<string, string>(
|
||||
_vmField,
|
||||
() => _vmField.Model.MyProperty,
|
||||
textBox,
|
||||
() => textBox.Text);
|
||||
|
||||
Assert.IsNotNull(_binding);
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
_vmField.Model.MyProperty = "New value";
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value for public property"
|
||||
}
|
||||
};
|
||||
|
||||
#if ANDROID
|
||||
TextBox = new EditText(Application.Context);
|
||||
#elif __IOS__
|
||||
TextBox = new UITextViewEx();
|
||||
#endif
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => TextBox.Text);
|
||||
|
||||
Assert.IsNotNull(_binding);
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
_vmField.Model.MyProperty = "New value";
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
|
||||
_vmField.Model.MyProperty = "Initial value for field again";
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => _vmField.Model.MyProperty,
|
||||
() => TextBox.Text);
|
||||
|
||||
Assert.IsNotNull(_binding);
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
_vmField.Model.MyProperty = "New value";
|
||||
Assert.AreEqual(textBox.Text, _vmField.Model.MyProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,6 +85,7 @@
|
|||
<Compile Include="..\..\GalaSoft.MvvmLight.Platform %28Android%29\Helpers\UpdateSourceTriggerMode.cs">
|
||||
<Link>Helpers\UpdateSourceTriggerMode.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Binding\BindingAccountTest.cs" />
|
||||
<Compile Include="Binding\BindingDeepPathTest.cs" />
|
||||
<Compile Include="Binding\BindingSourceControlTest.cs" />
|
||||
<Compile Include="Binding\BindingTargetControlTest.cs" />
|
||||
|
@ -108,6 +109,8 @@
|
|||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModel\AccountModel.cs" />
|
||||
<Compile Include="ViewModel\AccountViewModel.cs" />
|
||||
<Compile Include="ViewModel\CommandImpl.cs" />
|
||||
<Compile Include="ViewModel\TestModel.cs" />
|
||||
<Compile Include="ViewModel\TestViewModel.cs" />
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.ViewModel
|
||||
{
|
||||
public class AccountModel : ObservableObject
|
||||
{
|
||||
private string _name = "Account name";
|
||||
|
||||
public decimal Balance
|
||||
{
|
||||
get
|
||||
{
|
||||
return 26;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(ref _name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.ViewModel
|
||||
{
|
||||
public class AccountViewModel : ViewModelBase
|
||||
{
|
||||
public const string EmptyText = "Empty";
|
||||
public const string NotEmptyText = "Not empty ";
|
||||
|
||||
private AccountModel _accountDetails;
|
||||
private decimal _amount;
|
||||
|
||||
public AccountModel AccountDetails
|
||||
{
|
||||
get
|
||||
{
|
||||
return _accountDetails;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Set(() => AccountDetails, ref _accountDetails, value))
|
||||
{
|
||||
RaisePropertyChanged(() => FormattedOperation);
|
||||
RaisePropertyChanged(() => AccountDetailsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string AccountDetailsName
|
||||
{
|
||||
get
|
||||
{
|
||||
return AccountDetails == null ? EmptyText : AccountDetails.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public decimal Amount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _amount;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Set(() => Amount, ref _amount, value))
|
||||
{
|
||||
RaisePropertyChanged(() => FormattedOperation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FormattedOperation
|
||||
{
|
||||
get
|
||||
{
|
||||
return AccountDetails == null
|
||||
? EmptyText
|
||||
: NotEmptyText + AccountDetails.Balance + Amount;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAccount()
|
||||
{
|
||||
if (AccountDetails == null)
|
||||
{
|
||||
AccountDetails = new AccountModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
AccountDetails.Name += "A";
|
||||
}
|
||||
|
||||
RaisePropertyChanged(() => AccountDetailsName);
|
||||
}
|
||||
|
||||
public void SetAmount()
|
||||
{
|
||||
Amount += 10;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -120,6 +120,9 @@
|
|||
<Compile Include="..\..\GalaSoft.MvvmLight.Platform %28iOS%29\Helpers\ObservableTableViewController.cs">
|
||||
<Link>Helpers\ObservableTableViewController.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingAccountTest.cs">
|
||||
<Link>Binding\BindingAccountTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\Binding\BindingDeepPathTest.cs">
|
||||
<Link>Binding\BindingDeepPathTest.cs</Link>
|
||||
</Compile>
|
||||
|
@ -138,6 +141,12 @@
|
|||
<Compile Include="..\AndroidTestApp\Binding\BindingTest.cs">
|
||||
<Link>Binding\BindingTest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\ViewModel\AccountModel.cs">
|
||||
<Link>ViewModel\AccountModel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\ViewModel\AccountViewModel.cs">
|
||||
<Link>ViewModel\AccountViewModel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\AndroidTestApp\ViewModel\CommandImpl.cs">
|
||||
<Link>ViewModel\CommandImpl.cs</Link>
|
||||
</Compile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче