This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathTypeExtensionTests.cs
55 lines (47 loc) · 1.64 KB
/
TypeExtensionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Reflection;
using System.Xml;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[TestFixture]
public class TypeExtensionTests : BaseTestFixture
{
IXamlTypeResolver typeResolver;
Internals.XamlServiceProvider serviceProvider;
[SetUp]
public override void Setup()
{
base.Setup();
var nsManager = new XmlNamespaceManager(new NameTable());
nsManager.AddNamespace("", "http://xamarin.com/schemas/2014/forms");
nsManager.AddNamespace("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests");
nsManager.AddNamespace("sys", "clr-namespace:System;assembly=mscorlib");
nsManager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
typeResolver = new Internals.XamlTypeResolver(nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly());
serviceProvider = new Internals.XamlServiceProvider(null, null)
{
IXamlTypeResolver = typeResolver,
};
}
[Test]
public void TestxType()
{
var markupString = @"{x:Type sys:String}";
Assert.AreEqual(typeof(string), (new MarkupExtensionParser()).ParseExpression(ref markupString, serviceProvider));
}
[Test]
public void TestWithoutPrefix()
{
var markupString = @"{x:Type Grid}";
Assert.AreEqual(typeof(Grid), (new MarkupExtensionParser()).ParseExpression(ref markupString, serviceProvider));
}
[Test]
public void TestWithExplicitTypeName()
{
var markupString = @"{x:Type TypeName=sys:String}";
Assert.AreEqual(typeof(string), (new MarkupExtensionParser()).ParseExpression(ref markupString, serviceProvider));
}
}
}