This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathBindableObjectExtensionTests.cs
72 lines (62 loc) · 2.35 KB
/
BindableObjectExtensionTests.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
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);
}
}
}