Ejemplo n.º 1
0
        public void NullIsAValidValue()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", null);
            Assert.IsNull(dict["foo"]);
        }
Ejemplo n.º 2
0
        public void RegistrationDoesNotPreventGarbageCollection()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", new object());
            GC.Collect();
            object unused = dict["foo"];
        }
Ejemplo n.º 3
0
        public void AddingToSameKeyTwiceAlwaysThrows()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o);
            dict.Add("foo1", o);
        }
Ejemplo n.º 4
0
        public void CanFindOutIfContainsAKey()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", null);
            Assert.IsTrue(dict.ContainsKey("foo"));
            Assert.IsFalse(dict.ContainsKey("foo2"));
        }
Ejemplo n.º 5
0
        public void AddingToSameKeyTwiceAlwaysThrows()
        {
            object o = new object();
            WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

            dict.Add("foo1", o);
            dict.Add("foo1", o);
        }
Ejemplo n.º 6
0
        public void CanRegisterObjectAndFindItByID()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", o);
            Assert.IsNotNull(dict["foo"]);
            Assert.AreSame(o, dict["foo"]);
        }
Ejemplo n.º 7
0
        public void CanRemoveAnObjectThatWasAlreadyAdded()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", o);
            dict.Remove("foo");
            object unused = dict["foo"];
        }
Ejemplo n.º 8
0
        public void CanAddItemAfterPreviousItemIsCollected()
        {
            WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();
            dict.Add("foo", new object());

            GC.Collect();

            dict.Add("foo", new object());
        }
		public void CanRegisterObjectAndFindItByID()
		{
			object o = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo", o);
			Assert.IsNotNull(dict["foo"]);
			Assert.AreSame(o, dict["foo"]);
		}
		public void CanAddSameObjectTwiceWithDifferentKeys()
		{
			object o = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo1", o);
			dict.Add("foo2", o);

			Assert.AreSame(dict["foo1"], dict["foo2"]);
		}
Ejemplo n.º 11
0
        public void KeyCanBeOfArbitraryType()
        {
            object oKey = new object();
            object oVal = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add(oKey, oVal);

            Assert.AreSame(oVal, dict[oKey]);
        }
Ejemplo n.º 12
0
        public void CanAddItemAfterPreviousItemIsCollected()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo", new object());

            GC.Collect();

            dict.Add("foo", new object());
        }
		public void KeyCanBeOfArbitraryType()
		{
			object oKey = new object();
			object oVal = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add(oKey, oVal);

			Assert.AreSame(oVal, dict[oKey]);
		}
Ejemplo n.º 14
0
        public void CanAddSameObjectTwiceWithDifferentKeys()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o);
            dict.Add("foo2", o);

            Assert.AreSame(dict["foo1"], dict["foo2"]);
        }
Ejemplo n.º 15
0
        public void RegistrationDoesNotPreventGarbageCollection()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            RegistrationDoesNotPreventGarbageCollection_TestHelper(dict);
            GC.Collect();
            GC.WaitForPendingFinalizers();

            object unused = dict["foo"];
        }
Ejemplo n.º 16
0
        public void CanAddItemAfterPreviousItemIsCollected()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            CanAddItemAfterPreviousItemIsCollected_TestHelper(dict);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            dict.Add("foo", new object());
        }
Ejemplo n.º 17
0
        public void RemovingAKeyOfOneObjectDoesNotAffectOtherKeysForSameObject()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o);
            dict.Add("foo2", o);
            dict.Remove("foo1");

            Assert.AreSame(o, dict["foo2"]);
        }
		public void CanRegisterTwoObjectsAndGetThemBoth()
		{
			object o1 = new object();
			object o2 = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo1", o1);
			dict.Add("foo2", o2);

			Assert.AreSame(o1, dict["foo1"]);
			Assert.AreSame(o2, dict["foo2"]);
		}
Ejemplo n.º 19
0
        public void CountReturnsNumberOfKeysWithLiveValues()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            CountReturnsNumberOfKeysWithLiveValues_TestHelper(out object o, dict);

            o = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.AreEqual(0, dict.Count);
        }
Ejemplo n.º 20
0
        public void RemovingAKeyDoesNotAffectOtherKeys()
        {
            object o1 = new object();
            object o2 = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o1);
            dict.Add("foo2", o2);
            dict.Remove("foo1");

            Assert.AreSame(o2, dict["foo2"]);
        }
Ejemplo n.º 21
0
        public void CanRegisterTwoObjectsAndGetThemBoth()
        {
            object o1 = new object();
            object o2 = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o1);
            dict.Add("foo2", o2);

            Assert.AreSame(o1, dict["foo1"]);
            Assert.AreSame(o2, dict["foo2"]);
        }
Ejemplo n.º 22
0
        public void CountReturnsNumberOfKeysWithLiveValues()
        {
            object o = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o);
            dict.Add("foo2", o);

            Assert.AreEqual(2, dict.Count);

            o = null;
            GC.Collect();

            Assert.AreEqual(0, dict.Count);
        }
Ejemplo n.º 23
0
        public void CanEnumerate()
        {
            object o1 = new object();
            object o2 = new object();
            WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

            dict.Add("foo1", o1);
            dict.Add("foo2", o2);

            foreach (KeyValuePair<object, object> kvp in dict)
            {
                Assert.IsNotNull(kvp);
                Assert.IsNotNull(kvp.Key);
                Assert.IsNotNull(kvp.Value);
            }
        }
Ejemplo n.º 24
0
        public void CanEnumerate()
        {
            object o1 = new object();
            object o2 = new object();
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Add("foo1", o1);
            dict.Add("foo2", o2);

            foreach (KeyValuePair <object, object> kvp in dict)
            {
                Assert.IsNotNull(kvp);
                Assert.IsNotNull(kvp.Key);
                Assert.IsNotNull(kvp.Value);
            }
        }
Ejemplo n.º 25
0
        private static void CountReturnsNumberOfKeysWithLiveValues_TestHelper(out object o, WeakRefDictionary <object, object> dict)
        {
            o = new object();
            dict.Add("foo1", o);
            dict.Add("foo2", o);

            Assert.AreEqual(2, dict.Count);
        }
		public void RemovingAKeyDoesNotAffectOtherKeys()
		{
			object o1 = new object();
			object o2 = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo1", o1);
			dict.Add("foo2", o2);
			dict.Remove("foo1");

			Assert.AreSame(o2, dict["foo2"]);
		}
Ejemplo n.º 27
0
        public void AskingForAKeyThatDoesntExistThrows()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            object unused = dict["foo"];
        }
Ejemplo n.º 28
0
        public void RemovingANonExistantKeyDoesntThrow()
        {
            WeakRefDictionary <object, object> dict = new WeakRefDictionary <object, object>();

            dict.Remove("foo1");
        }
		public void CountReturnsNumberOfKeysWithLiveValues()
		{
			object o = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo1", o);
			dict.Add("foo2", o);

			Assert.AreEqual(2, dict.Count);

			o = null;
			GC.Collect();

			Assert.AreEqual(0, dict.Count);
		}
		public void RegistrationDoesNotPreventGarbageCollection()
		{
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();
			dict.Add("foo", new object());
			GC.Collect();
			object unused = dict["foo"];
		}
Ejemplo n.º 31
0
 /// <summary>Initializes a new ObjectManager</summary>
 public ObjectManager()
 {
     _objects = new WeakRefDictionary <TKey, T>();
     _factory = Composition.GetInstanceFactory <T>();
 }
		public void RemovingANonExistantKeyDoesntThrow()
		{
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();
			dict.Remove("foo1");
		}
		public void CanFindOutIfContainsAKey()
		{
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo", null);
			Assert.IsTrue(dict.ContainsKey("foo"));
			Assert.IsFalse(dict.ContainsKey("foo2"));
		}
		public void RemovingAKeyOfOneObjectDoesNotAffectOtherKeysForSameObject()
		{
			object o = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo1", o);
			dict.Add("foo2", o);
			dict.Remove("foo1");

			Assert.AreSame(o, dict["foo2"]);
		}
Ejemplo n.º 35
0
 private static void CanAddItemAfterPreviousItemIsCollected_TestHelper(WeakRefDictionary <object, object> dict)
 {
     dict.Add("foo", new object());
 }
		public void AskingForAKeyThatDoesntExistThrows()
		{
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();
			object unused = dict["foo"];
		}
Ejemplo n.º 37
0
 private static void RegistrationDoesNotPreventGarbageCollection_TestHelper(WeakRefDictionary <object, object> dict)
 {
     dict.Add("foo", new object());
 }
		public void CanRemoveAnObjectThatWasAlreadyAdded()
		{
			object o = new object();
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();

			dict.Add("foo", o);
			dict.Remove("foo");
			object unused = dict["foo"];
		}
		public void NullIsAValidValue()
		{
			WeakRefDictionary<object, object> dict = new WeakRefDictionary<object, object>();
			dict.Add("foo", null);
			Assert.IsNull(dict["foo"]);
		}