Assert.True(rd0.TryGetMergedValue("foo", out _));
Assert.AreEqual("Foo", _);
}
+
+ [Test]
+ public void ThrowOnDuplicateKey()
+ {
+ var rd0 = new ResourceDictionary();
+ rd0.Add("foo", "Foo");
+ try {
+ rd0.Add("foo", "Bar");
+ } catch (ArgumentException ae) {
+ Assert.AreEqual("A resource with the key 'foo' is already present in the ResourceDictionary.", ae.Message);
+ Assert.Pass();
+ }
+ Assert.Fail();
+ }
}
}
\ No newline at end of file
public void Add(string key, object value)
{
+ if (ContainsKey(key))
+ throw new ArgumentException($"A resource with the key '{key}' is already present in the ResourceDictionary.");
_innerDictionary.Add(key, value);
OnValueChanged(key, value);
}