Added BindingThreadingTest
This commit is contained in:
Родитель
c4eb36471e
Коммит
7f3e72a593
|
@ -0,0 +1,85 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight.Helpers;
|
||||
using GalaSoft.MvvmLight.Test.ViewModel;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GalaSoft.MvvmLight.Test.Binding
|
||||
{
|
||||
[TestFixture]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public class BindingThreadingTest
|
||||
{
|
||||
private Binding<string, string> _binding;
|
||||
|
||||
public TestViewModel VmSource
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public TestViewModel VmTarget
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async void Binding_ExecuteFromBackgroundThread_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
|
||||
const string newValue = "New value";
|
||||
|
||||
await Task.Run(
|
||||
() =>
|
||||
{
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
});
|
||||
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Binding_ExecuteFromSameThread_NoError()
|
||||
{
|
||||
VmSource = new TestViewModel
|
||||
{
|
||||
Model = new TestModel
|
||||
{
|
||||
MyProperty = "Initial value"
|
||||
}
|
||||
};
|
||||
|
||||
VmTarget = new TestViewModel();
|
||||
|
||||
_binding = this.SetBinding(
|
||||
() => VmSource.Model.MyProperty,
|
||||
() => VmTarget.TargetProperty);
|
||||
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
|
||||
const string newValue = "New value";
|
||||
|
||||
VmSource.Model.MyProperty = newValue;
|
||||
|
||||
Assert.AreEqual(newValue, VmSource.Model.MyProperty);
|
||||
Assert.AreEqual(VmSource.Model.MyProperty, VmTarget.TargetProperty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -87,6 +87,7 @@
|
|||
</Compile>
|
||||
<Compile Include="Binding\BindingAccountTest.cs" />
|
||||
<Compile Include="Binding\BindingDeepPathTest.cs" />
|
||||
<Compile Include="Binding\BindingThreadingTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromTargetControlTest.cs" />
|
||||
<Compile Include="Binding\BindingValueChangedFromTargetTest.cs" />
|
||||
<Compile Include="Binding\BindingTargetTest.cs" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>MVVM UNIT</string>
|
||||
|
|
Загрузка…
Ссылка в новой задаче