+ ConcreteDictionary myDictionary = new ConcreteDictionary (1);
+ Assert.AreEqual (myDictionary, myDictionary.BaseDictionary);
+ }
+
+ public class NullDictionary : DictionaryBase
+ {
+ protected override object OnGet (object key, object currentValue)
+ {
+ return null;
+ }
+ }
+
+ [Test]
+ public void NullDictionary_Get ()
+ {
+ IDictionary dictionary = new NullDictionary ();
+ dictionary ["a"] = "b";
+ Assert.AreEqual ("b", dictionary ["a"]);
+ }
+
+ public class ModifyDictionary : DictionaryBase
+ {
+ protected override object OnGet (object key, object currentValue)
+ {
+ (this as IDictionary) [key] = key;
+ return key;
+ }
+ }
+
+ [Test]
+ public void ModifyDictionary_Get ()
+ {
+ IDictionary dictionary = new ModifyDictionary ();
+ dictionary ["a"] = "b";
+#if NET_2_0
+ // first time we return "b" - because the value was cached
+ Assert.AreEqual ("b", dictionary ["a"], "#1");
+#else
+ Assert.AreEqual ("a", dictionary ["a"], "#1");
+#endif
+ // second time we return "a" - because it's the value in the dictionary
+ Assert.AreEqual ("a", dictionary ["a"], "#2");
+ }
+
+ public class ThrowDictionary : DictionaryBase
+ {
+ protected override object OnGet (object key, object currentValue)
+ {
+ throw new ArgumentException ((string) key, (string) currentValue);
+ }
+ }
+
+ [Test]
+ public void ThrowDictionary_Get ()
+ {
+ IDictionary dictionary = new ThrowDictionary ();
+ dictionary ["a"] = "b";
+
+ try {
+ object value = dictionary ["a"];
+ Assert.Fail ("#1: " + value);
+ } catch (ArgumentException ex) {
+ Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.IsTrue (ex.Message.StartsWith ("a"), "#5");
+ Assert.AreEqual ("b", ex.ParamName, "#6");
+ }