summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs
blob: b9329e4aa6a3366ae850741d1041e56254b4735f (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;

namespace Xamarin.Forms.Xaml.UnitTests
{
	public partial class TestSharedResourceDictionary : ContentPage
	{
		public TestSharedResourceDictionary ()
		{
			InitializeComponent ();
		}

		public TestSharedResourceDictionary (bool useCompiledXaml)
		{
			//this stub will be replaced at compile time
		}

		[TestFixture]
		public class Tests
		{
			[SetUp]
			public void Setup()
			{
				Device.PlatformServices = new MockPlatformServices();
				Application.Current = new MockApplication {
					Resources = new ResourceDictionary {
						MergedWith = typeof(MyRD)
					}
				};
			}

			[TearDown]
			public void TearDown()
			{
				Device.PlatformServices = null;
			}

			[TestCase (false)]
			[TestCase (true)]
			public void MergedResourcesAreFound (bool useCompiledXaml)
			{
				var layout = new TestSharedResourceDictionary (useCompiledXaml);
				Assert.AreEqual (Color.Pink, layout.label.TextColor);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void NoConflictsBetweenSharedRDs (bool useCompiledXaml)
			{
				var layout = new TestSharedResourceDictionary (useCompiledXaml);
				Assert.AreEqual (Color.Pink, layout.label.TextColor);
				Assert.AreEqual (Color.Purple, layout.label2.TextColor);
			}

			[TestCase (false)]
			[TestCase (true)]
			public void ImplicitStyleCanBeSharedFromSharedRD (bool useCompiledXaml)
			{
				var layout = new TestSharedResourceDictionary(useCompiledXaml);
				Assert.AreEqual(Color.Red, layout.implicitLabel.TextColor);
			}

			class MyRD : ResourceDictionary
			{
				public MyRD()
				{
					Add("foo", "Foo");
					Add("bar", "Bar");
				}
			}

			[TestCase(false)]
			[TestCase(true)]
			public void MergedRDAtAppLevel(bool useCompiledXaml)
			{
				var layout = new TestSharedResourceDictionary(useCompiledXaml);
				Assert.AreEqual("Foo", layout.label3.Text);
			}

		}
	}
}