diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-12-06 08:56:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-06 08:56:08 +0100 |
commit | ff1bf0b5ef5ceb9b5b4b65809f91c4c608d26fff (patch) | |
tree | 3188b6fd66414745563c1d99af56dd4e6cdd0c79 /Xamarin.Forms.Core.UnitTests | |
parent | c612398bd26bdb0e0d92c7edf5bb102657868431 (diff) | |
download | xamarin-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.Core.UnitTests')
-rw-r--r-- | Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs b/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs index c4e6bbf3..e5b8b60d 100644 --- a/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs +++ b/Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs @@ -253,13 +253,44 @@ namespace Xamarin.Forms.Core.UnitTests Assert.Fail (); } - [Test] - public void ShowKeyInExceptionIfNotFound() - { - var rd = new ResourceDictionary(); - rd.Add("foo", "bar"); - var ex = Assert.Throws<KeyNotFoundException>(() => { var foo = rd["test_invalid_key"]; }); - Assert.That(ex.Message, Is.StringContaining("test_invalid_key")); - } - } + [Test] + public void ShowKeyInExceptionIfNotFound() + { + var rd = new ResourceDictionary(); + rd.Add("foo", "bar"); + var ex = Assert.Throws<KeyNotFoundException>(() => { var foo = rd ["test_invalid_key"]; }); + Assert.That(ex.Message, Is.StringContaining("test_invalid_key")); + } + + class MyRD : ResourceDictionary + { + public MyRD() + { + CreationCount = CreationCount + 1; + Add("foo", "Foo"); + Add("bar", "Bar"); + } + + public static int CreationCount { get; set; } + } + + [Test] + public void MergedWithFailsToMergeAnythingButRDs() + { + var rd = new ResourceDictionary(); + Assert.DoesNotThrow(() => rd.MergedWith = typeof(MyRD)); + Assert.Throws<ArgumentException>(() => rd.MergedWith = typeof(ContentPage)); + } + + [Test] + public void MergedResourcesAreFound() + { + var rd0 = new ResourceDictionary(); + rd0.MergedWith = typeof(MyRD); + + object _; + Assert.True(rd0.TryGetMergedValue("foo", out _)); + Assert.AreEqual("Foo", _); + } + } }
\ No newline at end of file |