public void TestLockFreeDictionary()
        {
            IDictionary<int, Guid> dict = new ConcurrentDictionary<int, Guid>();

            KeyValuePair<int, Guid> test = new KeyValuePair<int, Guid>(-64, Guid.NewGuid());

            dict.Add(42, Guid.NewGuid());
            dict.Add(22, Guid.NewGuid());
            dict.Add(test);
            dict.Add(55, Guid.NewGuid());

            Assert.IsTrue(dict.ContainsKey(-64));
            Assert.IsTrue(dict.Contains(test));
            Assert.IsFalse(dict.Contains(new KeyValuePair<int, Guid>(-64, new Guid())));

            dict[-64] = Guid.NewGuid();
            Assert.IsFalse(dict.Contains(test));

            Guid newID = Guid.NewGuid();
            dict[12] = newID;
            Guid id = dict[12];

            Assert.IsTrue(newID == id);

            Assert.IsTrue(dict.Count == 5);

            dict.Remove(-64);
            Assert.IsTrue(dict.Count == 4);

        }
        public void ContainsKeyPairTest()
        {
            var validKeyPair = new KeyValuePair <string, string> ("key", "validValue");
            var wrongKeyPair = new KeyValuePair <string, string> ("key", "wrongValue");

            IDictionary <string, string> dict = new ConcurrentDictionary <string, string> ();

            dict.Add(validKeyPair);

            Assert.IsTrue(dict.Contains(validKeyPair));
            Assert.IsFalse(dict.Contains(wrongKeyPair));
        }
        public static void TestIDictionary()
        {
            IDictionary dictionary = new ConcurrentDictionary<string, int>();
            Assert.False(dictionary.IsReadOnly);

            foreach (var entry in dictionary)
            {
                Assert.False(true, "TestIDictionary:  FAILED.  GetEnumerator retuned items when the dictionary is empty");
            }

            const int SIZE = 10;
            for (int i = 0; i < SIZE; i++)
                dictionary.Add(i.ToString(), i);

            Assert.AreEqual(SIZE, dictionary.Count);

            //test contains
            Assert.False(dictionary.Contains(1), "TestIDictionary:  FAILED.  Contain retuned true for incorrect key type");
            Assert.False(dictionary.Contains("100"), "TestIDictionary:  FAILED.  Contain retuned true for incorrect key");
            Assert.True(dictionary.Contains("1"), "TestIDictionary:  FAILED.  Contain retuned false for correct key");

            //test GetEnumerator
            int count = 0;
            foreach (var obj in dictionary)
            {
                DictionaryEntry entry = (DictionaryEntry)obj;
                string key = (string)entry.Key;
                int value = (int)entry.Value;
                int expectedValue = int.Parse(key);
                Assert.True(value == expectedValue,
                    String.Format("TestIDictionary:  FAILED.  Unexpected value returned from GetEnumerator, expected {0}, actual {1}", value, expectedValue));
                count++;
            }

            Assert.AreEqual(SIZE, count);
            Assert.AreEqual(SIZE, dictionary.Keys.Count);
            Assert.AreEqual(SIZE, dictionary.Values.Count);

            //Test Remove
            dictionary.Remove("9");
            Assert.AreEqual(SIZE - 1, dictionary.Count);

            //Test this[]
            for (int i = 0; i < dictionary.Count; i++)
                Assert.AreEqual(i, (int)dictionary[i.ToString()]);

            dictionary["1"] = 100; // try a valid setter
            Assert.AreEqual(100, (int)dictionary["1"]);

            //nonsexist key
            Assert.Null(dictionary["NotAKey"]);
        }
Example #4
0
        public void PairCollide()
        {
            var firstPair  = new KeyValuePair <string, string>("key", "validValue");
            var secondPair = new KeyValuePair <string, string>("key", "wrongValue");

            IDictionary <string, string> dict = new ConcurrentDictionary <string, string>();

            dict.Add(firstPair); // Do not change to object initialization
            Assert.Throws <ArgumentException>(() => dict.Add(secondPair));

            Assert.IsTrue(dict.Contains(firstPair));
            Assert.IsFalse(dict.Contains(secondPair));
        }
Example #5
0
        public object GetPropertyData(ServiceType type, string data)
        {
            if (OperationContext.Current != null)
            {
                IPublishing registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>();

                var result = false;
                if (!_callbackList.Contains(new KeyValuePair <ServiceType, IPublishing>(type, registeredUser)))
                {
                    result = _callbackList.TryAdd(type, registeredUser);
                }
            }
            IManager manager;
            object   childManager = null;

            DataBoundary serializedObject = JsonConvert.DeserializeObject <DataBoundary>(data);

            if (Services.TryGetValue(type, out manager) && serializedObject != null)
            {
                MethodInfo method;
                if (serializedObject.TypeName != string.Empty && serializedObject.TypeName != null)
                {
                    method       = manager.GetType().GetMethod(serializedObject.TypeName);
                    childManager = method.Invoke(manager, new object[0]);
                }

                object       temp;
                PropertyInfo info;
                if (childManager != null)
                {
                    info = childManager.GetType().GetProperty(serializedObject.CommandName);
                    temp = childManager.GetType().GetProperty(serializedObject.CommandName).GetValue(childManager, new object[0]);
                }
                else
                {
                    info = manager.GetType().GetProperty(serializedObject.CommandName);
                    temp = manager.GetType().GetProperty(serializedObject.CommandName).GetValue(manager, new object[0]);
                }

                serializedObject.Attributes.Clear();
                serializedObject.Attributes.Add(info.GetMethod.ReturnType, temp);

                return(JsonConvert.SerializeObject(serializedObject));
            }

            return(null);
        }
Example #6
0
 public bool Contains(KeyValuePair <TKey, TValue> item)
 {
     if (dict == null)
     {
         return(false);
     }
     return(dict.Contains(item));
 }
        public void Contains_KeyValuePairThrowsNotImplementedException()
        {
            // Arrange
            ConcurrentDictionary <int, int> dictionary = new ConcurrentDictionary <int, int>();

            // Act/Assert
            Assert.Throws <NotImplementedException>(() => dictionary.Contains(new KeyValuePair <int, int>(0, 0)));
        }
        public bool Contains(KeyValuePair <TKey, TValue> item)
        {
#if !PORTABLE
            return(_dictionary.ContainsKey(item.Key));
#else
            return(_dictionary.Contains(item));
#endif
        }
        public static void TestIDictionary_Negative()
        {
            IDictionary dictionary = new ConcurrentDictionary <string, int>();

            Assert.Throws <ArgumentNullException>(
                () => dictionary.Add(null, 1));
            // "TestIDictionary:  FAILED.  Add didn't throw ANE when null key is passed");

            Assert.Throws <ArgumentException>(
                () => dictionary.Add(1, 1));
            // "TestIDictionary:  FAILED.  Add didn't throw AE when incorrect key type is passed");

            Assert.Throws <ArgumentException>(
                () => dictionary.Add("1", "1"));
            // "TestIDictionary:  FAILED.  Add didn't throw AE when incorrect value type is passed");

            Assert.Throws <ArgumentNullException>(
                () => dictionary.Contains(null));
            // "TestIDictionary:  FAILED.  Contain didn't throw ANE when null key is passed");

            //Test Remove
            Assert.Throws <ArgumentNullException>(
                () => dictionary.Remove(null));
            // "TestIDictionary:  FAILED.  Remove didn't throw ANE when null key is passed");

            //Test this[]
            Assert.Throws <ArgumentNullException>(
                () => { object val = dictionary[null]; });
            // "TestIDictionary:  FAILED.  this[] getter didn't throw ANE when null key is passed");
            Assert.Throws <ArgumentNullException>(
                () => dictionary[null] = 0);
            // "TestIDictionary:  FAILED.  this[] setter didn't throw ANE when null key is passed");

            Assert.Throws <ArgumentException>(
                () => dictionary[1] = 0);
            // "TestIDictionary:  FAILED.  this[] setter didn't throw AE when invalid key type is passed");

            Assert.Throws <ArgumentException>(
                () => dictionary["1"] = "0");
            // "TestIDictionary:  FAILED.  this[] setter didn't throw AE when invalid value type is passed");
        }
 /// <summary>
 /// Checks whether the specified item exists or not
 /// </summary>
 public bool Contains(KeyValuePair <TKey, TValue> item)
 {
     return(_concurrentDictionary.Contains(item));
 }
        public void PairCollide()
        {
            var firstPair = new KeyValuePair<string, string>("key", "validValue");
            var secondPair = new KeyValuePair<string, string>("key", "wrongValue");

            IDictionary<string, string> dict = new ConcurrentDictionary<string, string>();
            dict.Add(firstPair);
            Assert.Throws<ArgumentException>(() => dict.Add(secondPair));

            Assert.IsTrue(dict.Contains(firstPair));
            Assert.IsFalse(dict.Contains(secondPair));
        }
Example #12
0
 /// <summary>
 /// 保存数据库上下文池中所有已更改的数据库上下文
 /// </summary>
 /// <returns></returns>
 public int SavePoolNow()
 {
     // 查找所有已改变的数据库上下文并保存更改
     return(_dbContexts
            .Where(u => u.Value != null && u.Value.ChangeTracker.HasChanges() && !_failedDbContexts.Contains(u))
            .Select(u => u.Value.SaveChanges()).Count());
 }
Example #13
0
 /// <summary>
 /// Determines whether the current collection contains the specified value.
 /// </summary>
 /// <param name="item">Item.</param>
 public bool Contains(KeyValuePair <string, Cash> item)
 {
     return(_currencies.Contains(item));
 }
Example #14
0
 public bool Contains(KeyValuePair <string, string> item)
 {
     return(cacheKeyCollection.Contains(item));
 }
Example #15
0
 /// <summary>
 /// Check if this collection contains this key value pair.
 /// </summary>
 /// <param name="pair">Search key-value pair</param>
 /// <remarks>IDictionary implementation</remarks>
 /// <returns>Bool true if contains this key-value pair</returns>
 public bool Contains(KeyValuePair <Symbol, Security> pair)
 {
     return(_securityManager.Contains(pair));
 }
Example #16
0
 public bool Contains(KeyValuePair <TKey, TValue> item)
 {
     return(_dic.Contains(item));
 }
Example #17
0
 public bool Contains(KeyValuePair <string, object> item)
 {
     return(cacheStruct.Contains(item));
 }
Example #18
0
 /// <summary>
 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
 /// </summary>
 /// <returns>
 /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false.
 /// </returns>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 public bool Contains(KeyValuePair <Symbol, Universe> item)
 {
     return(_universes.Contains(item));
 }
Example #19
0
 public bool Contains(AbstractTransaction tx) => _txPool.Contains(new KeyValuePair <string, AbstractTransaction>(tx.Hash, tx));
        public void Contains_KeyValuePairThrowsNotImplementedException()
        {
            // Arrange
            ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();

            // Act/Assert
            Assert.Throws<NotImplementedException>(() => dictionary.Contains(new KeyValuePair<int, int>(0, 0)));
        }
Example #21
0
 public bool Contains(KeyValuePair <string, IEnumerable <string> > item)
 {
     return(Headers.Contains(item));
 }
 public bool Contains(KeyValuePair <string, object> item)
 {
     return(_inner.Contains(item));
 }
Example #23
0
 public bool Contains(KeyValuePair <TKey, TValue> item) => ConcurrentDictionary.Contains(item);
 public bool Contains(KeyValuePair <Tuple <Type, Type>, IExpresionList> item)
 {
     return(innerDictionary.Contains(item));
 }