summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-07-19 01:17:29 +0200
committerJason Smith <jason.smith@xamarin.com>2016-07-18 16:17:29 -0700
commitf304f25df2d80094d2c31fda4986f92454599a7e (patch)
treee9b9a32bea7e5f8c5e07fbcb4cabbaa5abb0c2f8 /Xamarin.Forms.Xaml.UnitTests
parent272033723ea275ceb8a288fa605eafd035c79f2d (diff)
downloadxamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.tar.gz
xamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.tar.bz2
xamarin-forms-f304f25df2d80094d2c31fda4986f92454599a7e.zip
[Xaml] allow the Previewer to provide their own Xaml files for any type (#262)
* [Xaml] allow the Previewer to provide their own Xaml files for any type * [Xaml] use a Func instead of an interface, easier to use by reflection. Add tests * [XamlC] move the InitializeComponent duplication to XamlC task * [XamlC] generate branching code * [XamlC] fix the XamlC issue * [XamlC] make the API public * [docs] fix docs
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs3
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml.cs55
4 files changed, 70 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 417e800a..cd22258c 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -347,6 +347,9 @@
<Compile Include="SharedResourceDictionary2.xaml.cs">
<DependentUpon>SharedResourceDictionary2.xaml</DependentUpon>
</Compile>
+ <Compile Include="XamlLoaderGetXamlForTypeTests.xaml.cs">
+ <DependentUpon>XamlLoaderGetXamlForTypeTests.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -617,6 +620,9 @@
<EmbeddedResource Include="SharedResourceDictionary2.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="XamlLoaderGetXamlForTypeTests.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
index a175b57f..23c72a00 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
@@ -3,6 +3,8 @@ using NUnit.Framework;
namespace Xamarin.Forms.Xaml.UnitTests
{
+#pragma warning disable 0618 //retaining legacy call to obsolete code
+
[TestFixture]
public class XamlLoaderCreateTests
{
@@ -35,4 +37,5 @@ namespace Xamarin.Forms.Xaml.UnitTests
Assert.NotNull (button);
}
}
+#pragma warning restore 0618
} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml
new file mode 100644
index 00000000..ec551771
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml
@@ -0,0 +1,6 @@
+<?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.XamlLoaderGetXamlForTypeTests">
+ <Button x:Name="Button"/>
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml.cs
new file mode 100644
index 00000000..10c3f2e2
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml.cs
@@ -0,0 +1,55 @@
+´╗┐using System;
+using System.Collections.Generic;
+
+using NUnit.Framework;
+
+using Xamarin.Forms;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class XamlLoaderGetXamlForTypeTests : ContentPage
+ {
+ public XamlLoaderGetXamlForTypeTests()
+ {
+ InitializeComponent();
+ }
+
+ public XamlLoaderGetXamlForTypeTests(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider = null;
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void XamlContentIsReplaced(bool useCompiledXaml)
+ {
+ var layout = new XamlLoaderGetXamlForTypeTests(useCompiledXaml);
+ Assert.That(layout.Content, Is.TypeOf<Button>());
+
+ Xamarin.Forms.Xaml.Internals.XamlLoader.XamlFileProvider = (t) => {
+ if (t == typeof(XamlLoaderGetXamlForTypeTests))
+ return @"
+ <ContentPage xmlns=""http://xamarin.com/schemas/2014/forms""
+ xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
+ x:Class=""Xamarin.Forms.Xaml.UnitTests.XamlLoaderGetXamlForTypeTests"">
+ <Label x:Name=""Label""/>
+ </ContentPage>";
+ return null;
+ };
+
+ layout = new XamlLoaderGetXamlForTypeTests(useCompiledXaml);
+ Assert.That(layout.Content, Is.TypeOf<Label>());
+ }
+ }
+ }
+}
+