From 198f75621dbe792035d51e2a7f10bc18e9cbb11b Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Wed, 1 Mar 2017 23:37:07 +0700 Subject: [PATCH 1/2] Expose and test KeyValuePair.Create --- src/System.Runtime/ref/System.Runtime.cs | 4 ++ .../tests/System.Runtime.Tests.csproj | 8 ++-- .../Collections/Generic/KeyValuePairTests.cs | 47 +++++++++++++++++++ .../Generic/KeyValuePairTests.netcoreapp.cs | 19 ++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.cs create mode 100644 src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.netcoreapp.cs diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index b604de48530a..904e5118e170 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -3790,6 +3790,10 @@ public KeyNotFoundException(string message) { } public KeyNotFoundException(string message, System.Exception innerException) { } protected KeyNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } } + public static class KeyValuePair + { + public static KeyValuePair Create(TKey key, TValue value) { throw null; } + } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public partial struct KeyValuePair { diff --git a/src/System.Runtime/tests/System.Runtime.Tests.csproj b/src/System.Runtime/tests/System.Runtime.Tests.csproj index d3f4fef5f48b..b1f0583a144e 100644 --- a/src/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/System.Runtime/tests/System.Runtime.Tests.csproj @@ -12,10 +12,10 @@ - + - - + + @@ -51,6 +51,7 @@ + @@ -127,6 +128,7 @@ + diff --git a/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.cs b/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.cs new file mode 100644 index 000000000000..c4bcf03576be --- /dev/null +++ b/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.cs @@ -0,0 +1,47 @@ +// 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.Generic.Tests +{ + public partial class KeyValuePairTests + { + [Fact] + public void Ctor_KeyValue_ReturnsExpected() + { + var keyValuePair = new KeyValuePair(1, "2"); + Assert.Equal(1, keyValuePair.Key); + Assert.Equal("2", keyValuePair.Value); + } + + [Fact] + public void ToString_NonNullKeyNonNullValue_ReturnsExpected() + { + var keyValuePair = new KeyValuePair("1", "2"); + Assert.Equal("[1, 2]", keyValuePair.ToString()); + } + + [Fact] + public void ToString_NonNullKeyNullValue_ReturnsExpected() + { + var keyValuePair = new KeyValuePair("1", null); + Assert.Equal("[1, ]", keyValuePair.ToString()); + } + + [Fact] + public void ToString_NullKeyNonNullValue_ReturnsExpected() + { + var keyValuePair = new KeyValuePair(null, "1"); + Assert.Equal("[, 1]", keyValuePair.ToString()); + } + + [Fact] + public void ToString_NullKeyNullValue_ReturnsExpected() + { + var keyValuePair = new KeyValuePair(null, null); + Assert.Equal("[, ]", keyValuePair.ToString()); + } + } +} diff --git a/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.netcoreapp.cs b/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.netcoreapp.cs new file mode 100644 index 000000000000..3b84d0190e84 --- /dev/null +++ b/src/System.Runtime/tests/System/Collections/Generic/KeyValuePairTests.netcoreapp.cs @@ -0,0 +1,19 @@ +// 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.Generic.Tests +{ + public partial class KeyValuePairTests + { + [Fact] + public void Create_ReturnsExpected() + { + KeyValuePair keyValuePair = KeyValuePair.Create(1, "2"); + Assert.Equal(1, keyValuePair.Key); + Assert.Equal("2", keyValuePair.Value); + } + } +} From f940485e0567a83e9e26a199bdd815db59f513f9 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Thu, 2 Mar 2017 09:18:28 +0700 Subject: [PATCH 2/2] Update API baseline compat --- src/System.Runtime/src/ApiCompatBaseline.uapaot.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt b/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt index 7740dd04bdcc..f885f2a349de 100644 --- a/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt +++ b/src/System.Runtime/src/ApiCompatBaseline.uapaot.txt @@ -143,6 +143,7 @@ MembersMustExist : Member 'System.WeakReference..ctor(System.Runtime.Serializati MembersMustExist : Member 'System.WeakReference.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract. CannotRemoveBaseTypeOrInterface : Type 'System.WeakReference' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract. MembersMustExist : Member 'System.WeakReference.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract. +TypesMustExist : Type 'System.Collections.Generic.KeyValuePair' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'System.ComponentModel.DefaultValueAttribute..ctor(System.SByte)' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'System.ComponentModel.DefaultValueAttribute..ctor(System.UInt16)' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'System.ComponentModel.DefaultValueAttribute..ctor(System.UInt32)' does not exist in the implementation but it does exist in the contract. @@ -240,4 +241,4 @@ CannotRemoveBaseTypeOrInterface : Type 'System.Threading.Tasks.Task' does not im MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose()' does not exist in the implementation but it does exist in the contract. MembersMustExist : Member 'System.Threading.Tasks.Task.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract. CannotRemoveBaseTypeOrInterface : Type 'System.Threading.Tasks.Task' does not implement interface 'System.IDisposable' in the implementation but it does in the contract. -Total Issues: 241 +Total Issues: 242