-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
BindingTests.cs
75 lines (62 loc) · 1.76 KB
/
BindingTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
}
}
}