Example #1
0
        public void ConcurrentEntitiesModification()
        {
            NoHashCode noHashCode3 = new NoHashCode();
            object     value3      = new object();

            NoHashCode noHashCode4 = new NoHashCode();
            object     value4      = new object();

            IDictionary map = GetIdentityMap();

            map.Add(noHashCode1, value1);
            map.Add(noHashCode2, value2);

            ICollection concurrent = IdentityMap.ConcurrentEntries(map);

            for (int i = 0; i < concurrent.Count;)
            {
                if (i == 0)
                {
                    map.Add(noHashCode3, value3);
                }
                if (i == 1)
                {
                    map.Add(noHashCode4, value4);
                }

                i++;
                Assert.AreEqual(2, concurrent.Count, "Should still be 2 items in the concurrent ICollection");
                Assert.AreEqual(2 + i, map.Count, "Should be " + (2 + i) + " items in the IdentityMap");
            }
        }
        public void SetUp()
        {
            item1 = new MutableHashCode(1);
            item2 = new MutableHashCode(2);

            value1 = new object();
            value2 = new object();

            noHashCode1 = new NoHashCode();
            noHashCode2 = new NoHashCode();

            expectedMap = new Hashtable();
            expectedMap.Add(item1, value1);
            expectedMap.Add(item2, value2);
        }
		public void SetUp()
		{
			item1 = new MutableHashCode(1);
			item2 = new MutableHashCode(2);

			value1 = new object();
			value2 = new object();

			noHashCode1 = new NoHashCode();
			noHashCode2 = new NoHashCode();

			expectedMap = new Hashtable();
			expectedMap.Add(item1, value1);
			expectedMap.Add(item2, value2);
		}
Example #4
0
        public void ConcurrentEntries()
        {
            IDictionary map = GetIdentityMap();

            map.Add(noHashCode1, value1);
            map.Add(noHashCode2, value2);

            // call ConcurrentEntries and verify it doesn't use the HashCode to build the
            // new list.
            ICollection concurrent = IdentityMap.ConcurrentEntries(map);

            Assert.AreEqual(2, concurrent.Count, "There are two elements in concurrent Map");
            foreach (DictionaryEntry de in concurrent)
            {
                NoHashCode noCode      = (NoHashCode)de.Key;
                object     noCodeValue = de.Value;

                Assert.IsTrue(map.Contains(noCode), "The Key in the concurrent map should have been in the original map's Keys");
                Assert.IsTrue(noCodeValue == map[noCode],
                              "The Value identified by the Key in concurrent map should be the same as the IdentityMap");
            }
        }
		public void ConcurrentEntitiesModification()
		{
			NoHashCode noHashCode3 = new NoHashCode();
			object value3 = new object();

			NoHashCode noHashCode4 = new NoHashCode();
			object value4 = new object();

			IDictionary map = GetIdentityMap();
			map.Add(noHashCode1, value1);
			map.Add(noHashCode2, value2);

			ICollection concurrent = IdentityMap.ConcurrentEntries(map);

			for (int i = 0; i < concurrent.Count;)
			{
				if (i == 0) map.Add(noHashCode3, value3);
				if (i == 1) map.Add(noHashCode4, value4);

				i++;
				Assert.AreEqual(2, concurrent.Count, "Should still be 2 items in the concurrent ICollection");
				Assert.AreEqual(2 + i, map.Count, "Should be " + (2 + i) + " items in the IdentityMap");
			}
		}