public void AddOrUpdateSafeAddsValuePairIfDictionaryDoesNotContainKey() { const string expected = "foo"; var dictionary = new ConcurrentDictionary <int, Lazy <string> >(); dictionary.AddOrUpdateSafe(1, k => expected, (k, v) => string.Empty); Lazy <string> value; Assert.IsTrue(dictionary.TryGetValue(1, out value)); Assert.AreEqual(expected, value.Value); }
public void AddOrUpdateSafeUpdatesValueIfDictionaryDoesContainKey() { const string expected = "bar"; var dictionary = new ConcurrentDictionary <int, Lazy <string> >(); dictionary[1] = new Lazy <string>(() => "foo"); dictionary.AddOrUpdateSafe(1, k => string.Empty, (k, v) => expected); Lazy <string> value; Assert.IsTrue(dictionary.TryGetValue(1, out value)); Assert.AreEqual(expected, value.Value); }
public void RegisterTypeName(string typeName, Type type) { _customTypes.AddOrUpdateSafe(typeName, s => type, (s, type1) => type); }