Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft')
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/.gitattributes1
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/AssumesTests.cs301
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/.gitattributes4
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ConditionalWeakTableTests.cs226
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxyTests.cs76
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryTests.cs214
-rw-r--r--mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/WeakReferenceCollectionTests.cs104
7 files changed, 0 insertions, 926 deletions
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/.gitattributes b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/.gitattributes
deleted file mode 100644
index 6562b26af9d..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-/AssumesTests.cs -crlf
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/AssumesTests.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/AssumesTests.cs
deleted file mode 100644
index 6286722b4db..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/AssumesTests.cs
+++ /dev/null
@@ -1,301 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.ComponentModel.Composition;
-using System.Collections.Generic;
-using System.UnitTesting;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-#if !SILVERLIGHT
-using System.Runtime.Serialization;
-#endif
-
-namespace Microsoft.Internal
-{
- [TestClass]
- public class AssumesTests
- {
- [TestMethod]
- public void NotNullOfT_NullAsValueArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string>((string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2_NullAsValue1Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string>((string)null, "Value");
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2_NullAsValue2Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string>("Value", (string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2_NullAsValue1ArgumentAndValue2Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string>((string)null, (string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue1Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>((string)null, "Value", "Value");
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue2Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>("Value", (string)null, "Value");
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue3Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>("Value", "Value", (string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue1ArgumentAndValue2Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>((string)null, (string)null, "Value");
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue1ArgumentAnd3_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>((string)null, "Value", (string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_NullAsValue2ArgumentAndValue3Argument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNull<string, string, string>("Value", (string)null, (string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOfT_ValueAsValueArgument_ShouldNotThrow()
- {
- Assumes.NotNull<string>("Value");
- }
-
- [TestMethod]
- public void NotNullOfT1T2_ValueAsValue1ArgumentAndValue2Argument_ShouldNotThrow()
- {
- Assumes.NotNull<string, string>("Value", "Value");
- }
-
- [TestMethod]
- public void NotNullOfT1T2T3_ValueAsValue1ArgumentAndValue2ArgumentAndValue3Argument_ShouldNotThrow()
- {
- Assumes.NotNull<string, string, string>("Value", "Value", "Value");
- }
-
- [TestMethod]
- public void NullOfT_NullAsValueArgument_ShouldNotThrow()
- {
- Assumes.Null<string>((string)null);
- }
-
- [TestMethod]
- public void NullOfT_ValueAsValueArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.Null<string>("Value");
- });
- }
-
- [TestMethod]
- public void NotNullOrEmpty_NullAsValueArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNullOrEmpty((string)null);
- });
- }
-
- [TestMethod]
- public void NotNullOrEmpty_EmptyAsValueArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.NotNullOrEmpty("");
- });
- }
-
- [TestMethod]
- public void NotNullOrEmpty_ValueAsValueArgument_ShouldNotThrow()
- {
- var expectations = new List<string>();
- expectations.Add(" ");
- expectations.Add(" ");
- expectations.Add(" ");
- expectations.Add("Value");
-
- foreach (var e in expectations)
- {
- Assumes.NotNullOrEmpty(e);
- }
- }
-
- [TestMethod]
- public void IsTrue1_FalseAsConditionArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.IsTrue(false);
- });
- }
-
- [TestMethod]
- public void IsTrue2_FalseAsConditionArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.IsTrue(false, "Message");
- });
- }
-
- [TestMethod]
- public void IsTrue1_TrueAsConditionArgument_ShouldNotThrow()
- {
- Assumes.IsTrue(true);
- }
-
- [TestMethod]
- public void IsTrue2_TrueAsConditionArgument_ShouldNotThrow()
- {
- Assumes.IsTrue(true, "Message");
- }
-
- [TestMethod]
- public void IsFalse1_TrueAsConditionArgument_ShouldThrowInternalErrorException()
- {
- Throws(() =>
- {
- Assumes.IsFalse(true);
- });
- }
-
- [TestMethod]
- public void IsFalse1_FalseAsConditionArgument_ShouldNotThrow()
- {
- Assumes.IsFalse(false);
- }
-
- [TestMethod]
- public void NotReachable_ShouldAlwaysThrow()
- {
- Throws(() =>
- {
- Assumes.NotReachable<object>();
- });
- }
-
- [TestMethod]
- public void Fail_ShouldThrowInternalErrorException()
- {
- var expectations = Expectations.GetExceptionMessages();
-
- foreach (var e in expectations)
- {
- Throws(() =>
- {
- Assumes.Fail(e);
- });
- }
- }
-
- private static void Throws(Action action)
- {
- try
- {
- action();
- Assert.Fail();
- }
- catch (Exception ex)
- {
- Type exceptionType = ex.GetType();
-
- // The exception should not be a
- // publicily catchable exception
- Assert.IsFalse(exceptionType.IsVisible);
- }
- }
-
-#if !SILVERLIGHT
-
- [TestMethod]
- public void Message_CanBeSerialized()
- {
- var expectations = Expectations.GetExceptionMessages();
-
- foreach (var e in expectations)
- {
- var exception = CreateInternalErrorException(e);
-
- var result = SerializationTestServices.RoundTrip(exception);
-
- Assert.AreEqual(exception.Message, result.Message);
- }
- }
-
-#endif
-
- private static Exception CreateInternalErrorException()
- {
- return CreateInternalErrorException((string)null);
- }
-
- private static Exception CreateInternalErrorException(string message)
- {
- Exception exception = null;
-
- try
- {
- Assumes.Fail(message);
- }
- catch (Exception ex)
- {
- exception = ex;
- }
-
- Assert.IsNotNull(exception);
- return exception;
- }
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/.gitattributes b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/.gitattributes
deleted file mode 100644
index 1496b702476..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/.gitattributes
+++ /dev/null
@@ -1,4 +0,0 @@
-/ConditionalWeakTableTests.cs -crlf
-/ReadOnlyDictionaryDebuggerProxyTests.cs -crlf
-/ReadOnlyDictionaryTests.cs -crlf
-/WeakReferenceCollectionTests.cs -crlf
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ConditionalWeakTableTests.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ConditionalWeakTableTests.cs
deleted file mode 100644
index 66e52344156..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ConditionalWeakTableTests.cs
+++ /dev/null
@@ -1,226 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.UnitTesting;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Microsoft.Internal.Collections
-{
- [TestClass]
- public class ConditionalWeakTableTests
- {
- [TestMethod]
- public void Add_KeyShouldBeCollected()
- {
- var obj = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, new object());
-
- var wr = new WeakReference(obj);
-
- obj = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- Assert.IsNull(wr.Target, "Key should be collected now!");
-
- GC.KeepAlive(cwt);
- }
-
- [TestMethod]
- public void Add_KeyHeld_ValueShouldNotBeCollected()
- {
- var obj = new object();
- var str = new StringBuilder();
- var cwt = new ConditionalWeakTable<object, StringBuilder>();
-
- var wrKey = new WeakReference(obj);
- var wrValue = new WeakReference(str);
-
- cwt.Add(obj, str);
-
- str = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- // Should still have both references
- Assert.IsNotNull(wrKey.Target, "Key should NOT be collected yet!");
- Assert.IsNotNull(wrValue.Target, "Value should NOT be collected yet!");
-
- GC.KeepAlive(obj);
- GC.KeepAlive(cwt);
- }
-
-#if CLR40
- [TestMethod]
- public void Add_KeyCollected_ValueShouldBeCollected()
- {
- var obj = new object();
- var str = new StringBuilder();
- var cwt = new ConditionalWeakTable<object, StringBuilder>();
-
- cwt.Add(obj, str);
-
- var wrKey = new WeakReference(obj);
- var wrValue = new WeakReference(str);
- str = null;
- obj = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- Assert.IsNull(wrKey.Target, "Key should be collected now!");
- Assert.IsNull(wrValue.Target, "Value should be collected now!");
-
- GC.KeepAlive(cwt);
- }
-#endif
-
- [TestMethod]
- public void Remove_ValidKey_ShouldReturnTrue()
- {
- var obj = new object();
- var obj2 = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, obj2);
-
- Assert.IsTrue(cwt.Remove(obj));
- }
-
- [TestMethod]
- public void Remove_InvalidKey_ShouldReturnTrue()
- {
- var obj = new object();
- var obj2 = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, obj2);
-
- Assert.IsFalse(cwt.Remove(obj2));
- }
-
- [TestMethod]
- public void TryGetValue_ValidKey_ShouldReturnTrueAndValue()
- {
- var obj = new object();
- var obj2 = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, obj2);
-
- object obj3;
- Assert.IsTrue(cwt.TryGetValue(obj, out obj3), "Should find a value with the key!");
- Assert.AreEqual(obj2, obj3);
- }
-
- [TestMethod]
- public void TryGetValue_InvalidKey_ShouldReturnFalseAndNull()
- {
- var obj = new object();
- var obj2 = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, obj2);
-
- object obj3;
- Assert.IsFalse(cwt.TryGetValue(obj2, out obj3), "Should NOT find a value with the key!");
- Assert.IsNull(obj3);
- }
-
-#if !CLR40
- [TestMethod]
- public void Add_KeyValueSame_KeyShouldNotBeCollected()
- {
- // Dev10:556089 - This test demonstrations a bug in our implementation
- // of ConditionalWeakTable which needs CLR 4 support to fix so once
- // we switch to the CLR 4 version of ConditionalWeakTable this should go away.
-
- var obj = new object();
- var cwt = new ConditionalWeakTable<object, object>();
-
- cwt.Add(obj, obj);
-
- var wrKey = new WeakReference(obj);
- obj = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- Assert.IsNotNull(wrKey.Target, "Key should NOT be collected yet!");
-
- // Apply pressure to ensure they still don't go away.
- ApplyMemoryPressureOnConditionalWeakTable(cwt);
-
- Assert.IsNotNull(wrKey.Target, "Key should NOT be collected yet!");
-
- GC.KeepAlive(cwt);
- }
-
- public class ObjectHolder
- {
- public object Obj { get; set; }
- public ObjectHolder() { }
- public ObjectHolder(object obj)
- {
- Obj = obj;
- }
- }
-
- [TestMethod]
- public void Add_ValueReferencesKey_KeyAndValueShouldNotBeCollected()
- {
- // Dev10:556089 - This test demonstrations a bug in our implementation
- // of ConditionalWeakTable which needs CLR 4 support to fix so once
- // we switch to the CLR 4 version of ConditionalWeakTable this should go away.
-
- var obj = new object();
- var holder = new ObjectHolder(obj);
- var cwt = new ConditionalWeakTable<object, ObjectHolder>();
-
- cwt.Add(obj, holder);
-
- var wrKey = new WeakReference(obj);
- var wrValue = new WeakReference(holder);
- holder = null;
- obj = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- Assert.IsNotNull(wrKey.Target, "Key should NOT be collected yet!");
- Assert.IsNotNull(wrValue.Target, "Value should NOT be collected now!");
-
- // Apply pressure to ensure they still don't go away.
- ApplyMemoryPressureOnConditionalWeakTable(cwt);
-
- Assert.IsNotNull(wrKey.Target, "Key should NOT be collected yet!");
- Assert.IsNotNull(wrValue.Target, "Value should NOT be collected now!");
-
- GC.KeepAlive(cwt);
- }
-
- private void ApplyMemoryPressureOnConditionalWeakTable<T,V>(ConditionalWeakTable<T,V> table)
- where T : class, new()
- where V : class, new()
- {
- // Adding 100 items should do it.
- for (int i = 0; i < 100; i++)
- {
- table.Add(new T(), new V());
- }
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
-#endif //!CLR40
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxyTests.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxyTests.cs
deleted file mode 100644
index d0068e24d90..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxyTests.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// -----------------------------------------------------------------------
-// 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<ArgumentNullException>("dictionary", () =>
- {
- new ReadOnlyDictionaryDebuggerProxy<string, object>((ReadOnlyDictionary<string, object>)null);
- });
- }
-
- [TestMethod]
- public void Constructor_EmptyDictionaryAsDictionaryArgument_ShouldSetItemsPropertyToEmptyEnumerable()
- {
- var dictionary = CreateReadOnlyDictionary<string, object>();
-
- var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(dictionary);
-
- EnumerableAssert.IsEmpty(proxy.Items);
- }
-
- [TestMethod]
- public void Constructor_ValueAsDictionaryArgument_ShouldSetItemsProperty()
- {
- var expectations = Expectations.GetMetadata();
-
- foreach (var e in expectations)
- {
- var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(CreateReadOnlyDictionary(e));
-
- EnumerableAssert.AreEqual(e, proxy.Items);
- }
- }
-
- [TestMethod]
- public void Items_ShouldNotCacheUnderlyingItems()
- {
- var dictionary = new Dictionary<string, object>();
- dictionary.Add("Name", "Value");
-
- var proxy = new ReadOnlyDictionaryDebuggerProxy<string, object>(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<TKey, TValue> CreateReadOnlyDictionary<TKey, TValue>()
- {
- return CreateReadOnlyDictionary<TKey, TValue>(null);
- }
-
- private static ReadOnlyDictionary<TKey, TValue> CreateReadOnlyDictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
- {
- return new ReadOnlyDictionary<TKey, TValue>(dictionary);
- }
- }
-} \ No newline at end of file
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryTests.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryTests.cs
deleted file mode 100644
index bad8b195370..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/ReadOnlyDictionaryTests.cs
+++ /dev/null
@@ -1,214 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.UnitTesting;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Microsoft.Internal.Collections
-{
- [TestClass]
- public class ReadOnlyDictionaryTests
- {
- [TestMethod]
- public void Constructor_NullAsDictionaryArgument_ShouldCreateEmptyDictionary()
- {
- var dictionary = new ReadOnlyDictionary<string, object>(null);
-
- EnumerableAssert.IsEmpty(dictionary);
- }
-
- [TestMethod]
- public void Constructor_WritableDictionaryAsDictionaryArgument_ShouldPopulateCollection()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = new ReadOnlyDictionary<string, object>(dictionary);
-
- EnumerableAssert.AreEqual(dictionary, readOnlyDictionary);
- }
-
- [TestMethod]
- public void Add1_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary.Add(new KeyValuePair<string, object>("Key", "Value"));
- });
- }
-
- [TestMethod]
- public void Add2_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary.Add("Key", "Value");
- });
- }
-
- [TestMethod]
- public void Clear_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary.Clear();
- });
- }
-
- [TestMethod]
- public void Remove1_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary.Remove("Value");
- });
- }
-
- [TestMethod]
- public void Remove2_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary.Remove(new KeyValuePair<string, object>("Key", "Value"));
- });
- }
-
- [TestMethod]
- public void ItemSet_ShouldThrowNotSupported()
- {
- var dictionary = GetReadOnlyDictionaryWithData();
-
- ExceptionAssert.Throws<NotSupportedException>(() =>
- {
- dictionary["Key"] = "Value";
- });
- }
-
- [TestMethod]
- public void Keys_ShouldReturnWrappedDictionaryKeys()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- EnumerableAssert.AreEqual(readOnlyDictionary.Keys, dictionary.Keys);
- }
-
- [TestMethod]
- public void Values_ShouldReturnWrappedDictionaryValues()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- EnumerableAssert.AreEqual(readOnlyDictionary.Values, readOnlyDictionary.Values);
- }
-
- [TestMethod]
- public void IsReadOnly_ShouldAlwaysBeTrue()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- Assert.IsFalse(dictionary.IsReadOnly);
- Assert.IsTrue(readOnlyDictionary.IsReadOnly);
- }
-
- [TestMethod]
- public void Count_ShouldReturnWrappedDictionaryCount()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- Assert.AreEqual(dictionary.Count, readOnlyDictionary.Count);
- }
-
- [TestMethod]
- public void ContainsKey()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- Assert.IsTrue(readOnlyDictionary.ContainsKey("Key1"));
- Assert.IsFalse(readOnlyDictionary.ContainsKey("InvalidKey"));
- }
-
- [TestMethod]
- public void Contains()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
-
- Assert.IsTrue(readOnlyDictionary.Contains(new KeyValuePair<string,object>("Key1", "Value1")));
- Assert.IsFalse(readOnlyDictionary.Contains(new KeyValuePair<string,object>("InvalidKey", "Value1")));
- Assert.IsFalse(readOnlyDictionary.Contains(new KeyValuePair<string,object>("Key1", "InvalidValue")));
- }
-
- [TestMethod]
- public void CopyTo()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
- KeyValuePair<string, object>[] destination = new KeyValuePair<string, object> [readOnlyDictionary.Count];
- readOnlyDictionary.CopyTo(destination, 0);
- EnumerableAssert.AreEqual(readOnlyDictionary, destination);
- }
-
- [TestMethod]
- public void GetEnumerator()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
- IEnumerable<KeyValuePair<string, object>> genericEnumerable = readOnlyDictionary;
- EnumerableAssert.AreEqual(genericEnumerable, dictionary);
- IEnumerable weakEnumerable = (IEnumerable)readOnlyDictionary;
- EnumerableAssert.AreEqual(weakEnumerable, dictionary);
- }
-
- [TestMethod]
- public void Item()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
- Assert.AreEqual("Value1", readOnlyDictionary["Key1"], "Expecting to read wrapped value");
- }
-
- [TestMethod]
- public void TryGetValue()
- {
- var dictionary = GetWritableDictionaryWithData();
- var readOnlyDictionary = GetReadOnlyDictionary(dictionary);
- object result;
- bool ret = readOnlyDictionary.TryGetValue("Key1", out result);
- Assert.IsTrue(ret, "Expecting TryGetExportedValue to return true for wrapped key");
- Assert.AreEqual("Value1", result, "Expecting TryGetExportedValue to return wrapped value");
- }
-
- private static IDictionary<String, object> GetReadOnlyDictionaryWithData()
- {
- return GetReadOnlyDictionary(GetWritableDictionaryWithData());
- }
-
- private static IDictionary<TKey, TValue> GetReadOnlyDictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
- {
- return new ReadOnlyDictionary<TKey, TValue>(dictionary);
- }
-
- private static IDictionary<String, object> GetWritableDictionaryWithData()
- {
- IDictionary<String, object> dictionary = new Dictionary<String, object>();
- dictionary.Add("Key1", "Value1");
- dictionary.Add("Key2", 42);
- return dictionary;
- }
- }
-} \ No newline at end of file
diff --git a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/WeakReferenceCollectionTests.cs b/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/WeakReferenceCollectionTests.cs
deleted file mode 100644
index 2c65224df26..00000000000
--- a/mcs/class/System.ComponentModel.Composition/Tests/ComponentModelUnitTest/Microsoft/Internal/Collections/WeakReferenceCollectionTests.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.UnitTesting;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Microsoft.Internal.Collections
-{
- [TestClass]
- public class WeakReferenceCollectionTests
- {
- [TestMethod]
- public void Add_ObjectShouldGetCollected()
- {
- var obj = new object();
- var wrc = new WeakReferenceCollection<object>();
-
- wrc.Add(obj);
-
- var wr = new WeakReference(obj);
- obj = null;
-
- Assert.IsNotNull(wr.Target, "Object should NOT have been collected yet!");
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- Assert.IsNull(wr.Target, "Object should have been collected!");
-
- GC.KeepAlive(wrc);
- }
-
- [TestMethod]
- public void Remove_ObjectShouldGetRemoved()
- {
- var obj = new object();
- var wrc = new WeakReferenceCollection<object>();
-
- wrc.Add(obj);
-
- Assert.AreEqual(1, wrc.AliveItemsToList().Count, "Should have 1 item!");
-
- wrc.Remove(obj);
-
- Assert.AreEqual(0, wrc.AliveItemsToList().Count, "Should have 0 item!");
- }
-
- [TestMethod]
- public void AliveItemsToList_ShouldReturnAllItems()
- {
- var list = new object[] {new object(), new object(), new object()};
- var wrc = new WeakReferenceCollection<object>();
-
- foreach (object obj in list)
- {
- wrc.Add(obj);
- }
-
- Assert.AreEqual(list.Length, wrc.AliveItemsToList().Count, "Should have same number of items!");
- }
-
- [TestMethod]
- public void AliveItemsToList_ShouldReturnAllAliveItems()
- {
- var list = new object[] { new object(), new object(), new object() };
- var wrc = new WeakReferenceCollection<object>();
-
- var obj1 = new object();
- wrc.Add(obj1);
-
- foreach (object obj in list)
- {
- wrc.Add(obj);
- }
-
- var obj2 = new object();
- wrc.Add(obj2);
-
- Assert.AreEqual(list.Length + 2, wrc.AliveItemsToList().Count, "Should have same number of items!");
-
- obj1 = obj2 = null;
-
- GC.Collect();
- GC.WaitForPendingFinalizers();
-
- var aliveItems = wrc.AliveItemsToList();
- Assert.AreEqual(list.Length, aliveItems.Count, "Should have 2 less items!");
-
- Assert.AreEqual(list[0], aliveItems[0]);
- Assert.AreEqual(list[1], aliveItems[1]);
- Assert.AreEqual(list[2], aliveItems[2]);
- }
-
- [TestMethod]
- public void AliveItemsToList_ShouldReturnEmpty()
- {
- var wrc = new WeakReferenceCollection<object>();
- Assert.AreEqual(0, wrc.AliveItemsToList().Count, "Should have 0 items!");
- }
- }
-} \ No newline at end of file