Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Add the key in the message on throwing a KeyNotFoundException #282

Merged
merged 2 commits into from Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion Xamarin.Forms.Core.UnitTests/ResourceDictionaryTests.cs
Expand Up @@ -252,5 +252,14 @@ public void MultiLevelMerge ()
elt.Parent = parent;
Assert.Fail ();
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the unit test inside the test class. It won't compile otherwise. :) 👎 until fixed (to prevent merge)

[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"));
}
}
}
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core/ResourceDictionary.cs
Expand Up @@ -98,7 +98,7 @@ public bool ContainsKey(string key)
return _innerDictionary[index];
if (_mergedInstance != null && _mergedInstance.ContainsKey(index))
return _mergedInstance[index];
throw new KeyNotFoundException();
throw new KeyNotFoundException($"The resource '{index}' is not present in the dictionary.");
}
set
{
Expand Down