1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections.Generic;
\r
6 using System.ComponentModel.Composition;
\r
7 using System.UnitTesting;
\r
8 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
10 namespace Microsoft.Internal.Collections
\r
13 public class ReadOnlyDictionaryDebuggerProxyTests
\r
16 public void Constructor_NullAsDictionaryArgument_ShouldThrowArgumentNull()
\r
18 ExceptionAssert.ThrowsArgument<ArgumentNullException>("dictionary", () =>
\r
20 new ReadOnlyDictionaryDebuggerProxy<string, object>((ReadOnlyDictionary<string, object>)null);
\r
25 public void Constructor_EmptyDictionaryAsDictionaryArgument_ShouldSetItemsPropertyToEmptyEnumerable()
\r
27 var dictionary = CreateReadOnlyDictionary<string, object>();
\r
29 var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(dictionary);
\r
31 EnumerableAssert.IsEmpty(proxy.Items);
\r
35 public void Constructor_ValueAsDictionaryArgument_ShouldSetItemsProperty()
\r
37 var expectations = Expectations.GetMetadata();
\r
39 foreach (var e in expectations)
\r
41 var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(CreateReadOnlyDictionary(e));
\r
43 EnumerableAssert.AreEqual(e, proxy.Items);
\r
48 public void Items_ShouldNotCacheUnderlyingItems()
\r
50 var dictionary = new Dictionary<string, object>();
\r
51 dictionary.Add("Name", "Value");
\r
53 var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(CreateReadOnlyDictionary(dictionary));
\r
55 EnumerableAssert.AreEqual(dictionary, proxy.Items);
\r
57 dictionary.Add("AnotherName", "Value");
\r
59 EnumerableAssert.AreEqual(dictionary, proxy.Items);
\r
61 dictionary.Add("AndAnotherName", "Value");
\r
63 EnumerableAssert.AreEqual(dictionary, proxy.Items);
\r
66 private static ReadOnlyDictionary<TKey, TValue> CreateReadOnlyDictionary<TKey, TValue>()
\r
68 return CreateReadOnlyDictionary<TKey, TValue>(null);
\r
71 private static ReadOnlyDictionary<TKey, TValue> CreateReadOnlyDictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
\r
73 return new ReadOnlyDictionary<TKey, TValue>(dictionary);
\r