summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-09-23 08:56:29 +0200
committerJason Smith <jason.smith@xamarin.com>2016-09-22 23:56:29 -0700
commit1076e735697d393c7b10654f8dc7d9a91c7c13e1 (patch)
treed16e5bba69c4c982c3a0f94d00bb509107bf4574 /Xamarin.Forms.Xaml.UnitTests
parent74cb5c4a97dcb123eb471f6b1dffa1267d0305aa (diff)
downloadxamarin-forms-1076e735697d393c7b10654f8dc7d9a91c7c13e1.tar.gz
xamarin-forms-1076e735697d393c7b10654f8dc7d9a91c7c13e1.tar.bz2
xamarin-forms-1076e735697d393c7b10654f8dc7d9a91c7c13e1.zip
[XamlC] supports enum and consts in x:Static (#369)
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs72
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStatic.xaml8
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs56
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml8
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml.cs55
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj7
6 files changed, 125 insertions, 81 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs
deleted file mode 100644
index 86e02fe7..00000000
--- a/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using NUnit.Framework;
-using System.Xml;
-
-using Xamarin.Forms.Core.UnitTests;
-using System.Reflection;
-
-namespace Xamarin.Forms.Xaml.UnitTests
-{
- [TestFixture]
- public class StaticExtensionTests : BaseTestFixture
- {
- IXamlTypeResolver typeResolver;
-
- [SetUp]
- public override void Setup ()
- {
- base.Setup ();
- var nsManager = new XmlNamespaceManager (new NameTable ());
- nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests");
- nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2006/xaml");
-
- typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ());
- }
-
- [Test]
- public void TestxStatic ()
- {
- //{x:Static Member=prefix:typeName.staticMemberName}
- //{x:Static prefix:typeName.staticMemberName}
-
- //The code entity that is referenced must be one of the following:
- // - A constant
- // - A static property
- // - A field
- // - An enumeration value
- // All other cases should throw
-
- var serviceProvider = new Internals.XamlServiceProvider (null, null) {
- IXamlTypeResolver = typeResolver,
- };
-
- //Static property
- var markupString = @"{x:Static Member=""local:MockxStatic.MockStaticProperty""}";
- Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //constant
- markupString = @"{x:Static Member=""local:MockxStatic.MockConstant""}";
- Assert.AreEqual ("Constant", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //field
- markupString = @"{x:Static Member=""local:MockxStatic.MockField""}";
- Assert.AreEqual ("Field", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //enum
- markupString = @"{x:Static Member=""local:MockEnum.Second""}";
- Assert.AreEqual (MockEnum.Second, (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //throw on InstanceProperty
- markupString = @"{x:Static Member=""local:MockxStatic.InstanceProperty""}";
- Assert.Throws<XamlParseException> (()=> (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //quotes are optional
- markupString = @"{x:Static Member=local:MockxStatic.MockStaticProperty}";
- Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
-
- //Member is optional
- markupString = @"{x:Static local:MockxStatic.MockStaticProperty}";
- Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider));
- }
- }
-} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
index 7c2910cd..32d2945e 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.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"
@@ -10,5 +10,11 @@
Text="{x:Static local:MockxStatic.MockStaticProperty}" />
<Label x:Name="color"
TextColor="{x:Static local:MockxStatic.BackgroundColor}" />
+ <Label x:Name="constant"
+ Text="{x:Static local:MockxStatic.MockConstant}"/>
+ <Label x:Name="field"
+ Text="{x:Static local:MockxStatic.MockField}"/>
+ <ScrollView x:Name="enuM"
+ Orientation="{x:Static ScrollOrientation.Both}"/>
</StackLayout>
</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
index ff1f0199..d8a466e9 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
@@ -1,9 +1,5 @@
-using System;
-using System.Collections.Generic;
-
-using Xamarin.Forms;
-
-using NUnit.Framework;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -16,7 +12,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
public static readonly Color BackgroundColor = Color.Fuchsia;
}
- public enum MockEnum
+ public enum MockEnum : long
{
First,
Second,
@@ -37,6 +33,28 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestFixture]
public class Tests
{
+ //{x:Static Member=prefix:typeName.staticMemberName}
+ //{x:Static prefix:typeName.staticMemberName}
+
+ //The code entity that is referenced must be one of the following:
+ // - A constant
+ // - A static property
+ // - A field
+ // - An enumeration value
+ // All other cases should throw
+
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
[TestCase (false)]
[TestCase (true)]
public void StaticProperty (bool useCompiledXaml)
@@ -60,6 +78,30 @@ namespace Xamarin.Forms.Xaml.UnitTests
var layout = new XStatic (useCompiledXaml);
Assert.AreEqual (Color.Fuchsia, layout.color.TextColor);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Constant(bool useCompiledXaml)
+ {
+ var layout = new XStatic(useCompiledXaml);
+ Assert.AreEqual("Constant", layout.constant.Text);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Field(bool useCompiledXaml)
+ {
+ var layout = new XStatic(useCompiledXaml);
+ Assert.AreEqual("Field", layout.field.Text);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Enum(bool useCompiledXaml)
+ {
+ var layout = new XStatic(useCompiledXaml);
+ Assert.AreEqual(ScrollOrientation.Both, layout.enuM.Orientation);
+ }
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml b/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml
new file mode 100644
index 00000000..58d3cb10
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml
@@ -0,0 +1,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"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.XStaticException">
+ <Label x:Name="shouldThrow"
+ Text="{x:Static Member=local:MockxStatic.InstanceProperty}" />
+</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml.cs
new file mode 100644
index 00000000..261de06a
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/XStaticException.xaml.cs
@@ -0,0 +1,55 @@
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ [XamlCompilation(XamlCompilationOptions.Skip)]
+ public partial class XStaticException : ContentPage
+ {
+ public XStaticException()
+ {
+ InitializeComponent();
+ }
+
+ public XStaticException(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ //{x:Static Member=prefix:typeName.staticMemberName}
+ //{x:Static prefix:typeName.staticMemberName}
+
+ //The code entity that is referenced must be one of the following:
+ // - A constant
+ // - A static property
+ // - A field
+ // - An enumeration value
+ // All other cases should throw
+
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void ThrowOnInstanceProperty(bool useCompiledXaml)
+ {
+ if (!useCompiledXaml)
+ Assert.Throws(new XamlParseExceptionConstraint(7, 6), () => new XStaticException(useCompiledXaml));
+ else
+ Assert.Throws(new XamlParseExceptionConstraint(7, 6), () => MockCompiler.Compile(typeof(XStaticException)));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 16f54e88..b2f5e0ac 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -96,7 +96,6 @@
<Compile Include="MarkupExtensionTests.cs" />
<Compile Include="NameScopeTests.cs" />
<Compile Include="OnPlatformTests.cs" />
- <Compile Include="StaticExtensionTests.cs" />
<Compile Include="NullExtensionTests.cs" />
<Compile Include="TypeExtensionTests.cs" />
<Compile Include="FactoryMethodTests.cs" />
@@ -366,6 +365,9 @@
<DependentUpon>NativeViewsAndBindings.xaml</DependentUpon>
</Compile>
<Compile Include="MockCompiler.cs" />
+ <Compile Include="XStaticException.xaml.cs">
+ <DependentUpon>XStaticException.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -648,6 +650,9 @@
<EmbeddedResource Include="NativeViewsAndBindings.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="XStaticException.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />