-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ResourceLoader.xaml.cs
147 lines (128 loc) · 4.71 KB
/
ResourceLoader.xaml.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
public partial class ResourceLoader : ContentPage
{
public ResourceLoader()
{
InitializeComponent();
}
public ResourceLoader(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
public class Tests
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
#pragma warning disable CS0618 // Type or member is obsolete
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider = null;
#pragma warning restore CS0618 // Type or member is obsolete
}
[TestCase(false), TestCase(true)]
public void XamlLoadingUsesResourceLoader(bool useCompiledXaml)
{
var layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.FromHex("#368F95")));
#pragma warning disable CS0618 // Type or member is obsolete
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider = (asmName, path) => {
#pragma warning restore CS0618 // Type or member is obsolete
if (path == "ResourceLoader.xaml")
return @"
<ContentPage
xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
x:Class=""Xamarin.Forms.Xaml.UnitTests.ResourceLoader"" >
<Label x:Name = ""label"" TextColor = ""Pink"" />
</ContentPage >";
return null;
};
layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.Pink));
}
[Test]
public void XamlLoadingUsesResourceProvider2([Values (false, true)]bool useCompiledXaml)
{
var layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.FromHex("#368F95")));
object instance = null;
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider2 = (rlq) => {
if (rlq.ResourcePath == "ResourceLoader.xaml") {
instance = rlq.Instance;
return new Forms.Internals.ResourceLoader.ResourceLoadingResponse
{
ResourceContent = @"
<ContentPage
xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
x:Class=""Xamarin.Forms.Xaml.UnitTests.ResourceLoader""
xmlns:d=""http://xamarin.com/schemas/2014/forms/design""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
mc:Ignorable=""d"" >
<Label x:Name = ""label"" TextColor = ""Pink"" d:TextColor = ""HotPink"" />
</ContentPage >"
};
}
return null;
};
layout = new ResourceLoader(useCompiledXaml);
Assert.That(instance, Is.EqualTo(layout));
Assert.That(layout.label.TextColor, Is.EqualTo(Color.Pink));
}
[Test]
public void XamlLoadingUsesResourceProvider2WithDesignProperties([Values(false, true)]bool useCompiledXaml)
{
var layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.FromHex("#368F95")));
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider2 = (rlq) => {
if (rlq.ResourcePath == "ResourceLoader.xaml")
return new Forms.Internals.ResourceLoader.ResourceLoadingResponse {
UseDesignProperties = true,
ResourceContent = @"
<ContentPage
xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
x:Class=""Xamarin.Forms.Xaml.UnitTests.ResourceLoader""
xmlns:d=""http://xamarin.com/schemas/2014/forms/design""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
mc:Ignorable=""d"" >
<Label x:Name = ""label"" TextColor = ""Pink"" d:TextColor = ""HotPink"" />
</ContentPage >"};
return null;
};
layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.HotPink));
}
[TestCase(false), TestCase(true)]
public void RDLoadingUsesResourceLoader(bool useCompiledXaml)
{
var layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.FromHex("#368F95")));
#pragma warning disable CS0618 // Type or member is obsolete
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider = (asmName, path) => {
#pragma warning restore CS0618 // Type or member is obsolete
if (path == "AppResources/Colors.xaml")
return @"
<ResourceDictionary
xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x = ""http://schemas.microsoft.com/winfx/2009/xaml"" >
<Color x:Key = ""GreenColor"" >#36FF95</Color>
</ResourceDictionary >";
return null;
};
layout = new ResourceLoader(useCompiledXaml);
Assert.That(layout.label.TextColor, Is.EqualTo(Color.FromHex("#36FF95")));
}
}
}
}