summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/XamlLoaderGetXamlForTypeTests.xaml.cs
blob: 10c3f2e216e961235a620125f36607b4e79c46f9 (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
44
45
46
47
48
49
50
51
52
53
54
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>());
			}
		}
	}
}