summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs')
-rw-r--r--Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs b/Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs
new file mode 100644
index 00000000..b3f0198d
--- /dev/null
+++ b/Xamarin.Forms.Core.UnitTests/BindingExpressionTests.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Core.UnitTests
+{
+ [TestFixture]
+ public class BindingExpressionTests : BaseTestFixture
+ {
+ [Test]
+ public void Ctor()
+ {
+ string path = "Foo.Bar";
+ var binding = new Binding (path);
+
+ var be = new BindingExpression (binding, path);
+
+ Assert.AreSame (binding, be.Binding);
+ Assert.AreEqual (path, be.Path);
+ }
+
+ [Test]
+ public void CtorInvalid()
+ {
+ string path = "Foo.Bar";
+ var binding = new Binding (path);
+
+ Assert.Throws<ArgumentNullException> (() => new BindingExpression (binding, null),
+ "Allowed the path to eb null");
+
+ Assert.Throws<ArgumentNullException> (() => new BindingExpression (null, path),
+ "Allowed the binding to be null");
+ }
+
+ [Test]
+ public void ApplyNull()
+ {
+ const string path = "Foo.Bar";
+ var binding = new Binding (path);
+ var be = new BindingExpression (binding, path);
+ Assert.DoesNotThrow (() => be.Apply (null, new MockBindable(), TextCell.TextProperty));
+ }
+
+ // We only throw on invalid path features, if they give an invalid property
+ // name, it won't have compiled in the first place or they misstyped.
+ [TestCase ("Foo.")]
+ [TestCase ("Foo[]")]
+ [TestCase ("Foo.Bar[]")]
+ [TestCase ("Foo[1")]
+ public void InvalidPaths (string path)
+ {
+ var fex = Assert.Throws<FormatException> (() => {
+ var binding = new Binding (path);
+ new BindingExpression (binding, path);
+ });
+
+ Assert.IsFalse (String.IsNullOrWhiteSpace (fex.Message),
+ "FormatException did not contain an explanation");
+ }
+
+ [Test]
+ public void ValidPaths (
+ [Values (
+ ".", "[1]", "[1 ]", ".[1]", ". [1]",
+ "Foo", "Foo.Bar", "Foo. Bar", "Foo.Bar[1]",
+ "Foo.Bar [1]")]
+ string path,
+ [Values (true, false)] bool spaceBefore,
+ [Values (true, false)] bool spaceAfter)
+ {
+ if (spaceBefore)
+ path = " " + path;
+ if (spaceAfter)
+ path = path + " ";
+
+ var binding = new Binding (path);
+ Assert.DoesNotThrow (() => new BindingExpression (binding, path));
+ }
+ }
+}