diff options
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs')
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs new file mode 100644 index 00000000..3786ccb5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class ConstraintExpression : ContentPage + { + public ConstraintExpression () + { + InitializeComponent (); + } + + public ConstraintExpression (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void ConstantConstraint (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml); + var label = layout.constantConstraint; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (42, constraint.Compute (null)); + } + + [TestCase (false)] + [TestCase (true)] + public void ConstraintRelativeToParent (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml); + layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 200)); + var label = layout.constraintRelativeToParent; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (102, constraint.Compute (layout.relativeLayout)); + } + + [TestCase (false)] + [TestCase (true)] + public void ContraintRelativeToView (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml) { + IsPlatformEnabled = true + }; + layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 100)); + layout.foo.Layout (new Rectangle (5, 5, 190, 25)); + + var label = layout.constraintRelativeToView; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (97, constraint.Compute (layout.relativeLayout)); + } + } + } +}
\ No newline at end of file |