use new OperatingSystem APIs in test projects that target NetCoreAppCurrent only...
authorAdam Sitnik <adam.sitnik@gmail.com>
Mon, 10 Aug 2020 15:50:42 +0000 (17:50 +0200)
committerGitHub <noreply@github.com>
Mon, 10 Aug 2020 15:50:42 +0000 (17:50 +0200)
* use new OperatingSystem APIs in test projects that target NetCoreAppCurrent only

* use `||` instead of `|`

74 files changed:
src/libraries/Common/tests/System/Net/SslProtocolSupport.cs
src/libraries/System.Console/tests/ManualTests/ManualTests.cs
src/libraries/System.Console/tests/WindowAndCursorProps.cs
src/libraries/System.Diagnostics.Process/tests/ProcessStandardConsoleTests.cs
src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.Unix.cs
src/libraries/System.Diagnostics.Process/tests/ProcessThreadTests.cs
src/libraries/System.Globalization.Extensions/tests/IdnMapping/IdnMappingGetAsciiTests.cs
src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs
src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs
src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs
src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs
src/libraries/System.IO.FileSystem/tests/Directory/Delete.cs
src/libraries/System.IO.FileSystem/tests/Directory/Exists.cs
src/libraries/System.IO.FileSystem/tests/Directory/GetDirectories.cs
src/libraries/System.IO.FileSystem/tests/Directory/SetCurrentDirectory.cs
src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Exists.cs
src/libraries/System.IO.FileSystem/tests/File/Delete.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLines.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllLinesAsync.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllText.cs
src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllTextAsync.cs
src/libraries/System.IO.FileSystem/tests/FileInfo/Length.cs
src/libraries/System.IO.FileSystem/tests/FileStream/SafeFileHandle.cs
src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs
src/libraries/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.delete.cs
src/libraries/System.IO.FileSystem/tests/PortedCommon/IOInputs.cs
src/libraries/System.IO.FileSystem/tests/PortedCommon/ReparsePointUtilities.cs
src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/IsoStorageTest.cs
src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs
src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewStream.Tests.cs
src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.Simple.cs
src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.Specific.cs
src/libraries/System.IO.Pipes/tests/PipeTest.Read.cs
src/libraries/System.IO.Pipes/tests/PipeTest.Write.cs
src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPGlobalPropertiesTest.cs
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamAlpnTests.cs
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamEKUTest.cs
src/libraries/System.Net.Security/tests/FunctionalTests/TestConfiguration.cs
src/libraries/System.Net.Security/tests/FunctionalTests/TransportContextTest.cs
src/libraries/System.Net.Security/tests/StressTests/SslStress/SslServerBase.cs
src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs
src/libraries/System.Private.Xml/tests/Misc/XmlUrlResolverTests.cs
src/libraries/System.Runtime.Extensions/tests/System/Environment.GetEnvironmentVariable.cs
src/libraries/System.Runtime.Extensions/tests/System/Environment.SetEnvironmentVariable.cs
src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/OffsetOfTests.cs
src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Oid.cs
src/libraries/System.Security.Cryptography.Pkcs/tests/CertLoader.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/Cert.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/ChainTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionImportTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/CtorTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/DynamicChainTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/FindTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxFormatTests.SingleCertGenerator.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxFormatTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxFormatTests_Collection.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxFormatTests_SingleCert.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/RevocationTests/DynamicRevocationTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/X500DistinguishedNameEncodingTests.cs

index 78ae108..e6ac188 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 
 namespace System.Net.Test.Common
index 43688d7..9bbec55 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Xunit;
 
@@ -96,7 +95,7 @@ namespace System
             yield return MkConsoleKeyInfo('\x01', ConsoleKey.A, ConsoleModifiers.Control | ConsoleModifiers.Alt);
             yield return MkConsoleKeyInfo('\r', ConsoleKey.Enter, (ConsoleModifiers)0);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 // windows will report '\n' as 'Ctrl+Enter', which is typically not picked up by Unix terminals
                 yield return MkConsoleKeyInfo('\n', ConsoleKey.Enter, ConsoleModifiers.Control);
index 0e63417..aed9ef0 100644 (file)
@@ -4,7 +4,6 @@
 using System;
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 using Microsoft.DotNet.RemoteExecutor;
 using Microsoft.DotNet.XUnitExtensions;
 using Xunit;
@@ -323,7 +322,7 @@ public class WindowAndCursorProps
     [OuterLoop] // clears the screen, not very inner-loop friendly
     public static void Clear_Invoke_Success()
     {
-        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (!Console.IsInputRedirected && !Console.IsOutputRedirected))
+        if (!OperatingSystem.IsWindows() || (!Console.IsInputRedirected && !Console.IsOutputRedirected))
         {
             // Nothing to verify; just run the code.
             Console.Clear();
@@ -341,7 +340,7 @@ public class WindowAndCursorProps
     [PlatformSpecific(~TestPlatforms.Browser)]
     public static void SetCursorPosition_Invoke_Success()
     {
-        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (!Console.IsInputRedirected && !Console.IsOutputRedirected))
+        if (!OperatingSystem.IsWindows() || (!Console.IsInputRedirected && !Console.IsOutputRedirected))
         {
             int origLeft = Console.CursorLeft;
             int origTop = Console.CursorTop;
@@ -383,7 +382,7 @@ public class WindowAndCursorProps
             Assert.Equal(origTop, Console.CursorTop);
             Assert.Equal(origTuple, Console.GetCursorPosition());
         }
-        else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+        else if (!OperatingSystem.IsWindows())
         {
             Assert.Equal(0, Console.CursorLeft);
             Assert.Equal(0, Console.CursorTop);
@@ -405,7 +404,7 @@ public class WindowAndCursorProps
             Console.CursorLeft = origLeft;
             Assert.Equal(origLeft, Console.CursorLeft);
         }
-        else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+        else if (!OperatingSystem.IsWindows())
         {
             Assert.Equal(0, Console.CursorLeft);
         }
@@ -448,7 +447,7 @@ public class WindowAndCursorProps
             Console.CursorTop = origTop;
             Assert.Equal(origTop, Console.CursorTop);
         }
-        else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+        else if (!OperatingSystem.IsWindows())
         {
             Assert.Equal(0, Console.CursorTop);
         }
index 6e9bd49..dd41c0e 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Text;
 using Microsoft.DotNet.RemoteExecutor;
 using Xunit;
@@ -32,7 +31,7 @@ namespace System.Diagnostics.Tests
                 Assert.True(p.WaitForExit(WaitInMS));
             };
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (!OperatingSystem.IsWindows())
             {
                 run(Encoding.UTF8.CodePage);
                 return;
index ced27b8..3d946ad 100644 (file)
@@ -57,7 +57,7 @@ namespace System.Diagnostics.Tests
             environment.Add("NewKey2", "NewValue2");
             Assert.True(environment.ContainsKey("NewKey"));
 
-            Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.ContainsKey("newkey"));
+            Assert.Equal(OperatingSystem.IsWindows(), environment.ContainsKey("newkey"));
             Assert.False(environment.ContainsKey("NewKey99"));
 
             //Iterating
@@ -93,7 +93,7 @@ namespace System.Diagnostics.Tests
 
             //Contains
             Assert.True(environment.Contains(new KeyValuePair<string, string>("NewKey", "NewValue")));
-            Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair<string, string>("nEwKeY", "NewValue")));
+            Assert.Equal(OperatingSystem.IsWindows(), environment.Contains(new KeyValuePair<string, string>("nEwKeY", "NewValue")));
             Assert.False(environment.Contains(new KeyValuePair<string, string>("NewKey99", "NewValue99")));
 
             //Exception not thrown with invalid key
@@ -110,7 +110,7 @@ namespace System.Diagnostics.Tests
             Assert.True(environment.TryGetValue("NewKey", out stringout));
             Assert.Equal("NewValue", stringout);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.True(environment.TryGetValue("NeWkEy", out stringout));
                 Assert.Equal("NewValue", stringout);
@@ -144,7 +144,7 @@ namespace System.Diagnostics.Tests
             Assert.Throws<KeyNotFoundException>(() => environment["1bB"]);
 
             Assert.True(environment.Contains(new KeyValuePair<string, string>("NewKey2", "NewValue2OverriddenAgain")));
-            Assert.Equal(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), environment.Contains(new KeyValuePair<string, string>("NEWKeY2", "NewValue2OverriddenAgain")));
+            Assert.Equal(OperatingSystem.IsWindows(), environment.Contains(new KeyValuePair<string, string>("NEWKeY2", "NewValue2OverriddenAgain")));
 
             Assert.False(environment.Contains(new KeyValuePair<string, string>("NewKey2", "newvalue2Overriddenagain")));
             Assert.False(environment.Contains(new KeyValuePair<string, string>("newkey2", "newvalue2Overriddenagain")));
index 6aca35f..9097dd7 100644 (file)
@@ -108,7 +108,7 @@ namespace System.Diagnostics.Tests
         [OuterLoop]
         public void ProcessStart_UseShellExecute_OnUnix_OpenMissingFile_DoesNotThrow()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
+            if (OperatingSystem.IsLinux() &&
                 s_allowedProgramsToRun.FirstOrDefault(program => IsProgramInstalled(program)) == null)
             {
                 return;
@@ -139,12 +139,12 @@ namespace System.Diagnostics.Tests
                 File.WriteAllText(fileToOpen, $"{nameof(ProcessStart_UseShellExecute_OnUnix_SuccessWhenProgramInstalled)}");
             }
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || programToOpen != null)
+            if (OperatingSystem.IsMacOS() || programToOpen != null)
             {
                 using (var px = Process.Start(new ProcessStartInfo { UseShellExecute = true, FileName = fileToOpen }))
                 {
                     Assert.NotNull(px);
-                    if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) // on OSX, process name is dotnet for some reason. Refer to https://github.com/dotnet/runtime/issues/23525
+                    if (!OperatingSystem.IsMacOS()) // on OSX, process name is dotnet for some reason. Refer to https://github.com/dotnet/runtime/issues/23525
                     {
                         Assert.Equal(programToOpen, px.ProcessName);
                     }
@@ -558,7 +558,7 @@ namespace System.Diagnostics.Tests
             // If this test runs as the user, we expect to be able to match the user groups exactly.
             // Except on OSX, where getgrouplist may return a list of groups truncated to NGROUPS_MAX.
             bool checkGroupsExact = userId == geteuid().ToString() &&
-                                    !RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+                                    !OperatingSystem.IsMacOS();
 
             // Start as username
             var invokeOptions = new RemoteInvokeOptions();
@@ -600,7 +600,7 @@ namespace System.Diagnostics.Tests
 
                 // On systems with a low value of NGROUPS_MAX (e.g 16 on OSX), the groups may be truncated.
                 // On Linux NGROUPS_MAX is 65536, so we expect to see every group.
-                bool checkGroupsExact = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
+                bool checkGroupsExact = OperatingSystem.IsLinux();
 
                 // Start as username
                 var invokeOptions = new RemoteInvokeOptions();
index ca9a3f6..fa6503b 100644 (file)
@@ -8,7 +8,6 @@ using System.IO;
 using System.IO.Pipes;
 using System.Linq;
 using System.Net;
-using System.Runtime.InteropServices;
 using System.Security;
 using System.Text;
 using System.Threading;
@@ -52,7 +51,7 @@ namespace System.Diagnostics.Tests
 
         private void AssertNonZeroWindowsZeroUnix(long value)
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.NotEqual(0, value);
             }
@@ -64,7 +63,7 @@ namespace System.Diagnostics.Tests
 
         private void AssertNonZeroAllZeroDarwin(long value)
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 Assert.Equal(0, value);
             }
@@ -422,7 +421,7 @@ namespace System.Diagnostics.Tests
 
             Assert.NotEqual(Environment.ProcessId, _process.Id);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.Equal(_process.Id, Interop.GetProcessId(_process.SafeHandle));
             }
@@ -517,14 +516,14 @@ namespace System.Diagnostics.Tests
                 Assert.InRange((long)p.MinWorkingSet, 0, long.MaxValue);
             }
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) {
+            if (OperatingSystem.IsMacOS() || OperatingSystem.IsFreeBSD()) {
                 return; // doesn't support getting/setting working set for other processes
             }
 
             long curValue = (long)_process.MaxWorkingSet;
             Assert.InRange(curValue, 0, long.MaxValue);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 try
                 {
@@ -572,14 +571,14 @@ namespace System.Diagnostics.Tests
                 Assert.InRange((long)p.MinWorkingSet, 0, long.MaxValue);
             }
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) {
+            if (OperatingSystem.IsMacOS() || OperatingSystem.IsFreeBSD()) {
                 return; // doesn't support getting/setting working set for other processes
             }
 
             long curValue = (long)_process.MinWorkingSet;
             Assert.InRange(curValue, 0, long.MaxValue);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 try
                 {
@@ -758,7 +757,7 @@ namespace System.Diagnostics.Tests
         {
             CreateDefaultProcess();
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 // resident memory can be 0 on OSX.
                 Assert.InRange(_process.WorkingSet64, 0, long.MaxValue);
@@ -1815,7 +1814,7 @@ namespace System.Diagnostics.Tests
         {
             CreateDefaultProcess();
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 // resident memory can be 0 on OSX.
 #pragma warning disable 0618
index b6bd36a..2a0f26c 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.ComponentModel;
-using System.Runtime.InteropServices;
 using System.Threading;
 using Microsoft.DotNet.RemoteExecutor;
 using Xunit;
@@ -20,7 +19,7 @@ namespace System.Diagnostics.Tests
             ProcessThread thread = _process.Threads[0];
             ThreadPriorityLevel level = ThreadPriorityLevel.Normal;
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 Assert.Throws<PlatformNotSupportedException>(() => thread.PriorityLevel);
             }
index 57e0ec5..fe648a0 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.ComponentModel;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Linq;
 using Microsoft.DotNet.RemoteExecutor;
@@ -28,7 +27,7 @@ namespace System.Diagnostics.Tests
                     // On OSX, thread id is a 64bit unsigned value. We truncate the ulong to int
                     // due to .NET API surface area. Hence, on overflow id can be negative while
                     // casting the ulong to int.
-                    if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                    if (!OperatingSystem.IsMacOS())
                     {
                         Assert.InRange(thread.Id, 0, int.MaxValue);
                     }
index 756edf8..26acb30 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Globalization.Tests
@@ -92,8 +91,8 @@ namespace System.Globalization.Tests
             if (ex == null)
             {
                 // Windows and OSX always throw exception. some versions of Linux succeed and others throw exception
-                Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
-                Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
+                Assert.False(OperatingSystem.IsWindows());
+                Assert.False(OperatingSystem.IsMacOS());
                 Assert.Equal(".", result);
             }
             else
@@ -122,9 +121,9 @@ namespace System.Globalization.Tests
             yield return new object[] { "\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 3, 9, typeof(ArgumentException) };
             yield return new object[] { "\u0061\u0062\u0063.\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067.\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0", 11, 10, typeof(ArgumentException) };
 
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))  // expected platform differences, see https://github.com/dotnet/runtime/issues/17190
+            if (!OperatingSystem.IsWindows())  // expected platform differences, see https://github.com/dotnet/runtime/issues/17190
             {
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (OperatingSystem.IsMacOS())
                 {
                     yield return new object[] { ".", 0, 1, typeof(ArgumentException) };
                 }
index 80bb9b1..51cce8f 100644 (file)
@@ -36,11 +36,11 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.Attributes)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & NotifyFilters.Security) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & NotifyFilters.Security) > 0))
                     expected |= WatcherChangeTypes.Changed; // Attribute change on OSX is a ChangeOwner operation which passes the Security NotifyFilter.
                 ExpectEvent(watcher, expected, action, cleanup, dir.Path);
             }
@@ -60,9 +60,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.CreationTime)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
 
                 ExpectEvent(watcher, expected, action, expectedPath: dir.Path);
@@ -106,9 +106,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.LastAccess)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
 
                 ExpectEvent(watcher, expected, action, expectedPath: dir.Path);
@@ -129,9 +129,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.LastWrite)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
 
                 ExpectEvent(watcher, expected, action, expectedPath: dir.Path);
@@ -156,9 +156,9 @@ namespace System.IO.Tests
                     WatcherChangeTypes expected = 0;
                     if ((filter & NotifyFilters.LastWrite) > 0)
                         expected |= WatcherChangeTypes.Changed;
-                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                    else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                         expected |= WatcherChangeTypes.Changed;
-                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                    else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                         expected |= WatcherChangeTypes.Changed;
                     ExpectEvent(watcher, expected, action, expectedPath: dir.Path);
                 }
index 2b8675a..92bd0b6 100644 (file)
@@ -38,11 +38,11 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.Attributes)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & NotifyFilters.Security) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & NotifyFilters.Security) > 0))
                     expected |= WatcherChangeTypes.Changed; // Attribute change on OSX is a ChangeOwner operation which passes the Security NotifyFilter.
 
                 ExpectEvent(watcher, expected, action, cleanup, file.Path);
@@ -63,9 +63,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.CreationTime)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
 
                 ExpectEvent(watcher, expected, action, expectedPath: file.Path);
@@ -109,9 +109,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.LastAccess)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
                 ExpectEvent(watcher, expected, action, expectedPath: file.Path);
             }
@@ -131,9 +131,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.LastWrite)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForAttribute) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForAttribute) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
                 ExpectEvent(watcher, expected, action, expectedPath: file.Path);
             }
@@ -154,9 +154,9 @@ namespace System.IO.Tests
                 WatcherChangeTypes expected = 0;
                 if (filter == NotifyFilters.Size || filter == NotifyFilters.LastWrite)
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForModify) > 0))
+                else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
-                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                     expected |= WatcherChangeTypes.Changed;
                 else if (PlatformDetection.IsWindows7 && filter == NotifyFilters.Attributes) // win7 FSW Size change passes the Attribute filter
                     expected |= WatcherChangeTypes.Changed;
@@ -183,9 +183,9 @@ namespace System.IO.Tests
                     WatcherChangeTypes expected = 0;
                     if (((filter & NotifyFilters.Size) > 0) || ((filter & NotifyFilters.LastWrite) > 0))
                         expected |= WatcherChangeTypes.Changed;
-                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && ((filter & LinuxFiltersForModify) > 0))
+                    else if (OperatingSystem.IsLinux() && ((filter & LinuxFiltersForModify) > 0))
                         expected |= WatcherChangeTypes.Changed;
-                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && ((filter & OSXFiltersForModify) > 0))
+                    else if (OperatingSystem.IsMacOS() && ((filter & OSXFiltersForModify) > 0))
                         expected |= WatcherChangeTypes.Changed;
                     else if (PlatformDetection.IsWindows7 && ((filter & NotifyFilters.Attributes) > 0)) // win7 FSW Size change passes the Attribute filter
                         expected |= WatcherChangeTypes.Changed;
index 4da782f..100aa44 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.ObjectModel;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 
@@ -507,8 +506,8 @@ namespace System.IO.Tests
             watcher.Path = currentDir;
             Assert.Equal(currentDir, watcher.Path);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || // expect no change for OrdinalIgnoreCase-equal strings
-                RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsWindows() || // expect no change for OrdinalIgnoreCase-equal strings
+                OperatingSystem.IsMacOS())
             {
                 watcher.Path = currentDir.ToUpperInvariant();
                 Assert.Equal(currentDir, watcher.Path);
index 6ebc03a..0d6ea8b 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using System.Threading;
 using Xunit;
 using Xunit.Sdk;
@@ -463,7 +462,7 @@ namespace System.IO.Tests
         public static bool CreateSymLink(string targetPath, string linkPath, bool isDirectory)
         {
             Process symLinkProcess = new Process();
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 symLinkProcess.StartInfo.FileName = "cmd";
                 symLinkProcess.StartInfo.Arguments = string.Format("/c mklink{0} \"{1}\" \"{2}\"", isDirectory ? " /D" : "", Path.GetFullPath(linkPath), Path.GetFullPath(targetPath));
index 3648f97..386b847 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using System.Text;
 using Xunit;
 using Microsoft.DotNet.XUnitExtensions;
@@ -10,7 +9,7 @@ namespace System.IO.Tests
 {
     public class Directory_Delete_str : FileSystemTest
     {
-        static bool IsBindMountSupported => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !PlatformDetection.IsInContainer;
+        static bool IsBindMountSupported => OperatingSystem.IsLinux() && !PlatformDetection.IsInContainer;
 
         #region Utilities
 
index cfe5834..04b1411 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Linq;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.Tests
@@ -125,7 +124,7 @@ namespace System.IO.Tests
             // considered a file (since it's broken and we don't know what it'll eventually point to).
             Directory.Delete(path);
             Assert.False(Directory.Exists(path), "path should now not exist");
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.True(Directory.Exists(linkPath), "linkPath should still exist as a directory");
                 Assert.False(File.Exists(linkPath), "linkPath should not be a file");
@@ -142,11 +141,11 @@ namespace System.IO.Tests
             try
             {
                 Directory.Delete(linkPath);
-                Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Should only succeed on Windows");
+                Assert.True(OperatingSystem.IsWindows(), "Should only succeed on Windows");
             }
             catch (IOException)
             {
-                Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Should only fail on Unix");
+                Assert.False(OperatingSystem.IsWindows(), "Should only fail on Unix");
                 File.Delete(linkPath);
             }
 
index bbc069f..3e4c0aa 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Linq;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.Tests
@@ -34,7 +33,7 @@ namespace System.IO.Tests
             }
             targetDir.Delete(recursive: true);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.Equal(1, GetEntries(containingFolder.FullName).Count());
                 Assert.Equal(0, Directory.GetFiles(containingFolder.FullName).Count());
index 16287ef..60544b0 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using Microsoft.DotNet.RemoteExecutor;
 using Xunit;
 
@@ -37,7 +36,7 @@ namespace System.IO.Tests
                 // On OSX, the temp directory /tmp/ is a symlink to /private/tmp, so setting the current
                 // directory to a symlinked path will result in GetCurrentDirectory returning the absolute
                 // path that followed the symlink.
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (!OperatingSystem.IsMacOS())
                 {
                     Assert.Equal(TestDirectory, Directory.GetCurrentDirectory());
                 }
@@ -65,11 +64,11 @@ namespace System.IO.Tests
 
                     // Set Current Directory to symlink
                     Directory.SetCurrentDirectory(linkPath);
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                    if (OperatingSystem.IsWindows())
                     {
                         Assert.Equal(linkPath, Directory.GetCurrentDirectory());
                     }
-                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                    else if (OperatingSystem.IsMacOS())
                     {
                         Assert.Equal("/private" + path, Directory.GetCurrentDirectory());
                     }
index 9438d2a..615bd4c 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.Tests
@@ -157,7 +156,7 @@ namespace System.IO.Tests
             pathFI.Refresh();
             Assert.False(pathFI.Exists, "path should now not exist");
             linkPathFI.Refresh();
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.True(linkPathFI.Exists, "linkPath directory should still exist");
                 Assert.False(File.Exists(linkPath), "linkPath file should not exist");
index aee2e32..b696838 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using Xunit;
 using Microsoft.DotNet.XUnitExtensions;
 
@@ -9,7 +8,7 @@ namespace System.IO.Tests
 {
     public class File_Delete : FileSystemTest
     {
-        static bool IsBindMountSupported => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !PlatformDetection.IsInContainer;
+        static bool IsBindMountSupported => OperatingSystem.IsLinux() && !PlatformDetection.IsInContainer;
 
         protected virtual void Delete(string path)
         {
index 33c10d4..b6b4796 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading.Tasks;
 using Xunit;
@@ -106,7 +105,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     File.WriteAllBytes(path, Encoding.UTF8.GetBytes("text"));
                     Assert.Equal(Encoding.UTF8.GetBytes("text"), File.ReadAllBytes(path));
index 30fc35e..598fc01 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -120,7 +119,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     await File.WriteAllBytesAsync(path, Encoding.UTF8.GetBytes("text"));
                     Assert.Equal(Encoding.UTF8.GetBytes("text"), await File.ReadAllBytesAsync(path));
index 89ede86..d5ef0ee 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 using Xunit;
 
@@ -112,7 +111,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     Write(path, new string[] { "text" });
                     Assert.Equal(new string[] { "text" }, Read(path));
@@ -300,7 +299,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     Write(path, new string[] { "text" });
                     Assert.Equal(new string[] { "text" }, Read(path));
index 9a22ccc..87b3ad7 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -107,7 +106,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     await WriteAsync(path, new string[] { "text" });
                     Assert.Equal(new string[] { "text" }, await ReadAsync(path));
index 152858c..e511b69 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using System.Text;
 using Xunit;
 
@@ -119,7 +118,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     Write(path, "text");
                     Assert.Equal("text", Read(path));
index 3d2f1d9..3381398 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -115,7 +114,7 @@ namespace System.IO.Tests
             try
             {
                 // Operation succeeds when being run by the Unix superuser
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0)
+                if (!OperatingSystem.IsWindows() && geteuid() == 0)
                 {
                     await WriteAsync(path, "text");
                     Assert.Equal("text", await ReadAsync(path));
index 87648f2..b7c3bbe 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.Tests
@@ -79,7 +78,7 @@ namespace System.IO.Tests
                 Assert.Equal(FileSize, info.Length);
 
                 var linkInfo = new FileInfo(linkPath);
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // On Windows, symlinks have length 0.
                     Assert.Equal(0, linkInfo.Length);
index 03b3353..209ddf0 100644 (file)
@@ -4,7 +4,6 @@
 using Microsoft.Win32.SafeHandles;
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Xunit;
 
@@ -105,7 +104,7 @@ namespace System.IO.Tests
 
                     fs.WriteByte(0);
                     fsr.Position++;
-                    if (useAsync && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // Async I/O behaviors differ due to kernel-based implementation on Windows
+                    if (useAsync && OperatingSystem.IsWindows()) // Async I/O behaviors differ due to kernel-based implementation on Windows
                     {
                         Assert.Throws<IOException>(() => FSAssert.CompletesSynchronously(fs.ReadAsync(new byte[1], 0, 1)));
                     }
index 2710edc..5f60690 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Xunit;
@@ -257,7 +256,7 @@ namespace System.IO.Tests
         {
             foreach (bool useAsync in new[] { true, false })
             {
-                if (useAsync && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (useAsync && !OperatingSystem.IsWindows())
                 {
                     // We don't have a special async I/O implementation in FileStream on Unix.
                     continue;
@@ -282,7 +281,7 @@ namespace System.IO.Tests
         {
             // For inner loop, just test one case
             return ManyConcurrentWriteAsyncs_OuterLoop(
-                useAsync: RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
+                useAsync: OperatingSystem.IsWindows(),
                 presize: false,
                 exposeHandle: false,
                 cancelable: true,
index 49237f0..5a1022d 100644 (file)
@@ -3,7 +3,6 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.Tests
@@ -18,7 +17,7 @@ namespace System.IO.Tests
             {
                 Assert.True(File.Exists(fileName));
                 File.Delete(fileName);
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // Prior to 1903 Windows would not delete the filename until the last file handle is closed.
                     Assert.Equal(PlatformDetection.IsWindows10Version1903OrGreater, !File.Exists(fileName));
@@ -56,7 +55,7 @@ namespace System.IO.Tests
             using (FileStream fs = CreateFileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Delete))
             {
                 File.Delete(fileName);
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // Prior to 1903 Windows would not delete the filename until the last file handle is closed.
                     Assert.Equal(PlatformDetection.IsWindows10Version1903OrGreater, !File.Exists(fileName));
index 0f62c53..d651679 100644 (file)
@@ -5,21 +5,20 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 
 internal static class IOInputs
 {
-    public static bool SupportsSettingCreationTime { get { return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } }
-    public static bool SupportsGettingCreationTime { get { return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | RuntimeInformation.IsOSPlatform(OSPlatform.OSX); } }
+    public static bool SupportsSettingCreationTime => OperatingSystem.IsWindows();
+    public static bool SupportsGettingCreationTime => OperatingSystem.IsWindows() || OperatingSystem.IsMacOS();
 
     // Max path length (minus trailing \0). Unix values vary system to system; just using really long values here likely to be more than on the average system.
-    public static readonly int MaxPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 259 : 10000;
+    public static readonly int MaxPath = OperatingSystem.IsWindows() ? 259 : 10000;
 
     // Windows specific, this is the maximum length that can be passed using extended syntax. Does not include the trailing \0.
     public static readonly int MaxExtendedPath = short.MaxValue - 1;
 
     // Same as MaxPath on Unix
-    public static readonly int MaxLongPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? MaxExtendedPath : MaxPath;
+    public static readonly int MaxLongPath = OperatingSystem.IsWindows() ? MaxExtendedPath : MaxPath;
 
     // Windows specific, this is the maximum length that can be passed to APIs taking directory names, such as Directory.CreateDirectory & Directory.Move.
     // Does not include the trailing \0.
index c0c9305..d2304e1 100644 (file)
@@ -34,7 +34,7 @@ public static class MountHelper
     public static bool CreateSymbolicLink(string linkPath, string targetPath, bool isDirectory)
     {
         Process symLinkProcess = new Process();
-        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+        if (OperatingSystem.IsWindows())
         {
             symLinkProcess.StartInfo.FileName = "cmd";
             symLinkProcess.StartInfo.Arguments = string.Format("/c mklink{0} \"{1}\" \"{2}\"", isDirectory ? " /D" : "", linkPath, targetPath);
index 3b0428c..9af2e8b 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.IsolatedStorage
@@ -78,7 +77,7 @@ namespace System.IO.IsolatedStorage
                 };
 
                 // https://github.com/dotnet/runtime/issues/2092
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+                if (OperatingSystem.IsWindows()
                     && !PlatformDetection.IsInAppContainer)
                 {
                     validScopes.Add(PresetScopes.MachineStoreForApplication);
index 64f228c..e3e7f42 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
-using System.Runtime.InteropServices;
 using System.Text;
 
 namespace System.IO.IsolatedStorage
@@ -33,7 +32,7 @@ namespace System.IO.IsolatedStorage
 
             // https://github.com/dotnet/runtime/issues/2092
             // https://github.com/dotnet/runtime/issues/21742
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+            if (OperatingSystem.IsWindows()
                 && !PlatformDetection.IsInAppContainer)
             {
                 s_roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine));
index d5edbbc..f23da73 100644 (file)
@@ -3,7 +3,6 @@
 
 using Microsoft.Win32.SafeHandles;
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using Microsoft.DotNet.XUnitExtensions;
 using Xunit;
 
@@ -697,13 +696,13 @@ namespace System.IO.MemoryMappedFiles.Tests
         public void WriteToReadOnlyFile_ReadWrite(MemoryMappedFileAccess access)
         {
             WriteToReadOnlyFile(access, access == MemoryMappedFileAccess.Read ||
-                            (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformDetection.IsSuperUser));
+                            (!OperatingSystem.IsWindows() && PlatformDetection.IsSuperUser));
         }
 
         [Fact]
         public void WriteToReadOnlyFile_CopyOnWrite()
         {
-            WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformDetection.IsSuperUser));
+            WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!OperatingSystem.IsWindows() && PlatformDetection.IsSuperUser));
         }
 
         /// <summary>
index 86cc494..670aa4d 100644 (file)
@@ -23,8 +23,8 @@ namespace System.IO.MemoryMappedFiles.Tests
             const int _SC_PAGESIZE_NetBSD = 28;
             const int _SC_PAGESIZE_OSX = 29;
             pageSize = sysconf(
-                RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? _SC_PAGESIZE_OSX :
-                RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")) ? _SC_PAGESIZE_FreeBSD :
+                OperatingSystem.IsMacOS() ? _SC_PAGESIZE_OSX :
+                OperatingSystem.IsFreeBSD() ? _SC_PAGESIZE_FreeBSD :
                 RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")) ? _SC_PAGESIZE_NetBSD :
                 _SC_PAGESIZE_Linux);
             Assert.InRange(pageSize, 1, int.MaxValue);
index 052e0ab..9473abe 100644 (file)
@@ -51,7 +51,7 @@ namespace System.IO.MemoryMappedFiles.Tests
         /// <summary>Asserts that the handle's inheritability matches the specified value.</summary>
         protected static void AssertInheritability(SafeHandle handle, HandleInheritability inheritability)
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 uint flags;
                 Assert.True(GetHandleInformation(handle.DangerousGetHandle(), out flags));
index f86b39b..86f00bc 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.IO.MemoryMappedFiles.Tests
@@ -12,7 +11,7 @@ namespace System.IO.MemoryMappedFiles.Tests
     public abstract partial class MemoryMappedFilesTestBase : FileCleanupTestBase
     {
         /// <summary>Gets whether named maps are supported by the current platform.</summary>
-        protected static bool MapNamesSupported { get { return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } }
+        protected static bool MapNamesSupported => OperatingSystem.IsWindows();
 
         /// <summary>Creates a map name guaranteed to be unique.</summary>
         protected static string CreateUniqueMapName() { return Guid.NewGuid().ToString("N"); }
index f96e004..0be6027 100644 (file)
@@ -3,7 +3,6 @@
 
 using Microsoft.Win32.SafeHandles;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using Microsoft.DotNet.XUnitExtensions;
 using Xunit;
 
@@ -90,7 +89,7 @@ namespace System.IO.MemoryMappedFiles.Tests
                 }
                 catch (UnauthorizedAccessException)
                 {
-                    if ((RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || PlatformDetection.IsInContainer) &&
+                    if ((OperatingSystem.IsMacOS() || PlatformDetection.IsInContainer) &&
                        (viewAccess == MemoryMappedFileAccess.ReadExecute || viewAccess == MemoryMappedFileAccess.ReadWriteExecute))
                     {
                         // Containers and OSX with SIP enabled do not have execute permissions by default.
@@ -170,7 +169,7 @@ namespace System.IO.MemoryMappedFiles.Tests
                     using (MemoryMappedViewAccessor acc = mmf.CreateViewAccessor(MapLength, 0))
                     {
                         Assert.Equal(
-                            RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? MapLength : 0,
+                            OperatingSystem.IsWindows() ? MapLength : 0,
                             acc.PointerOffset);
                     }
                 }
index 5f98409..a9cf5db 100644 (file)
@@ -3,7 +3,6 @@
 
 using Microsoft.Win32.SafeHandles;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using Microsoft.DotNet.XUnitExtensions;
 using Xunit;
 
@@ -90,7 +89,7 @@ namespace System.IO.MemoryMappedFiles.Tests
                 }
                 catch (UnauthorizedAccessException)
                 {
-                    if ((RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || PlatformDetection.IsInContainer) &&
+                    if ((OperatingSystem.IsMacOS() || PlatformDetection.IsInContainer) &&
                         (viewAccess == MemoryMappedFileAccess.ReadExecute || viewAccess == MemoryMappedFileAccess.ReadWriteExecute))
                     {
                         // Containers and OSX with SIP enabled do not have execute permissions by default.
@@ -186,7 +185,7 @@ namespace System.IO.MemoryMappedFiles.Tests
                     using (MemoryMappedViewStream s = mmf.CreateViewStream(MapLength, 0))
                     {
                         Assert.Equal(
-                            RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? MapLength : 0,
+                            OperatingSystem.IsWindows() ? MapLength : 0,
                             s.PointerOffset);
                     }
                 }
index e576630..d89887d 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Xunit;
@@ -117,7 +116,7 @@ namespace System.IO.Pipes.Tests
                     Task<int> clientTask = client.ReadAsync(received1, 0, received1.Length);
                     using (NamedPipeServerStream server = new NamedPipeServerStream(PipeDirection.Out, false, true, serverBase.SafePipeHandle))
                     {
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                        if (OperatingSystem.IsWindows())
                         {
                             Assert.Equal(1, client.NumberOfServerInstances);
                         }
@@ -155,7 +154,7 @@ namespace System.IO.Pipes.Tests
                 {
                     using (NamedPipeClientStream client = new NamedPipeClientStream(PipeDirection.In, false, true, pair.clientStream.SafePipeHandle))
                     {
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                        if (OperatingSystem.IsWindows())
                         {
                             Assert.Equal(1, client.NumberOfServerInstances);
                         }
@@ -224,7 +223,7 @@ namespace System.IO.Pipes.Tests
                 NamedPipeServerStream server = pair.serverStream;
                 var ctx = new CancellationTokenSource();
 
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // cancellation token after the operation has been initiated
+                if (OperatingSystem.IsWindows()) // cancellation token after the operation has been initiated
                 {
                     Task serverWaitTimeout = server.WaitForConnectionAsync(ctx.Token);
                     ctx.Cancel();
@@ -322,7 +321,7 @@ namespace System.IO.Pipes.Tests
 
                 if (!pair.writeToServer)
                 {
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // writes on Unix may still succeed after other end disconnects, due to socket being used
+                    if (OperatingSystem.IsWindows()) // writes on Unix may still succeed after other end disconnects, due to socket being used
                     {
                         // Pipe is broken
                         Assert.Throws<IOException>(() => client.Write(buffer, 0, buffer.Length));
@@ -338,7 +337,7 @@ namespace System.IO.Pipes.Tests
                     Assert.Equal(0, client.Read(buffer, 0, buffer.Length));
                     Assert.Equal(-1, client.ReadByte());
 
-                    if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // NumberOfServerInstances not supported on Unix
+                    if (!OperatingSystem.IsWindows()) // NumberOfServerInstances not supported on Unix
                     {
                         Assert.Throws<PlatformNotSupportedException>(() => client.NumberOfServerInstances);
                     }
@@ -547,7 +546,7 @@ namespace System.IO.Pipes.Tests
                 if (server.CanWrite)
                 {
                     var ctx1 = new CancellationTokenSource();
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // On Unix WriteAsync's aren't cancelable once initiated
+                    if (OperatingSystem.IsWindows()) // On Unix WriteAsync's aren't cancelable once initiated
                     {
                         Task serverWriteToken = server.WriteAsync(buffer, 0, buffer.Length, ctx1.Token);
                         ctx1.Cancel();
@@ -643,7 +642,7 @@ namespace System.IO.Pipes.Tests
                 if (client.CanWrite)
                 {
                     var ctx1 = new CancellationTokenSource();
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // On Unix WriteAsync's aren't cancelable once initiated
+                    if (OperatingSystem.IsWindows()) // On Unix WriteAsync's aren't cancelable once initiated
                     {
                         Task serverWriteToken = client.WriteAsync(buffer, 0, buffer.Length, ctx1.Token);
                         ctx1.Cancel();
index 16714db..ff2644d 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Security.Principal;
 using System.Threading;
 using System.Threading.Tasks;
@@ -578,11 +577,11 @@ namespace System.IO.Pipes.Tests
 
             // Validate the length was expected
             string path = (string)e.ActualValue;
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+            if (OperatingSystem.IsLinux())
             {
                 Assert.Equal(108, path.Length);
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 Assert.Equal(104, path.Length);
             }
index d762f74..b3ebf7f 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
 using Xunit;
@@ -264,7 +263,7 @@ namespace System.IO.Pipes.Tests
                 Task.Run(() => { pair.writeablePipe.Write(sent, 0, sent.Length); });
                 Assert.Equal(sent.Length, pair.readablePipe.Read(received, 0, sent.Length));
                 Assert.Equal(sent, received);
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // WaitForPipeDrain isn't supported on Unix
+                if (OperatingSystem.IsWindows()) // WaitForPipeDrain isn't supported on Unix
                     pair.writeablePipe.WaitForPipeDrain();
             }
         }
index 3ef6b55..69ab803 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Xunit;
 
@@ -199,7 +198,7 @@ namespace System.IO.Pipes.Tests
         {
             using (ServerClientPair pair = CreateServerClientPair())
             {
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
+                if (!OperatingSystem.IsWindows() &&
                     (pair.readablePipe is NamedPipeClientStream || pair.writeablePipe is NamedPipeClientStream))
                 {
                     // On Unix, NamedPipe*Stream is implemented in term of sockets, where information
@@ -281,7 +280,7 @@ namespace System.IO.Pipes.Tests
         {
             using (ServerClientPair pair = CreateServerClientPair())
             {
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
+                if (!OperatingSystem.IsWindows() &&
                     (pair.readablePipe is NamedPipeClientStream || pair.writeablePipe is NamedPipeClientStream))
                 {
                     // On Unix, NamedPipe*Stream is implemented in term of sockets, where information
index 2e56810..f88cd14 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.IO;
 using System.Net.Sockets;
-using System.Runtime.InteropServices;
 using Xunit;
 using Xunit.Abstractions;
 
@@ -59,7 +58,7 @@ namespace System.Net.NameResolution.PalTests
             Assert.NotNull(hostName);
 
             SocketError error = NameResolutionPal.TryGetAddrInfo(hostName, justAddresses, out hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode);
-            if (error == SocketError.HostNotFound && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)))
+            if (error == SocketError.HostNotFound && (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()))
             {
                 // On Unix, we are not guaranteed to be able to resove the local host. The ability to do so depends on the
                 // machine configurations, which varies by distro and is often inconsistent.
index e202bf5..fd7cf08 100644 (file)
@@ -4,7 +4,6 @@
 using System.Net;
 using System.Net.Sockets;
 using System.Net.Test.Common;
-using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 
 using Xunit;
@@ -36,7 +35,7 @@ namespace System.Net.NetworkInformation.Tests
             Assert.NotNull(gp.GetActiveUdpListeners());
 
             Assert.NotNull(gp.GetIPv4GlobalStatistics());
-            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && !RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")))
+            if (!OperatingSystem.IsMacOS() && !OperatingSystem.IsFreeBSD())
             {
                 // OSX and FreeBSD do not provide IPv6  stats.
                 Assert.NotNull(gp.GetIPv6GlobalStatistics());
index 32ec112..6bea47f 100644 (file)
@@ -6,7 +6,6 @@ using System.IO;
 using System.Linq;
 using System.Net.Sockets;
 using System.Net.Test.Common;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 using System.Security.Cryptography.X509Certificates;
 using System.Text;
@@ -226,7 +225,7 @@ namespace System.Net.Security.Tests
 
         public static IEnumerable<object[]> Alpn_TestData()
         {
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 yield return new object[] { new List<SslApplicationProtocol> { SslApplicationProtocol.Http11, SslApplicationProtocol.Http2 }, new List<SslApplicationProtocol> { SslApplicationProtocol.Http2 }, null };
                 yield return new object[] { new List<SslApplicationProtocol> { SslApplicationProtocol.Http11 }, new List<SslApplicationProtocol> { SslApplicationProtocol.Http11, SslApplicationProtocol.Http2 }, null };
index a79ce8a..e9c47fc 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.IO;
 using System.Net.Test.Common;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading.Tasks;
@@ -122,7 +121,7 @@ namespace System.Net.Security.Tests
 
                 await Assert.ThrowsAsync<AuthenticationException>(() => tasks[0]);
 
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // IOException is thrown when trying to read from a disconnected socket.
                     await Assert.ThrowsAsync<IOException>(() => tasks[1]);
index 4843d81..a8c7b1b 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Diagnostics;
 using System.IO;
-using System.Runtime.InteropServices;
 using System.Security.Authentication;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading.Tasks;
@@ -28,9 +27,9 @@ namespace System.Net.Security.Tests
 
         public static bool SupportsNullEncryption { get { return s_supportsNullEncryption.Value; } }
 
-        public static bool SupportsHandshakeAlerts { get { return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } }
+        public static bool SupportsHandshakeAlerts { get { return OperatingSystem.IsLinux() || OperatingSystem.IsWindows(); } }
 
-        public static bool SupportsAlpnAlerts { get { return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && PlatformDetection.OpenSslVersion.CompareTo(new Version(1,0,2)) >= 0); } }
+        public static bool SupportsAlpnAlerts { get { return OperatingSystem.IsWindows() || (OperatingSystem.IsLinux() && PlatformDetection.OpenSslVersion.CompareTo(new Version(1,0,2)) >= 0); } }
 
         public static Task WhenAllOrAnyFailedWithTimeout(params Task[] tasks)
             => tasks.WhenAllOrAnyFailed(PassingTestTimeoutMilliseconds);
@@ -38,13 +37,13 @@ namespace System.Net.Security.Tests
         private static Lazy<bool> s_supportsNullEncryption = new Lazy<bool>(() =>
         {
             // On Windows, null ciphers (no encryption) are supported.
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 return true;
             }
 
             // On macOS, the null cipher (no encryption) is not supported.
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 return false;
             }
index 17b91a5..5d43c02 100644 (file)
@@ -55,7 +55,7 @@ namespace System.Net.Security.Tests
 
             Assert.True(cbt1 != null, "ChannelBindingKind.Endpoint token data should be returned.");
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 Assert.True(cbt2 == null, "ChannelBindingKind.Unique token data is not expected on OSX platform.");
             }
index 2fd0b36..dc3dd8c 100644 (file)
@@ -12,7 +12,6 @@ using System.Threading.Tasks;
 using System.Threading;
 using System.Security.Cryptography.X509Certificates;
 using System.Security.Cryptography;
-using System.Runtime.InteropServices;
 
 namespace SslStress
 {
@@ -158,7 +157,7 @@ namespace SslStress
             certReq.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false));
             certReq.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, false));
             X509Certificate2 cert = certReq.CreateSelfSigned(DateTimeOffset.UtcNow.AddMonths(-1), DateTimeOffset.UtcNow.AddMonths(1));
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 cert = new X509Certificate2(cert.Export(X509ContentType.Pfx));
             }
index 92061fb..564a3dc 100644 (file)
@@ -5,7 +5,6 @@ using System;
 using System.Collections.Generic;
 using System.Net.NetworkInformation;
 using System.Net.Sockets;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Net.Tests
@@ -196,7 +195,7 @@ namespace System.Net.Tests
                 // is turned off. Hence dns lookup for it's own hostname fails.
                 Assert.Equal(SocketError.HostNotFound, exception.SocketErrorCode);
                 Assert.Throws<SocketException>(() => Dns.GetHostEntryAsync(Dns.GetHostName()).GetAwaiter().GetResult());
-                Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
+                Assert.True(OperatingSystem.IsLinux() || OperatingSystem.IsMacOS());
             }
         }
 
index 4e39522..aa7ed27 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.IO;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Xml.Tests
@@ -45,7 +44,7 @@ namespace System.Xml.Tests
             // Base URI as null is the default for internal Xml operation.
             var baseUris = new List<Uri> { null };
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 // The case below does not work on Unix, the '#' ends up treated as a fragment and the path is cut there.
                 var currDirWithDirSeparator = Environment.CurrentDirectory + Path.DirectorySeparatorChar;
index 1c757b8..2f8a5a4 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Tests
             AssertExtensions.Throws<ArgumentOutOfRangeException, ArgumentException>("target", null, () => Environment.GetEnvironmentVariable("test", (EnvironmentVariableTarget)42));
             AssertExtensions.Throws<ArgumentOutOfRangeException, ArgumentException>("target", null, () => Environment.SetEnvironmentVariable("test", "test", (EnvironmentVariableTarget)(-1)));
             AssertExtensions.Throws<ArgumentOutOfRangeException, ArgumentException>("target", null, () => Environment.GetEnvironmentVariables((EnvironmentVariableTarget)(3)));
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && System.Tests.SetEnvironmentVariable.IsSupportedTarget(EnvironmentVariableTarget.User))
+            if (OperatingSystem.IsWindows() && System.Tests.SetEnvironmentVariable.IsSupportedTarget(EnvironmentVariableTarget.User))
             {
                 AssertExtensions.Throws<ArgumentException>("variable", null, () => Environment.SetEnvironmentVariable(new string('s', 256), "value", EnvironmentVariableTarget.User));
             }
@@ -84,7 +84,7 @@ namespace System.Tests
 
                 Assert.Equal(value, Environment.GetEnvironmentVariable("ThisIsATestEnvironmentVariable"));
 
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (!OperatingSystem.IsWindows())
                 {
                     value = null;
                 }
index aad0ba7..2d43aed 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Tests
                 return false;
             }
 
-            return target == EnvironmentVariableTarget.Process || RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+            return target == EnvironmentVariableTarget.Process || OperatingSystem.IsWindows();
         }
 
         [Fact]
index 9b65740..ec2a052 100644 (file)
@@ -44,7 +44,7 @@ namespace System.Tests
                 Environment.CurrentDirectory = TestDirectory;
                 Assert.Equal(Directory.GetCurrentDirectory(), Environment.CurrentDirectory);
 
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (!OperatingSystem.IsMacOS())
                 {
                     // On OSX, the temp directory /tmp/ is a symlink to /private/tmp, so setting the current
                     // directory to a symlinked path will result in GetCurrentDirectory returning the absolute
@@ -127,7 +127,7 @@ namespace System.Tests
         public void OSVersion_MatchesPlatform()
         {
             PlatformID id = Environment.OSVersion.Platform;
-            PlatformID expected = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? PlatformID.Win32NT : OperatingSystem.IsBrowser() ? PlatformID.Other : PlatformID.Unix;
+            PlatformID expected = OperatingSystem.IsWindows() ? PlatformID.Win32NT : OperatingSystem.IsBrowser() ? PlatformID.Other : PlatformID.Unix;
             Assert.Equal(expected, id);
         }
 
@@ -142,7 +142,7 @@ namespace System.Tests
 
             Assert.Contains(version.ToString(2), versionString);
 
-            string expectedOS = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows " : OperatingSystem.IsBrowser() ? "Other " : "Unix ";
+            string expectedOS = OperatingSystem.IsWindows() ? "Windows " : OperatingSystem.IsBrowser() ? "Other " : "Unix ";
             Assert.Contains(expectedOS, versionString);
         }
 
index 5ed3fd5..f299734 100644 (file)
@@ -62,7 +62,7 @@ namespace System.Runtime.InteropServices.Tests
         public void OffsetOf_ValidField_ReturnsExpected()
         {
             Type t = typeof(FieldAlignmentTest);
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
+            if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
             {
                 Assert.Equal(80, Marshal.SizeOf(t));
             }
@@ -78,7 +78,7 @@ namespace System.Runtime.InteropServices.Tests
             Assert.Equal(new IntPtr(12), Marshal.OffsetOf(t, nameof(FieldAlignmentTest.m_byte2)));
             Assert.Equal(new IntPtr(16), Marshal.OffsetOf(t, nameof(FieldAlignmentTest.m_int2)));
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
+            if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86))
             {
                 Assert.Equal(new IntPtr(24), Marshal.OffsetOf(t, nameof(FieldAlignmentTest.m_double1)));
                 Assert.Equal(new IntPtr(32), Marshal.OffsetOf(t, nameof(FieldAlignmentTest.m_char1)));
@@ -109,7 +109,7 @@ namespace System.Runtime.InteropServices.Tests
         {
             Type t = typeof(FieldAlignmentTest_Decimal);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.Wasm))
+            if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.Wasm))
             {
                 Assert.Equal(96, Marshal.SizeOf(t));
             }
@@ -121,7 +121,7 @@ namespace System.Runtime.InteropServices.Tests
             Assert.Equal(new IntPtr(0), Marshal.OffsetOf(t, nameof(FieldAlignmentTest_Decimal.b)));
             Assert.Equal(new IntPtr(8), Marshal.OffsetOf(t, nameof(FieldAlignmentTest_Decimal.p)));
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.Wasm))
+            if (OperatingSystem.IsWindows() || (RuntimeInformation.ProcessArchitecture != Architecture.X86 && RuntimeInformation.ProcessArchitecture != Architecture.Wasm))
             {
                 Assert.Equal(new IntPtr(88), Marshal.OffsetOf(t, nameof(FieldAlignmentTest_Decimal.s)));
             }
index ebe6a60..ce0e53e 100644 (file)
@@ -6,7 +6,6 @@ using System.Collections.ObjectModel;
 using System.Globalization;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text.RegularExpressions;
 using Microsoft.DotNet.RemoteExecutor;
@@ -16,8 +15,8 @@ namespace System.Tests
 {
     public static partial class TimeZoneInfoTests
     {
-        private static readonly bool s_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
-        private static readonly bool s_isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+        private static readonly bool s_isWindows = OperatingSystem.IsWindows();
+        private static readonly bool s_isOSX = OperatingSystem.IsMacOS();
 
         private static string s_strPacific = s_isWindows ? "Pacific Standard Time" : "America/Los_Angeles";
         private static string s_strSydney = s_isWindows ? "AUS Eastern Standard Time" : "Australia/Sydney";
index a9e70c0..74d475b 100644 (file)
@@ -3,7 +3,6 @@
 
 using System.Collections.Generic;
 using System.Reflection;
-using System.Runtime.InteropServices;
 using System.Text;
 using Test.Cryptography;
 using Xunit;
@@ -255,7 +254,7 @@ namespace System.Security.Cryptography.CryptoConfigTests
         [Theory, MemberData(nameof(AllValidNames))]
         public static void CreateFromName_AllValidNames(string name, string typeName, bool supportsUnixMac)
         {
-            bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+            bool isWindows = OperatingSystem.IsWindows();
 
             if (supportsUnixMac || isWindows)
             {
index a72697e..69b1092 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Security.Cryptography.Encoding.Tests
@@ -315,7 +314,7 @@ namespace System.Security.Cryptography.Encoding.Tests
             }
             catch (CryptographicException)
             {
-                bool isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+                bool isMac = OperatingSystem.IsMacOS();
 
                 Assert.True(isMac, "Exception is only raised on macOS");
 
@@ -348,7 +347,7 @@ namespace System.Security.Cryptography.Encoding.Tests
             }
             catch (CryptographicException)
             {
-                bool isMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+                bool isMac = OperatingSystem.IsMacOS();
 
                 Assert.True(isMac, "Exception is only raised on macOS");
 
index f9a260a..be71f91 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography;
 using System.Security.Cryptography.X509Certificates;
 
@@ -16,7 +15,7 @@ namespace Test.Cryptography
         private static X509KeyStorageFlags GetBestKeyStorageFlags()
         {
 #if NETCOREAPP
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 // On Windows 7 ephemeral keys with a key usage embedded in the PFX
                 // are treated differently than Windows 8.  So just use the default
@@ -28,7 +27,7 @@ namespace Test.Cryptography
                     return X509KeyStorageFlags.EphemeralKeySet;
                 }
             }
-            else if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (!OperatingSystem.IsMacOS())
             {
                 // OSX doesn't allow ephemeral, but every other Unix does.
                 return X509KeyStorageFlags.EphemeralKeySet;
index c18541a..8e385dc 100644 (file)
@@ -1,8 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
-
 namespace System.Security.Cryptography.X509Certificates.Tests
 {
     //
@@ -17,7 +15,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
         // netcoreapp-other: EphemeralKeySet
         internal static readonly X509KeyStorageFlags EphemeralIfPossible =
 #if !NO_EPHEMERALKEYSET_AVAILABLE
-            !RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? X509KeyStorageFlags.EphemeralKeySet :
+            !OperatingSystem.IsMacOS() ? X509KeyStorageFlags.EphemeralKeySet :
 #endif
             X509KeyStorageFlags.DefaultKeySet;
         //
index 77143fd..af0c0a9 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
 using Test.Cryptography;
@@ -249,7 +248,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 Assert.False(chain.Build(microsoftDotCom));
 
                 // Linux and Windows do not search the default system root stores when CustomRootTrust is enabled
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (OperatingSystem.IsMacOS())
                 {
                     Assert.Equal(3, chain.ChainElements.Count);
                     Assert.Equal(X509ChainStatusFlags.UntrustedRoot, chain.AllStatusFlags());
@@ -843,11 +842,11 @@ namespace System.Security.Cryptography.X509Certificates.Tests
         {
             X509ChainStatusFlags expectedFlags;
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 expectedFlags = X509ChainStatusFlags.NotSignatureValid;
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 // For OSX alone expectedFlags here means OR instead of AND.
                 // Because the error code changed in 10.13.4 from UntrustedRoot to PartialChain
@@ -879,7 +878,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
 
                 X509ChainStatusFlags allFlags = chain.AllStatusFlags();
 
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (OperatingSystem.IsMacOS())
                 {
                     // If we're on 10.13.3 or older we get UntrustedRoot.
                     // If we're on 10.13.4 or newer we get PartialChain.
@@ -1023,7 +1022,7 @@ tHP28fj0LUop/QFojSZPsaPAW6JvoQ0t4hd6WoyX6z7FsA==
                     bool valid = chain.Build(cert);
                     X509ChainStatusFlags allFlags = chain.AllStatusFlags();
 
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                    if (OperatingSystem.IsMacOS())
                     {
                         // OSX considers this to be valid because it doesn't report NotSignatureValid,
                         // just PartialChain ("I couldn't find an issuer that made the signature work"),
index 13ab67f..4690f50 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Security.Cryptography.X509Certificates.Tests
@@ -436,7 +435,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 yield return new object[] { X509KeyStorageFlags.DefaultKeySet };
 
 #if !NO_EPHEMERALKEYSET_AVAILABLE
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (!OperatingSystem.IsMacOS())
                     yield return new object[] { X509KeyStorageFlags.EphemeralKeySet };
 #endif
             }
index ddcce5f..2a25bec 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Security.Cryptography.X509Certificates.Tests
@@ -354,13 +353,13 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             CryptographicException defaultException = new CryptographicException();
             Assert.NotEqual(defaultException.Message, ex.Message);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 Assert.Equal(unchecked((int)0x80092009), ex.HResult);
                 // TODO (3233): Test that Message is also set correctly
                 //Assert.Equal("Cannot find the requested object.", ex.Message);
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            else if (OperatingSystem.IsMacOS())
             {
                 Assert.Equal(-25257, ex.HResult);
             }
index 9d88ca7..b71d255 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Linq;
-using System.Runtime.InteropServices;
 using Test.Cryptography;
 using Xunit;
 
@@ -97,7 +96,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             intermediateCert = TamperIfNeeded(intermediateCert, intermediateErrors);
             rootCert = TamperIfNeeded(rootCert, rootErrors);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            if (OperatingSystem.IsMacOS())
             {
                 // For the lower levels, turn NotSignatureValid into PartialChain,
                 // and clear all errors at higher levels.
@@ -129,7 +128,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                     }
                 }
             }
-            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            else if (OperatingSystem.IsWindows())
             {
                 // Windows only reports NotTimeValid on the start-of-chain (end-entity in this case)
                 // If it were possible in this suite to get only a higher-level cert as NotTimeValid
index 8a2a608..265c345 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using System.Runtime.InteropServices;
 using System.Text;
 
 using Xunit;
@@ -94,7 +93,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                     Assert.NotSame(expected, match);
 
                     // FriendlyName is Windows-only.
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                    if (OperatingSystem.IsWindows())
                     {
                         // Verify that the find result and original are linked, not just equal.
                         match.FriendlyName = "HAHA";
index ee9f01d..de3a5f1 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.Pkcs;
 using Xunit;
 
@@ -76,7 +75,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             using (var cert = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword, s_exportableImportFlags))
             using (RSA key = cert.GetRSAPrivateKey())
             {
-                if (dontShroudKey && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (dontShroudKey && OperatingSystem.IsWindows())
                 {
                     // CNG keys are only encrypted-exportable, so we need to export them encrypted.
                     // Then we can import it into a new, fully-exportable key. (Sigh.)
index e4c7644..e1ab045 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Globalization;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.Pkcs;
 using Test.Cryptography;
 using Xunit;
@@ -39,7 +38,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
         //
         // Our Unix loader matches the current Windows 10 behavior.
         private static readonly bool s_loaderFailsKeysEarly =
-            RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
+            OperatingSystem.IsWindows() &&
             !PlatformDetection.IsWindows10Version1607OrGreater;
 
         protected abstract void ReadPfx(
@@ -220,7 +219,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 byte[] pfxBytes = builder.Encode();
 
                 // On macOS the cert will come back with HasPrivateKey being false.
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (OperatingSystem.IsMacOS())
                 {
                     using (var publicCert = new X509Certificate2(cert.RawData))
                     {
@@ -282,7 +281,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
 
                 // On macOS the cert will come back with HasPrivateKey being false when the
                 // incorrect key comes first
-                if (!correctKeyFirst && RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+                if (!correctKeyFirst && OperatingSystem.IsMacOS())
                 {
                     using (var publicCert = new X509Certificate2(cert.RawData))
                     {
@@ -906,7 +905,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                     // Obviously this hit some sort of weird corner case in the Win7
                     // loader, but it's not important to the test.
 
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
+                    if (OperatingSystem.IsWindows() &&
                         !PlatformDetection.IsWindows8xOrLater)
                     {
                         followup = null;
index 35dc1f4..37ca1cc 100644 (file)
@@ -97,7 +97,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             CryptographicException ex = Assert.ThrowsAny<CryptographicException>(
                 () => coll.Import(pfxBytes, bestPassword, s_importFlags));
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 if (altWin32Error != 0 && ex.HResult != altWin32Error)
                 {
index 7138253..39f736d 100644 (file)
@@ -1,7 +1,6 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
-using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System.Security.Cryptography.X509Certificates.Tests
@@ -69,7 +68,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             CryptographicException ex = Assert.ThrowsAny<CryptographicException>(
                 () => new X509Certificate2(pfxBytes, bestPassword, s_importFlags));
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 if (altWin32Error != 0 && ex.HResult != altWin32Error)
                 {
index 195ab03..e0af533 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
-using System.Runtime.InteropServices;
 using Test.Cryptography;
 using Xunit;
 
@@ -222,7 +221,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
         {
             Assert.NotNull(ecdsa);
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 AssertEccAlgorithm(ecdsa, "ECDSA_P256");
             }
@@ -239,7 +238,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                     {
                         Assert.NotNull(ecdsa);
 
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                        if (OperatingSystem.IsWindows())
                         {
                             AssertEccAlgorithm(ecdsa, "ECDH");
                         }
@@ -263,7 +262,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
             {
                 Assert.NotNull(ecdsa);
 
-                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+                if (OperatingSystem.IsWindows())
                 {
                     // If Windows were to start detecting this case as ECDSA that wouldn't be bad,
                     // but this assert is the only proof that this certificate was made with OpenSSL.
index ac86924..514698a 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using System.Security.Cryptography.X509Certificates.Tests.Common;
 using Xunit;
 
@@ -526,7 +525,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests.RevocationTests
 
                         // [ActiveIssue("https://github.com/dotnet/runtime/issues/31246")]
                         // Linux reports this code at more levels than Windows does.
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                        if (OperatingSystem.IsLinux())
                         {
                             issuerExtraProblems |= X509ChainStatusFlags.NotValidForUsage;
                         }
@@ -610,7 +609,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests.RevocationTests
 
                         // [ActiveIssue("https://github.com/dotnet/runtime/issues/31246")]
                         // Linux reports this code at more levels than Windows does.
-                        if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+                        if (OperatingSystem.IsLinux())
                         {
                             issuerExtraProblems |= X509ChainStatusFlags.NotValidForUsage;
                         }
index 482b317..868e75e 100644 (file)
@@ -4,7 +4,6 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.Globalization;
-using System.Runtime.InteropServices;
 using Test.Cryptography;
 using Xunit;
 
@@ -135,7 +134,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
 
             string expectedHex;
 
-            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+            if (OperatingSystem.IsWindows())
             {
                 expectedHex = testCase.GetBmpEncoding() ?? testCase.GetPreferredEncoding();
             }