From 115ef11b3bda5ca8008670c933cee309ec696025 Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Tue, 10 Nov 2020 20:58:01 -0800 Subject: [PATCH] Adding Unit Test --- .../tests/Configurations.props | 7 ++++ .../tests/HashCodeSeedInitializerTests.cs | 39 +++++++++++++++++++ .../tests/Microsoft.Bcl.HashCode.Tests.csproj | 9 +++++ 3 files changed, 55 insertions(+) create mode 100644 src/Microsoft.Bcl.HashCode/tests/Configurations.props create mode 100644 src/Microsoft.Bcl.HashCode/tests/HashCodeSeedInitializerTests.cs create mode 100644 src/Microsoft.Bcl.HashCode/tests/Microsoft.Bcl.HashCode.Tests.csproj diff --git a/src/Microsoft.Bcl.HashCode/tests/Configurations.props b/src/Microsoft.Bcl.HashCode/tests/Configurations.props new file mode 100644 index 000000000000..c4ab5ac7ca7b --- /dev/null +++ b/src/Microsoft.Bcl.HashCode/tests/Configurations.props @@ -0,0 +1,7 @@ + + + + netfx; + + + diff --git a/src/Microsoft.Bcl.HashCode/tests/HashCodeSeedInitializerTests.cs b/src/Microsoft.Bcl.HashCode/tests/HashCodeSeedInitializerTests.cs new file mode 100644 index 000000000000..d9e5f32cab72 --- /dev/null +++ b/src/Microsoft.Bcl.HashCode/tests/HashCodeSeedInitializerTests.cs @@ -0,0 +1,39 @@ +// 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 Microsoft.DotNet.RemoteExecutor; +using System; +using System.Reflection; +using Xunit; + +namespace Microsoft.Bcl.HashCode.Tests +{ + public class HashCodeSeedInitializerTests + { + [Fact] + public void EnsureSeedReturnsDifferentValuesTest() + { + var executor1 = RemoteExecutor.Invoke(GetHashCodeSeed, new RemoteInvokeOptions() { CheckExitCode = false }); + + int FirstSeed = executor1.ExitCode; + executor1.Dispose(); + + var executor2 = RemoteExecutor.Invoke(GetHashCodeSeed, new RemoteInvokeOptions() { CheckExitCode = false }); + + int SecondSeed = executor2.ExitCode; + executor2.Dispose(); + + Assert.NotEqual(FirstSeed, SecondSeed); + + int GetHashCodeSeed() + { + var seed1Field = typeof(System.HashCode).GetField("s_seed", BindingFlags.NonPublic | BindingFlags.Static); + int returnCode = (int)((uint)seed1Field.GetValue(null)); + return returnCode; + }; + } + + } + +} diff --git a/src/Microsoft.Bcl.HashCode/tests/Microsoft.Bcl.HashCode.Tests.csproj b/src/Microsoft.Bcl.HashCode/tests/Microsoft.Bcl.HashCode.Tests.csproj new file mode 100644 index 000000000000..3149bc7bc997 --- /dev/null +++ b/src/Microsoft.Bcl.HashCode/tests/Microsoft.Bcl.HashCode.Tests.csproj @@ -0,0 +1,9 @@ + + + netfx-Debug;netfx-Release + true + + + + +