summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
blob: e5486e74a373fd17ae437b3ab876edd786e3c289 (plain)
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
using System;
using System.Windows.Input;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;

namespace Xamarin.Forms.Xaml.UnitTests
{
#pragma warning disable 0618 //retaining legacy call to obsolete code

	[TestFixture]
	public class XamlLoaderCreateTests
	{
		[Test]
		public void CreateFromXaml ()
		{
			var xaml = @"
				<ContentView xmlns=""http://xamarin.com/schemas/2014/forms""
							 xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						 	 x:Class=""Xamarin.Forms.Xaml.UnitTests.FOO"">
					<Label Text=""Foo""  x:Name=""label""/>
				</ContentView>";

			var view = XamlLoader.Create (xaml);
			Assert.That (view, Is.TypeOf<ContentView> ());
			Assert.AreEqual ("Foo", ((Label)((ContentView)view).Content).Text);
		}

		[Test]
		public void CreateFromXamlDoesntFailOnMissingEventHandler ()
		{
			var xaml = @"
				<Button xmlns=""http://xamarin.com/schemas/2014/forms""
						xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
						Clicked=""handleClick"">
				</Button>";

			Button button = null;
			Assert.DoesNotThrow (() => button = XamlLoader.Create (xaml, true) as Button);
			Assert.NotNull (button);
		}
	}
#pragma warning restore 0618
}