summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs')
-rw-r--r--Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs b/Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs
new file mode 100644
index 00000000..06a24c7f
--- /dev/null
+++ b/Xamarin.Forms.Core.UnitTests/BindableObjectExtensionTests.cs
@@ -0,0 +1,72 @@
+´╗┐using System;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Core.UnitTests
+{
+ [TestFixture]
+ public class BindableObjectExtensionTests : BaseTestFixture
+ {
+ [Test]
+ public void SetBindingNull()
+ {
+ Assert.That (() => BindableObjectExtensions.SetBinding (null, MockBindable.TextProperty, "Name"),
+ Throws.InstanceOf<ArgumentNullException>());
+ Assert.That (() => BindableObjectExtensions.SetBinding (new MockBindable(), null, "Name"),
+ Throws.InstanceOf<ArgumentNullException>());
+ Assert.That (() => BindableObjectExtensions.SetBinding (new MockBindable(), MockBindable.TextProperty, null),
+ Throws.InstanceOf<ArgumentNullException>());
+
+ Assert.That (() => BindableObjectExtensions.SetBinding<MockViewModel> (null, MockBindable.TextProperty, vm => vm.Text),
+ Throws.InstanceOf<ArgumentNullException>());
+ Assert.That (() => BindableObjectExtensions.SetBinding<MockViewModel> (new MockBindable(), null, vm => vm.Text),
+ Throws.InstanceOf<ArgumentNullException>());
+ Assert.That (() => BindableObjectExtensions.SetBinding<MockViewModel> (new MockBindable(), MockBindable.TextProperty, null),
+ Throws.InstanceOf<ArgumentNullException>());
+ }
+
+ [Test]
+ public void Issue2643()
+ {
+ Label labelTempoDiStampa = new Label();
+ labelTempoDiStampa.BindingContext = new { Name = "1", Company = "Xamarin" };
+ labelTempoDiStampa.SetBinding (Label.TextProperty, "Name", stringFormat: "Hi: {0}");
+
+ Assert.That (labelTempoDiStampa.Text, Is.EqualTo ("Hi: 1"));
+ }
+
+ class Bz27229ViewModel
+ {
+ public object Member { get; private set; }
+ public Bz27229ViewModel ()
+ {
+ Member = new Generic<Label> (new Label {Text="foo"});
+ }
+ }
+
+ class Generic<TResult>
+ {
+ public Generic (TResult result)
+ {
+ Result = result;
+ }
+
+ public TResult Result { get; set; }
+ }
+
+ [Test]
+ public void Bz27229 ()
+ {
+ var totalCheckTime = new TextCell { Text = "Total Check Time" };
+ totalCheckTime.BindingContext = new Bz27229ViewModel ();
+ totalCheckTime.SetBinding(TextCell.DetailProperty,"Member.Result.Text");
+ Assert.AreEqual ("foo", totalCheckTime.Detail);
+
+ totalCheckTime = new TextCell { Text = "Total Check Time" };
+ totalCheckTime.BindingContext = new Bz27229ViewModel ();
+ totalCheckTime.SetBinding<Bz27229ViewModel>(TextCell.DetailProperty, vm =>
+ ((Generic<Label>)vm.Member).Result.Text);
+
+ Assert.AreEqual ("foo", totalCheckTime.Detail);
+ }
+ }
+}