summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-07 10:57:43 +0100
committerGitHub <noreply@github.com>2016-12-07 10:57:43 +0100
commit8181e6d4cbe8aac6eb29c5140262d8bc51dba7b7 (patch)
tree5e97231ce476ec38961cb5de9f2ca5ea24569625 /Xamarin.Forms.Xaml.UnitTests
parent1dd4ce922e7d28038605a4476dce207f1440122f (diff)
downloadxamarin-forms-8181e6d4cbe8aac6eb29c5140262d8bc51dba7b7.tar.gz
xamarin-forms-8181e6d4cbe8aac6eb29c5140262d8bc51dba7b7.tar.bz2
xamarin-forms-8181e6d4cbe8aac6eb29c5140262d8bc51dba7b7.zip
[XamlC] Type ref tests, and fixes (#569)
* [XamlC] Add tests for TypeRefExts, fix and enhancements * [XamlC] more fixes, more tests * Fix failing test
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj1
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs112
2 files changed, 113 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 4977edb4..4f56c575 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -396,6 +396,7 @@
<Compile Include="FactoryMethodMissingMethod.xaml.cs">
<DependentUpon>FactoryMethodMissingMethod.xaml</DependentUpon>
</Compile>
+ <Compile Include="XamlC\TypeReferenceExtensionsTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs
new file mode 100644
index 00000000..3b6f293f
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/XamlC/TypeReferenceExtensionsTests.cs
@@ -0,0 +1,112 @@
+´╗┐using System;
+using NUnit.Framework;
+using Mono.Cecil;
+using Xamarin.Forms.Build.Tasks;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms
+{
+ public class Effect
+ {
+ }
+}
+namespace Xamarin.Forms.Xaml.XamlcUnitTests
+{
+ [TestFixture]
+ public class TypeReferenceExtensionsTests
+ {
+ class Foo
+ {
+ }
+
+ class Foo<T> : Foo
+ {
+ }
+
+ class Bar<T> : Foo<T>
+ {
+ }
+
+ ModuleDefinition module;
+
+ [SetUp]
+ public void SetUp()
+ {
+ var resolver = new XamlCAssemblyResolver();
+ resolver.AddAssembly(Uri.UnescapeDataString((new UriBuilder(typeof(TypeReferenceExtensionsTests).Assembly.CodeBase)).Path));
+ resolver.AddAssembly(Uri.UnescapeDataString((new UriBuilder(typeof(BindableObject).Assembly.CodeBase)).Path));
+ resolver.AddAssembly(Uri.UnescapeDataString((new UriBuilder(typeof(object).Assembly.CodeBase)).Path));
+ resolver.AddAssembly(Uri.UnescapeDataString((new UriBuilder(typeof(IList<>).Assembly.CodeBase)).Path));
+ resolver.AddAssembly(Uri.UnescapeDataString((new UriBuilder(typeof(Queue<>).Assembly.CodeBase)).Path));
+
+ module = ModuleDefinition.CreateModule("foo", new ModuleParameters {
+ AssemblyResolver = resolver,
+ Kind = ModuleKind.NetModule
+ });
+ }
+
+ [TestCase(typeof(bool), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(Dictionary<string, string>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(List<string>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(List<Button>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(Queue<KeyValuePair<string, string>>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(double), typeof(double), ExpectedResult = true)]
+ [TestCase(typeof(object), typeof(IList<TriggerBase>), ExpectedResult = false)]
+ [TestCase(typeof(object), typeof(double), ExpectedResult = false)]
+ [TestCase(typeof(object), typeof(int?), ExpectedResult = false)]
+ [TestCase(typeof(object), typeof(object), ExpectedResult = true)]
+ [TestCase(typeof(sbyte), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(string[]), typeof(System.Collections.IEnumerable), ExpectedResult = true)]
+ [TestCase(typeof(string[]), typeof(object), ExpectedResult = true)]
+ [TestCase(typeof(string[]), typeof(string), ExpectedResult = false)]
+ [TestCase(typeof(string[]), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(string[]), typeof(IEnumerable<string>), ExpectedResult = true)]
+ [TestCase(typeof(Type), typeof(object), ExpectedResult = true)]
+ [TestCase(typeof(Type), typeof(Type), ExpectedResult = true)]
+ [TestCase(typeof(Type), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(System.Windows.Input.ICommand), typeof(System.Windows.Input.ICommand), ExpectedResult = true)]
+ [TestCase(typeof(System.Windows.Input.ICommand), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(BindingBase), typeof(BindingBase), ExpectedResult = true)]
+ [TestCase(typeof(BindingCondition), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(Button), typeof(BindableObject), ExpectedResult = true)]
+ [TestCase(typeof(Button), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(Button), typeof(View), ExpectedResult = true)]
+ [TestCase(typeof(Color), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(Color), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(Color), typeof(Color), ExpectedResult = true)]
+ [TestCase(typeof(ColumnDefinition), typeof(BindableObject), ExpectedResult = true)]
+ [TestCase(typeof(ColumnDefinition), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(ColumnDefinition), typeof(ColumnDefinitionCollection), ExpectedResult = false)]
+ [TestCase(typeof(Constraint), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(Constraint), typeof(Constraint), ExpectedResult = true)]
+ [TestCase(typeof(ConstraintExpression), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(ContentPage), typeof(BindableObject), ExpectedResult = true)]
+ [TestCase(typeof(ContentPage), typeof(Page), ExpectedResult = true)]
+ [TestCase(typeof(ContentView), typeof(BindableObject), ExpectedResult = true)]
+ [TestCase(typeof(ContentView[]), typeof(IList<ContentView>), ExpectedResult = true)]
+ [TestCase(typeof(MultiTrigger), typeof(IList<TriggerBase>), ExpectedResult = false)]
+ [TestCase(typeof(OnIdiom<double>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(OnPlatform<string>), typeof(string), ExpectedResult = false)]
+ [TestCase(typeof(OnPlatform<string>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(OnPlatform<string>), typeof(BindingBase), ExpectedResult = false)]
+ [TestCase(typeof(OnPlatform<FontAttributes>), typeof(BindableObject), ExpectedResult = false)]
+ [TestCase(typeof(StackLayout), typeof(Layout<View>), ExpectedResult = true)]
+ [TestCase(typeof(StackLayout), typeof(View), ExpectedResult = true)]
+ [TestCase(typeof(Foo<string>), typeof(Foo), ExpectedResult = true)]
+ [TestCase(typeof(Bar<string>), typeof(Foo), ExpectedResult = true)]
+ [TestCase(typeof(Bar<string>), typeof(Foo<string>), ExpectedResult = true)]
+ public bool TestInheritsFromOrImplements(Type typeRef, Type baseClass)
+ {
+ return TypeReferenceExtensions.InheritsFromOrImplements(module.Import(typeRef), module.Import(baseClass));
+ }
+
+ [Test]
+ public void TestSameTypeNamesFromDifferentAssemblies()
+ {
+ var core = typeof(BindableObject).Assembly;
+ var test = typeof(TypeReferenceExtensionsTests).Assembly;
+
+ Assert.False(TestInheritsFromOrImplements(test.GetType("Xamarin.Forms.Effect"), core.GetType("Xamarin.Forms.Effect")));
+ }
+ }
+} \ No newline at end of file