This commit is contained in:
Laurent Bugnion 2016-04-20 23:48:54 +02:00
Родитель c4eb36471e
Коммит 7f3e72a593
3 изменённых файлов: 89 добавлений и 3 удалений

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

@ -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>