summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-26 22:29:47 +0200
committerJason Smith <jason.smith@xamarin.com>2016-09-26 13:29:47 -0700
commit55f066584c507ec92d5054fac4f3a35f54c05522 (patch)
tree358ec7ed9a74e008b3bc601a9b391bcd193fb86b /Xamarin.Forms.Xaml.UnitTests
parente6a20ddedb6c8dee989b4ac19c6e83cecafe9f29 (diff)
downloadxamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.tar.gz
xamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.tar.bz2
xamarin-forms-55f066584c507ec92d5054fac4f3a35f54c05522.zip
[XamlC] Compiled converters (#358)
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml9
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml.cs45
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
4 files changed, 65 insertions, 1 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml b/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml
new file mode 100644
index 00000000..56d7e082
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.CompiledTypeConverter"
+ RectangleP="0,1,2,4"
+ RectangleBP="4,8,16,32"
+ BackgroundColor="Pink">
+ <Label HorizontalOptions="EndAndExpand" />
+</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml.cs
new file mode 100644
index 00000000..092d67de
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/CompiledTypeConverter.xaml.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+
+using Xamarin.Forms;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class CompiledTypeConverter : ContentPage
+ {
+ public static readonly BindableProperty RectangleBPProperty =
+ BindableProperty.Create ("RectangleBP", typeof(Rectangle), typeof(CompiledTypeConverter), default(Rectangle));
+
+ public Rectangle RectangleBP {
+ get { return (Rectangle)GetValue (RectangleBPProperty); }
+ set { SetValue (RectangleBPProperty, value); }
+ }
+
+ public Rectangle RectangleP { get; set; }
+
+ public CompiledTypeConverter ()
+ {
+ InitializeComponent ();
+ }
+
+ public CompiledTypeConverter (bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [TestCase (false)]
+ [TestCase (true)]
+ public void CompiledTypeConverterAreInvoked (bool useCompiledXaml)
+ {
+ var p = new CompiledTypeConverter (useCompiledXaml);
+ Assert.AreEqual (new Rectangle (0, 1, 2, 4), p.RectangleP);
+ Assert.AreEqual (new Rectangle (4, 8, 16, 32), p.RectangleBP);
+ Assert.AreEqual (Color.Pink, p.BackgroundColor);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs
index f39e5dd3..cf1b0294 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs
@@ -8,6 +8,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
public string NonBindable { get; set; }
}
+ [XamlCompilation(XamlCompilationOptions.Skip)]
public partial class SetterOnNonBP : ContentPage
{
public SetterOnNonBP ()
@@ -27,7 +28,10 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestCase (true)]
public void ShouldThrow (bool useCompiledXaml)
{
- Assert.Throws (new XamlParseExceptionConstraint (10, 13), () => new SetterOnNonBP (useCompiledXaml));
+ if (!useCompiledXaml)
+ Assert.Throws(new XamlParseExceptionConstraint(10, 13), () => new SetterOnNonBP(useCompiledXaml));
+ else
+ Assert.Throws(new XamlParseExceptionConstraint(10, 13), () => MockCompiler.Compile(typeof(SetterOnNonBP)));
}
}
}
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index b2f5e0ac..dc7f7ea1 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -368,6 +368,9 @@
<Compile Include="XStaticException.xaml.cs">
<DependentUpon>XStaticException.xaml</DependentUpon>
</Compile>
+ <Compile Include="CompiledTypeConverter.xaml.cs" >
+ <DependentUpon>CompiledTypeConverter.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -653,6 +656,9 @@
<EmbeddedResource Include="XStaticException.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="CompiledTypeConverter.xaml" >
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />