public void CheckContainsKeyAndAddUsingASafeConcurrentDictionaryShouldNotThrow() { IDictionary <string, int> dictionary = new SafeConcurrentDictionary <string, int>(); var exception = false; Action <int> action = x => { try { if (!dictionary.ContainsKey("1")) { dictionary.Add("1", 23); } } catch { exception = true; } }; Parallel.For(1, Environment.ProcessorCount, action); exception.Should().BeFalse(); }
public void CheckContainsKeyAndAddUsingASafeConcurrentDictionaryShouldNotThrow() { IDictionary<string, int> dictionary = new SafeConcurrentDictionary<string, int>(); var exception = false; Action<int> action = x => { try { if (!dictionary.ContainsKey("1")) { dictionary.Add("1", 23); } } catch { exception = true; } }; Parallel.For(1, Environment.ProcessorCount, action); exception.Should().Be.False(); }