// ----------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // ----------------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.Internal.Collections { [TestClass] public class ReadOnlyDictionaryDebuggerProxyTests { [TestMethod] public void Constructor_NullAsDictionaryArgument_ShouldThrowArgumentNull() { ExceptionAssert.ThrowsArgument("dictionary", () => { new ReadOnlyDictionaryDebuggerProxy((ReadOnlyDictionary)null); }); } [TestMethod] public void Constructor_EmptyDictionaryAsDictionaryArgument_ShouldSetItemsPropertyToEmptyEnumerable() { var dictionary = CreateReadOnlyDictionary(); var proxy = new ReadOnlyDictionaryDebuggerProxy(dictionary); EnumerableAssert.IsEmpty(proxy.Items); } [TestMethod] public void Constructor_ValueAsDictionaryArgument_ShouldSetItemsProperty() { var expectations = Expectations.GetMetadata(); foreach (var e in expectations) { var proxy = new ReadOnlyDictionaryDebuggerProxy(CreateReadOnlyDictionary(e)); EnumerableAssert.AreEqual(e, proxy.Items); } } [TestMethod] public void Items_ShouldNotCacheUnderlyingItems() { var dictionary = new Dictionary(); dictionary.Add("Name", "Value"); var proxy = new ReadOnlyDictionaryDebuggerProxy(CreateReadOnlyDictionary(dictionary)); EnumerableAssert.AreEqual(dictionary, proxy.Items); dictionary.Add("AnotherName", "Value"); EnumerableAssert.AreEqual(dictionary, proxy.Items); dictionary.Add("AndAnotherName", "Value"); EnumerableAssert.AreEqual(dictionary, proxy.Items); } private static ReadOnlyDictionary CreateReadOnlyDictionary() { return CreateReadOnlyDictionary(null); } private static ReadOnlyDictionary CreateReadOnlyDictionary(IDictionary dictionary) { return new ReadOnlyDictionary(dictionary); } } }