summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/BindingTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests/BindingTests.cs')
-rw-r--r--Xamarin.Forms.Core.UnitTests/BindingTests.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/BindingTests.cs b/Xamarin.Forms.Core.UnitTests/BindingTests.cs
new file mode 100644
index 00000000..d586a6dd
--- /dev/null
+++ b/Xamarin.Forms.Core.UnitTests/BindingTests.cs
@@ -0,0 +1,75 @@
+using NUnit.Framework;
+using System.Collections.Generic;
+using System;
+
+namespace Xamarin.Forms.Core.UnitTests
+{
+ [TestFixture]
+ internal class BindingSystemTests : BaseTestFixture
+ {
+ [SetUp]
+ public override void Setup()
+ {
+ base.Setup ();
+ Device.PlatformServices = new MockPlatformServices ();
+ }
+
+ [TearDown]
+ public override void TearDown()
+ {
+ base.TearDown ();
+ Device.PlatformServices = null;
+ }
+
+ class BindableViewCell : ViewCell
+ {
+ public static readonly BindableProperty NameProperty =
+ BindableProperty.Create<BindableViewCell, string> (w => w.Name, "");
+
+ public Label NameLabel { get; set; }
+
+ public string Name
+ {
+ get { return (string) GetValue (NameProperty); }
+ set { SetValue (NameProperty, value); }
+ }
+
+ public BindableViewCell ()
+ {
+ NameLabel = new Label {BindingContext = this};
+ NameLabel.SetBinding (Label.TextProperty, new Binding ("Name"));
+ View = NameLabel;
+ }
+ }
+
+ [Test]
+ public void RecursiveSettingInSystem ()
+ {
+ var tempObjects = new[] {
+ new {Name = "Test1"},
+ new {Name = "Test2"}
+ };
+
+ var template = new DataTemplate (typeof (BindableViewCell)) {
+ Bindings = { {BindableViewCell.NameProperty, new Binding ("Name")} }
+ };
+
+ var cell1 = (Cell)template.CreateContent ();
+ cell1.BindingContext = tempObjects[0];
+ cell1.Parent = new ListView ();
+
+ var cell2 = (Cell)template.CreateContent ();
+ cell2.BindingContext = tempObjects[1];
+ cell2.Parent = new ListView ();
+
+ var viewCell1 = (BindableViewCell) cell1;
+ var viewCell2 = (BindableViewCell) cell2;
+
+ Assert.AreEqual ("Test1", viewCell1.Name);
+ Assert.AreEqual ("Test2", viewCell2.Name);
+
+ Assert.AreEqual ("Test1", viewCell1.NameLabel.Text);
+ Assert.AreEqual ("Test2", viewCell2.NameLabel.Text);
+ }
+ }
+} \ No newline at end of file