summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-04 22:08:11 +0100
committerGitHub <noreply@github.com>2016-12-04 22:08:11 +0100
commit39f2deb5e04886374e720013782c751a4bb7675d (patch)
tree64f2df7230760c26533730e73821a6dc5c7607da /Xamarin.Forms.Xaml.UnitTests
parentfb76107f4f3294a9d32c6983bc742ce8dff60cd8 (diff)
downloadxamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.tar.gz
xamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.tar.bz2
xamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.zip
[Xaml] support arrays as x:Arguments (#545)
* [Xaml] port some FactoryMethod tests to XamlC * [Xaml] support array parameters in factory ctors * [XamlC] support arrays as x:Arguments * fix build
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml15
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml.cs35
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml16
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml.cs35
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs53
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml16
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs13
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/SetValue.xaml2
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj13
9 files changed, 141 insertions, 57 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml
new file mode 100644
index 00000000..f49108cf
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<local:MockView xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.FactoryMethodMissingCtor">
+ <local:MockView.Content>
+ <local:MockFactory>
+ <x:Arguments>
+ <x:Object/>
+ <x:String>bar</x:String>
+ <x:Int32>42</x:Int32>
+ </x:Arguments>
+ </local:MockFactory>
+ </local:MockView.Content>
+</local:MockView> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml.cs
new file mode 100644
index 00000000..6771edf6
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingCtor.xaml.cs
@@ -0,0 +1,35 @@
+using System;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ [XamlCompilation(XamlCompilationOptions.Skip)]
+ public partial class FactoryMethodMissingCtor : MockView
+ {
+ public FactoryMethodMissingCtor()
+ {
+ InitializeComponent();
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Throw(bool useCompiledXaml)
+ {
+ if (useCompiledXaml)
+ Assert.Throws(new XamlParseExceptionConstraint(7, 4), () => MockCompiler.Compile(typeof(FactoryMethodMissingCtor)));
+ else
+ Assert.Throws<MissingMethodException>(() => new FactoryMethodMissingCtor());
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml
new file mode 100644
index 00000000..85e279d1
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<local:MockView
+ xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.FactoryMethodMissingMethod">
+ <local:MockView.Content>
+ <local:MockFactory x:FactoryMethod="Factory">
+ <x:Arguments>
+ <x:Object/>
+ <x:String>bar</x:String>
+ <x:Int32>42</x:Int32>
+ </x:Arguments>
+ </local:MockFactory>
+ </local:MockView.Content>
+</local:MockView> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml.cs
new file mode 100644
index 00000000..ecc40487
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodMissingMethod.xaml.cs
@@ -0,0 +1,35 @@
+using System;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ [XamlCompilation(XamlCompilationOptions.Skip)]
+ public partial class FactoryMethodMissingMethod : MockView
+ {
+ public FactoryMethodMissingMethod()
+ {
+ InitializeComponent();
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Throw(bool useCompiledXaml)
+ {
+ if (useCompiledXaml)
+ Assert.Throws(new XamlParseExceptionConstraint(8, 4), () => MockCompiler.Compile(typeof(FactoryMethodMissingMethod)));
+ else
+ Assert.Throws<MissingMemberException>(() => new FactoryMethodMissingMethod());
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs
deleted file mode 100644
index d6ee1886..00000000
--- a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System;
-using NUnit.Framework;
-
-using Xamarin.Forms.Core.UnitTests;
-
-namespace Xamarin.Forms.Xaml.UnitTests
-{
- [TestFixture]
- public class FactoryMethodTests : BaseTestFixture
- {
- [Test]
- public void ThrowOnMissingCtor ()
- {
- var xaml = @"
- <local:MockView
- xmlns=""http://xamarin.com/schemas/2014/forms""
- xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
- xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" >
- <local:MockView.Content>
- <local:MockFactory>
- <x:Arguments>
- <x:Object/>
- <x:String>bar</x:String>
- <x:Int32>42</x:Int32>
- </x:Arguments>
- </local:MockFactory>
- </local:MockView.Content>
- </local:MockView>";
- Assert.Throws<MissingMethodException> (()=>new MockView ().LoadFromXaml (xaml));
- }
-
- [Test]
- public void ThrowOnMissingMethod ()
- {
- var xaml = @"
- <local:MockView
- xmlns=""http://xamarin.com/schemas/2014/forms""
- xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
- xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" >
- <local:MockView.Content>
- <local:MockFactory x:FactoryMethod=""Factory"">
- <x:Arguments>
- <x:Object/>
- <x:String>bar</x:String>
- <x:Int32>42</x:Int32>
- </x:Arguments>
- </local:MockFactory>
- </local:MockView.Content>
- </local:MockView>";
- Assert.Throws<MissingMemberException> (()=>new MockView ().LoadFromXaml (xaml));
- }
- }
-}
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml
index 5225c7d9..9ff91dea 100644
--- a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
@@ -32,7 +32,7 @@
<local:MockView.Content>
<local:MockFactory x:FactoryMethod="ParameterlessFactory">
</local:MockFactory>
- </local:MockView.Content>
+ </local:MockView.Content>
</local:MockView>
<local:MockView x:Name="v4">
<local:MockView.Content>
@@ -68,5 +68,17 @@
<local:MockFactory x:Arguments="{x:Static local:MockxStatic.MockStaticProperty}"/>
</local:MockView.Content>
</local:MockView>
+ <local:MockView x:Name="v8">
+ <local:MockView.Content>
+ <local:MockFactory >
+ <x:Arguments>
+ <x:Array Type="{x:Type x:Object}">
+ <x:String>Foo</x:String>
+ <x:String>Bar</x:String>
+ </x:Array>
+ </x:Arguments>
+ </local:MockFactory>
+ </local:MockView.Content>
+ </local:MockView>
</StackLayout>
</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs
index 9fa4e924..f5790383 100644
--- a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs
@@ -32,6 +32,11 @@ namespace Xamarin.Forms.Xaml.UnitTests
Content = "int ctor " + arg.ToString ();
}
+ public MockFactory(object [] args)
+ {
+ Content = string.Join(" ", args);
+ }
+
public static MockFactory ParameterlessFactory ()
{
return new MockFactory {
@@ -138,6 +143,14 @@ namespace Xamarin.Forms.Xaml.UnitTests
var layout = new FactoryMethods(useCompiledXaml);
Assert.AreEqual("alternate ctor Property", layout.v7.Content.Content);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void TestCtorWithArrayParameter(bool useCompiledXaml)
+ {
+ var layout = new FactoryMethods(useCompiledXaml);
+ Assert.AreEqual("Foo Bar", layout.v8.Content.Content);
+ }
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
index fd11bd5a..5ebc4f4f 100644
--- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 9c2776ec..4977edb4 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -94,7 +94,6 @@
<Compile Include="OnPlatformTests.cs" />
<Compile Include="NullExtensionTests.cs" />
<Compile Include="TypeExtensionTests.cs" />
- <Compile Include="FactoryMethodTests.cs" />
<Compile Include="XamlgTests.cs" />
<Compile Include="Issues\TestCases.cs" />
<Compile Include="Issues\Issue1493.cs" />
@@ -391,6 +390,12 @@
<Compile Include="Issues\Bz47703.xaml.cs">
<DependentUpon>Bz47703.xaml</DependentUpon>
</Compile>
+ <Compile Include="FactoryMethodMissingCtor.xaml.cs">
+ <DependentUpon>FactoryMethodMissingCtor.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="FactoryMethodMissingMethod.xaml.cs">
+ <DependentUpon>FactoryMethodMissingMethod.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -703,6 +708,12 @@
<EmbeddedResource Include="Issues\Bz47703.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="FactoryMethodMissingCtor.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
+ <EmbeddedResource Include="FactoryMethodMissingMethod.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />