summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-06 08:56:08 +0100
committerGitHub <noreply@github.com>2016-12-06 08:56:08 +0100
commitff1bf0b5ef5ceb9b5b4b65809f91c4c608d26fff (patch)
tree3188b6fd66414745563c1d99af56dd4e6cdd0c79 /Xamarin.Forms.Xaml.UnitTests
parentc612398bd26bdb0e0d92c7edf5bb102657868431 (diff)
downloadxamarin-forms-ff1bf0b5ef5ceb9b5b4b65809f91c4c608d26fff.tar.gz
xamarin-forms-ff1bf0b5ef5ceb9b5b4b65809f91c4c608d26fff.tar.bz2
xamarin-forms-ff1bf0b5ef5ceb9b5b4b65809f91c4c608d26fff.zip
ResourceDictionary fixes (#536)
* [C] avoid leaking RDs, remove reflection call, validate arguments * [C,Xaml] The only way to get merged values are internal
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml3
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs38
2 files changed, 38 insertions, 3 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml
index 62c1abd2..3e0f7f5b 100644
--- a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
@@ -16,6 +16,7 @@
<ResourceDictionary MergedWith="local:SharedResourceDictionary2"/>
</ContentView.Resources>
<Label x:Name="label2" Style="{StaticResource sharedStyle2}"/>
+ <Label x:Name="label3" Text="{StaticResource foo}"/>
</ContentView>
</StackLayout>
</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs
index a272decc..b9329e4a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs
@@ -1,6 +1,5 @@
using NUnit.Framework;
-
-using Xamarin.Forms;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -19,6 +18,23 @@ namespace Xamarin.Forms.Xaml.UnitTests
[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)
@@ -43,6 +59,24 @@ namespace Xamarin.Forms.Xaml.UnitTests
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);
+ }
+
}
}
} \ No newline at end of file