Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Expose deconstruct api and add tests #17656

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace System.Collections.Tests
/// Contains tests that ensure the correctness of any class that implements the generic
/// IDictionary interface
/// </summary>
public abstract class IDictionary_Generic_Tests<TKey, TValue> : ICollection_Generic_Tests<KeyValuePair<TKey, TValue>>
public abstract partial class IDictionary_Generic_Tests<TKey, TValue> : ICollection_Generic_Tests<KeyValuePair<TKey, TValue>>
{
#region IDictionary<TKey, TValue> Helper Methods

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

using System.Collections.Generic;
using Xunit;

namespace System.Collections.Tests
{
/// <summary>
/// Contains tests that ensure the correctness of any class that implements the generic
/// IDictionary interface
/// </summary>
public abstract partial class IDictionary_Generic_Tests<TKey, TValue> : ICollection_Generic_Tests<KeyValuePair<TKey, TValue>>
{
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
public void KeyValuePair_Deconstruct(int size)
{
IDictionary<TKey, TValue> dictionary = GenericIDictionaryFactory(size);
Assert.All(dictionary, (entry) => {
TKey key;
TValue value;
entry.Deconstruct(out key, out value);
Assert.Equal(entry.Key, key);
Assert.Equal(entry.Value, value);

key = default(TKey);
value = default(TValue);
(key, value) = entry;
Assert.Equal(entry.Key, key);
Assert.Equal(entry.Value, value);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace System.Collections.Tests
/// Contains tests that ensure the correctness of any class that implements the nongeneric
/// IDictionary interface
/// </summary>
public abstract class IDictionary_NonGeneric_Tests : ICollection_NonGeneric_Tests
public abstract partial class IDictionary_NonGeneric_Tests : ICollection_NonGeneric_Tests
{
#region IDictionary Helper Methods

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

using Xunit;

namespace System.Collections.Tests
{
/// <summary>
/// Contains tests that ensure the correctness of any class that implements the nongeneric
/// IDictionary interface
/// </summary>
public abstract partial class IDictionary_NonGeneric_Tests : ICollection_NonGeneric_Tests
{
[Theory]
[MemberData(nameof(ValidCollectionSizes))]
public void DictionaryEntry_Deconstruct(int size)
{
IDictionary dictionary = NonGenericIDictionaryFactory(size);

// Assert.All is only supported for generic collections.
foreach (DictionaryEntry entry in dictionary)
{
object key;
object value;
entry.Deconstruct(out key, out value);
Assert.Equal(key, entry.Key);
Assert.Equal(value, entry.Value);

key = null;
value = null;
(key, value) = entry;
Assert.Equal(key, entry.Key);
Assert.Equal(value, entry.Value);
}
}
}
}
6 changes: 6 additions & 0 deletions src/System.Collections/tests/System.Collections.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
<Compile Include="$(CommonTestPath)\System\Collections\IDictionary.NonGeneric.Tests.cs">
<Link>Common\System\Collections\IDictionary.NonGeneric.Tests.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Collections\IDictionary.NonGeneric.Tests.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'">
<Link>Common\System\Collections\IDictionary.NonGeneric.Tests.netcoreapp.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Collections\IDictionary.Generic.Tests.cs">
<Link>Common\System\Collections\IDictionary.Generic.Tests.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Collections\IDictionary.Generic.Tests.netcoreapp.cs" Condition="'$(TargetGroup)' == 'netcoreapp'">
<Link>Common\System\Collections\IDictionary.Generic.Tests.netcoreapp.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Collections\IEnumerable.NonGeneric.Tests.cs">
<Link>Common\System\Collections\IEnumerable.NonGeneric.Tests.cs</Link>
</Compile>
Expand Down
4 changes: 4 additions & 0 deletions src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,8 @@ namespace System.Collections
public partial struct DictionaryEntry
{
public DictionaryEntry(object key, object value) { throw null; }
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public void Deconstruct(out object key, out object value) { throw null; }
public object Key { get { throw null; } set { } }
public object Value { get { throw null; } set { } }
}
Expand Down Expand Up @@ -3810,6 +3812,8 @@ public static class KeyValuePair
public partial struct KeyValuePair<TKey, TValue>
{
public KeyValuePair(TKey key, TValue value) { throw null; }
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public void Deconstruct(out TKey key, out TValue value) { throw null; }
public TKey Key { get { throw null; } }
public TValue Value { get { throw null; } }
public override string ToString() { throw null; }
Expand Down