From 43aa376ed9192b87eb5ebb66bc6a625790325e48 Mon Sep 17 00:00:00 2001 From: nbarbettini Date: Thu, 6 Apr 2017 06:57:26 -0700 Subject: [PATCH 01/12] Add TryAdd and Remove to CollectionExtensions --- .../ref/System.Collections.cs | 3 ++ .../Generic/CollectionExtensions.cs | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/System.Collections/ref/System.Collections.cs b/src/System.Collections/ref/System.Collections.cs index 81db6619e614..feeb5b8632dc 100644 --- a/src/System.Collections/ref/System.Collections.cs +++ b/src/System.Collections/ref/System.Collections.cs @@ -49,6 +49,9 @@ public static class CollectionExtensions public static TValue GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key) { throw null; } public static TValue GetValueOrDefault(this IReadOnlyDictionary dictionary, TKey key, TValue defaultValue) { throw null; } + + public static bool TryAdd(this IDictionary dictionary, TKey key, TValue value) { throw null; } + public static bool Remove(this IDictionary dictionary, TKey key, out TValue value) { throw null; } } public abstract partial class Comparer : System.Collections.Generic.IComparer, System.Collections.IComparer { diff --git a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index e3a5ef2e95a8..82dcb36fa119 100644 --- a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -37,5 +37,43 @@ public static TValue GetValueOrDefault(this IReadOnlyDictionary(this IDictionary dictionary, TKey key, TValue value) + { + if (dictionary == null) + { + throw new ArgumentNullException(nameof(dictionary)); + } + + try + { + dictionary.Add(key, value); + return true; + } + catch (Exception) + { + return false; + } + } + + public static bool Remove(this IDictionary dictionary, TKey key, out TValue value) + { + if (dictionary == null) + { + throw new ArgumentNullException(nameof(dictionary)); + } + + try + { + value = dictionary[key]; + dictionary.Remove(key); + return true; + } + catch (Exception) + { + value = default(TValue); + return false; + } + } } } From 1d0ef3cb158595a51becf36506ac095b1efbb331 Mon Sep 17 00:00:00 2001 From: nbarbettini Date: Fri, 7 Apr 2017 05:39:36 -0700 Subject: [PATCH 02/12] Better implementation of Remove --- .../Collections/Generic/CollectionExtensions.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index 82dcb36fa119..36ed0401c98f 100644 --- a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -63,17 +63,18 @@ public static bool Remove(this IDictionary dictionar throw new ArgumentNullException(nameof(dictionary)); } - try + // Testing purposes + throw new NotImplementedException(); + + value = default(TValue); + + if (dictionary.TryGetValue(key, out var foundValue)) { - value = dictionary[key]; - dictionary.Remove(key); + value = foundValue; return true; } - catch (Exception) - { - value = default(TValue); - return false; - } + + return false; } } } From b6433f628e09c9ab65da0dc22288665ec1333cfa Mon Sep 17 00:00:00 2001 From: nbarbettini Date: Fri, 7 Apr 2017 06:00:30 -0700 Subject: [PATCH 03/12] Add tests --- .../Generic/CollectionExtensionsTests.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 74501974d91a..7381b48fd87f 100644 --- a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -72,5 +72,65 @@ public void GetValueOrDefault_NullIReadOnlyDictionary_ThrowsArgumentNullExceptio Assert.Throws("dictionary", () => dictionary.GetValueOrDefault("key")); Assert.Throws("dictionary", () => dictionary.GetValueOrDefault("key", "value")); } + + [Fact] + public void TryAdd_NullIDictionary_ThrowsArgumentNullException() + { + IDictionary dictionary = null; + Assert.Throws("dictionary", () => dictionary.TryAdd("key", "value")); + } + + [Fact] + public void TryAdd_NullKeyIDictionary_ThrowsArgumenNullException() + { + IDictionary dictionary = new SortedDictionary() { { "key", "value" } }; + Assert.Throws("key", () => dictionary.TryAdd(null, "anotherValue")); + } + + [Fact] + public void TryAdd_KeyDoesntExistInIDictionary_ReturnsTrue() + { + IDictionary dictionary = new SortedDictionary(); + Assert.Equal(true, dictionary.TryAdd("key", "value")); + Assert.Equal("value", dictionary["key"]); + } + + [Fact] + public void TryAdd_KeyExistsInIDictionary_ReturnsFalse() + { + IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; + Assert.Equal(false, dictionary.TryAdd("key", "value2")); + Assert.Equal("value", dictionary["key"]); + } + + [Fact] + public void Remove_NullIDictionary_ThrowsArgumentNullException() + { + IDictionary dictionary = null; + Assert.Throws("dictionary", () => dictionary.Remove("key", out var value)); + } + + [Fact] + public void Remove_NullKeyIDictionary_ThrowsArgumenNullException() + { + IDictionary dictionary = new SortedDictionary() { { "key", "value" } }; + Assert.Throws("key", () => dictionary.Remove(null, out var value)); + } + + [Fact] + public void Remove_KeyExistsInIDictionary_ReturnsTrue() + { + IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; + Assert.Equal(true, dictionary.Remove("key", out var value)); + Assert.Equal("value", value); + } + + [Fact] + public void Remove_KeyDoesntExistInIDictionary_ReturnsFalse() + { + IDictionary dictionary = new SortedDictionary(); + Assert.Equal(false, dictionary.Remove("key", out var value)); + Assert.Equal("value", default(string)); + } } } From 20f23b85b7491b5ab94ad95e3877662be80a866d Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Fri, 7 Apr 2017 13:31:47 -0700 Subject: [PATCH 04/12] Fix bugs and finish tests --- .../Collections/DictionaryExtensions.cs | 20 ------------------- .../Generic/CollectionExtensions.cs | 11 +++------- .../Generic/CollectionExtensionsTests.cs | 2 +- .../tests/System.Collections.Tests.csproj | 2 +- 4 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 src/Common/tests/System/Collections/DictionaryExtensions.cs diff --git a/src/Common/tests/System/Collections/DictionaryExtensions.cs b/src/Common/tests/System/Collections/DictionaryExtensions.cs deleted file mode 100644 index 8840a7ed2273..000000000000 --- a/src/Common/tests/System/Collections/DictionaryExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace System.Collections.Generic -{ - internal static class DictionaryExtensions - { - public static bool TryAdd(this IDictionary dict, TKey key, TValue value) - { - if (!dict.ContainsKey(key)) - { - dict.Add(key, value); - return true; - } - - return false; - } - } -} diff --git a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index 36ed0401c98f..3c3b3e55075a 100644 --- a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -45,15 +45,13 @@ public static bool TryAdd(this IDictionary dictionar throw new ArgumentNullException(nameof(dictionary)); } - try + if (!dictionary.ContainsKey(key)) { dictionary.Add(key, value); return true; } - catch (Exception) - { - return false; - } + + return false; } public static bool Remove(this IDictionary dictionary, TKey key, out TValue value) @@ -63,9 +61,6 @@ public static bool Remove(this IDictionary dictionar throw new ArgumentNullException(nameof(dictionary)); } - // Testing purposes - throw new NotImplementedException(); - value = default(TValue); if (dictionary.TryGetValue(key, out var foundValue)) diff --git a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 7381b48fd87f..817ded05626b 100644 --- a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -130,7 +130,7 @@ public void Remove_KeyDoesntExistInIDictionary_ReturnsFalse() { IDictionary dictionary = new SortedDictionary(); Assert.Equal(false, dictionary.Remove("key", out var value)); - Assert.Equal("value", default(string)); + Assert.Equal(default(string), value); } } } diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index d820abc79a0d..6af6823cda71 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -71,7 +71,7 @@ Common\System\ObjectCloner.cs - + Common\System\Collections\DictionaryExtensions.cs From 2e1c830643ead4e0e741875dc3a918292a50ef0a Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Fri, 7 Apr 2017 14:00:06 -0700 Subject: [PATCH 05/12] Remove references to DictionaryExtensions --- .../Performance/System.Collections.Performance.Tests.csproj | 3 --- src/System.Collections/tests/System.Collections.Tests.csproj | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj b/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj index f860ba121d05..929fd9e11a23 100644 --- a/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj +++ b/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj @@ -9,9 +9,6 @@ - - Common\System\Collections\DictionaryExtensions.cs - diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index 6af6823cda71..ad7067d2a20b 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -71,9 +71,6 @@ Common\System\ObjectCloner.cs - - Common\System\Collections\DictionaryExtensions.cs - From cdccbbb93bdbdab836afb0b7a0ea19d678fb759b Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Fri, 7 Apr 2017 17:43:40 -0700 Subject: [PATCH 06/12] Remove should actually remove items --- .../src/System/Collections/Generic/CollectionExtensions.cs | 1 + .../tests/Generic/CollectionExtensionsTests.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index 3c3b3e55075a..c95702a6218a 100644 --- a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -66,6 +66,7 @@ public static bool Remove(this IDictionary dictionar if (dictionary.TryGetValue(key, out var foundValue)) { value = foundValue; + dictionary.Remove(key); return true; } diff --git a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 817ded05626b..1f20842a72bd 100644 --- a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -123,6 +123,7 @@ public void Remove_KeyExistsInIDictionary_ReturnsTrue() IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; Assert.Equal(true, dictionary.Remove("key", out var value)); Assert.Equal("value", value); + Assert.Throws(() => dictionary["key"]); } [Fact] From 4f2a7f114ca249ac26f3d1592446fe9fba80627d Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Fri, 7 Apr 2017 18:21:36 -0700 Subject: [PATCH 07/12] Only include on netfx builds --- src/System.Collections/tests/System.Collections.Tests.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index ad7067d2a20b..11b2d1d9ab26 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -71,6 +71,9 @@ Common\System\ObjectCloner.cs + + src\System\Collections\Generic\CollectionExtensions.cs + From 57bad2f840a43e343a68cd23fa09cf3bf240108f Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Sat, 8 Apr 2017 18:08:24 -0700 Subject: [PATCH 08/12] Clean up tests --- .../tests/Generic/CollectionExtensionsTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 1f20842a72bd..c6ab9842e0a2 100644 --- a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -81,17 +81,17 @@ public void TryAdd_NullIDictionary_ThrowsArgumentNullException() } [Fact] - public void TryAdd_NullKeyIDictionary_ThrowsArgumenNullException() + public void TryAdd_NullKeyIDictionary_ThrowsArgumentNullException() { - IDictionary dictionary = new SortedDictionary() { { "key", "value" } }; - Assert.Throws("key", () => dictionary.TryAdd(null, "anotherValue")); + IDictionary dictionary = new SortedDictionary(); + Assert.Throws("key", () => dictionary.TryAdd(null, "value")); } [Fact] public void TryAdd_KeyDoesntExistInIDictionary_ReturnsTrue() { IDictionary dictionary = new SortedDictionary(); - Assert.Equal(true, dictionary.TryAdd("key", "value")); + Assert.True(dictionary.TryAdd("key", "value")); Assert.Equal("value", dictionary["key"]); } @@ -99,7 +99,7 @@ public void TryAdd_KeyDoesntExistInIDictionary_ReturnsTrue() public void TryAdd_KeyExistsInIDictionary_ReturnsFalse() { IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; - Assert.Equal(false, dictionary.TryAdd("key", "value2")); + Assert.False(dictionary.TryAdd("key", "value2")); Assert.Equal("value", dictionary["key"]); } @@ -111,9 +111,9 @@ public void Remove_NullIDictionary_ThrowsArgumentNullException() } [Fact] - public void Remove_NullKeyIDictionary_ThrowsArgumenNullException() + public void Remove_NullKeyIDictionary_ThrowsArgumentNullException() { - IDictionary dictionary = new SortedDictionary() { { "key", "value" } }; + IDictionary dictionary = new SortedDictionary(); Assert.Throws("key", () => dictionary.Remove(null, out var value)); } @@ -121,7 +121,7 @@ public void Remove_NullKeyIDictionary_ThrowsArgumenNullException() public void Remove_KeyExistsInIDictionary_ReturnsTrue() { IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; - Assert.Equal(true, dictionary.Remove("key", out var value)); + Assert.True(dictionary.Remove("key", out var value)); Assert.Equal("value", value); Assert.Throws(() => dictionary["key"]); } @@ -130,7 +130,7 @@ public void Remove_KeyExistsInIDictionary_ReturnsTrue() public void Remove_KeyDoesntExistInIDictionary_ReturnsFalse() { IDictionary dictionary = new SortedDictionary(); - Assert.Equal(false, dictionary.Remove("key", out var value)); + Assert.False(dictionary.Remove("key", out var value)); Assert.Equal(default(string), value); } } From 34d27d8e6eb42315be49e0a9b07a969192cc78ec Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Sat, 8 Apr 2017 18:10:44 -0700 Subject: [PATCH 09/12] Improve per PR feedback --- .../src/System/Collections/Generic/CollectionExtensions.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index c95702a6218a..4a4078d565c0 100644 --- a/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -61,15 +61,13 @@ public static bool Remove(this IDictionary dictionar throw new ArgumentNullException(nameof(dictionary)); } - value = default(TValue); - - if (dictionary.TryGetValue(key, out var foundValue)) + if (dictionary.TryGetValue(key, out value)) { - value = foundValue; dictionary.Remove(key); return true; } + value = default(TValue); return false; } } From b6f9115629ceff119579a34e7e4296c5315a0a35 Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Sat, 8 Apr 2017 18:35:06 -0700 Subject: [PATCH 10/12] Revert changes --- .../Collections/DictionaryExtensions.cs | 20 +++++++++++++++++++ ...ystem.Collections.Performance.Tests.csproj | 3 +++ .../tests/System.Collections.Tests.csproj | 6 +++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/Common/tests/System/Collections/DictionaryExtensions.cs diff --git a/src/Common/tests/System/Collections/DictionaryExtensions.cs b/src/Common/tests/System/Collections/DictionaryExtensions.cs new file mode 100644 index 000000000000..8840a7ed2273 --- /dev/null +++ b/src/Common/tests/System/Collections/DictionaryExtensions.cs @@ -0,0 +1,20 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Collections.Generic +{ + internal static class DictionaryExtensions + { + public static bool TryAdd(this IDictionary dict, TKey key, TValue value) + { + if (!dict.ContainsKey(key)) + { + dict.Add(key, value); + return true; + } + + return false; + } + } +} diff --git a/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj b/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj index 929fd9e11a23..f860ba121d05 100644 --- a/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj +++ b/src/System.Collections/tests/Performance/System.Collections.Performance.Tests.csproj @@ -9,6 +9,9 @@ + + Common\System\Collections\DictionaryExtensions.cs + diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index 11b2d1d9ab26..87e0a7029be7 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -71,8 +71,8 @@ Common\System\ObjectCloner.cs - - src\System\Collections\Generic\CollectionExtensions.cs + + Common\System\Collections\DictionaryExtensions.cs @@ -161,4 +161,4 @@ - \ No newline at end of file + From e5f005b2a939d039afed3d2e98bc9f963e1d62ce Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Sun, 16 Apr 2017 12:47:08 -0700 Subject: [PATCH 11/12] Omit DictionaryExtensions from netcoreapp and uat --- .../tests/System.Collections.Concurrent.Tests.csproj | 2 +- .../tests/System.Collections.Immutable.Tests.csproj | 2 +- src/System.Collections/tests/System.Collections.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj b/src/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj index 88f05125e65c..5d3c9a88962d 100644 --- a/src/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj +++ b/src/System.Collections.Concurrent/tests/System.Collections.Concurrent.Tests.csproj @@ -10,7 +10,7 @@ - + Common\System\Collections\DictionaryExtensions.cs diff --git a/src/System.Collections.Immutable/tests/System.Collections.Immutable.Tests.csproj b/src/System.Collections.Immutable/tests/System.Collections.Immutable.Tests.csproj index 01a3daf0d60d..0562168caad7 100644 --- a/src/System.Collections.Immutable/tests/System.Collections.Immutable.Tests.csproj +++ b/src/System.Collections.Immutable/tests/System.Collections.Immutable.Tests.csproj @@ -14,7 +14,7 @@ - + Common\System\Collections\DictionaryExtensions.cs diff --git a/src/System.Collections/tests/System.Collections.Tests.csproj b/src/System.Collections/tests/System.Collections.Tests.csproj index 87e0a7029be7..1a3a94b83614 100644 --- a/src/System.Collections/tests/System.Collections.Tests.csproj +++ b/src/System.Collections/tests/System.Collections.Tests.csproj @@ -71,7 +71,7 @@ Common\System\ObjectCloner.cs - + Common\System\Collections\DictionaryExtensions.cs From 02cfc7f5bfb4f0a5da4dc43637cd6665ece2b5e9 Mon Sep 17 00:00:00 2001 From: Nate Barbettini Date: Sun, 16 Apr 2017 15:08:45 -0700 Subject: [PATCH 12/12] Harden Remove tests per PR feedback --- .../tests/Generic/CollectionExtensionsTests.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs index c6ab9842e0a2..13d5f7aa56e0 100644 --- a/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -107,14 +107,18 @@ public void TryAdd_KeyExistsInIDictionary_ReturnsFalse() public void Remove_NullIDictionary_ThrowsArgumentNullException() { IDictionary dictionary = null; - Assert.Throws("dictionary", () => dictionary.Remove("key", out var value)); + string value = null; + Assert.Throws("dictionary", () => dictionary.Remove("key", out value)); + Assert.Null(value); } [Fact] public void Remove_NullKeyIDictionary_ThrowsArgumentNullException() { IDictionary dictionary = new SortedDictionary(); - Assert.Throws("key", () => dictionary.Remove(null, out var value)); + string value = null; + Assert.Throws("key", () => dictionary.Remove(null, out value)); + Assert.Null(value); } [Fact]