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 pathHRTests.cs
103 lines (93 loc) · 3.18 KB
/
HRTests.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
using System;
using NUnit.Framework;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[TestFixture]
public class HRTests
{
[SetUp]
public void Setup()
{
Device.PlatformServices = new MockPlatformServices();
Xamarin.Forms.Internals.Registrar.RegisterAll(new Type[0]);
Application.Current = null;
}
[TearDown]
public void TearDown()
{
Device.PlatformServices = null;
XamlLoader.FallbackTypeResolver = null;
XamlLoader.ValueCreatedCallback = null;
XamlLoader.InstantiationFailedCallback = null;
Forms.Internals.ResourceLoader.ExceptionHandler2 = null;
#pragma warning disable 0618
Internals.XamlLoader.DoNotThrowOnExceptions = false;
#pragma warning restore 0618
Application.ClearCurrent();
}
[Test]
public void LoadResources()
{
var app = @"
<Application xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"">
<Application.Resources>
<ResourceDictionary>
<Color x:Key=""almostPink"">HotPink</Color>
</ResourceDictionary>
</Application.Resources>
</Application>
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf<ResourceDictionary>());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(1));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
[Test]
public void LoadMultipleResources()
{
var app = @"
<Application xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"">
<Application.Resources>
<Color x:Key=""almostPink"">HotPink</Color>
<Color x:Key=""yellowOrGreen"">Chartreuse</Color>
</Application.Resources>
</Application>
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf<ResourceDictionary>());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(2));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
[Test]
public void LoadSingleImplicitResources()
{
var app = @"
<Application xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"">
<Application.Resources>
<Color x:Key=""almostPink"">HotPink</Color>
</Application.Resources>
</Application>
";
Assert.That(Application.Current, Is.Null);
var mockApplication = new MockApplication();
var rd = XamlLoader.LoadResources(app, mockApplication);
Assert.That(rd, Is.TypeOf<ResourceDictionary>());
Assert.That(((ResourceDictionary)rd).Count, Is.EqualTo(1));
//check that the live app hasn't ben modified
Assert.That(Application.Current, Is.EqualTo(mockApplication));
Assert.That(Application.Current.Resources.Count, Is.EqualTo(0));
}
}
}