|
| 1 | +// Copyright (c) .NET Foundation and contributors. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Runtime.InteropServices; |
| 6 | +using Microsoft.NET.TestFramework; |
| 7 | +using Xunit; |
| 8 | +using Xunit.Abstractions; |
| 9 | + |
| 10 | +namespace Microsoft.DotNet.Cli.Utils.Tests |
| 11 | +{ |
| 12 | + public class RuntimeEnvironmentTests : SdkTest |
| 13 | + { |
| 14 | + public RuntimeEnvironmentTests(ITestOutputHelper log) : base(log) |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + [WindowsOnlyFact] |
| 19 | + public void VerifyWindows() |
| 20 | + { |
| 21 | + Assert.Equal(Platform.Windows, RuntimeEnvironment.OperatingSystemPlatform); |
| 22 | + Assert.Equal("Windows", RuntimeEnvironment.OperatingSystem); |
| 23 | + |
| 24 | + VerifyOperatingSystemVersionEqualsEnvironmentOSVersion(); |
| 25 | + } |
| 26 | + |
| 27 | + [MacOsOnlyFact] |
| 28 | + public void VerifyMacOs() |
| 29 | + { |
| 30 | + Assert.Equal(Platform.Darwin, RuntimeEnvironment.OperatingSystemPlatform); |
| 31 | + Assert.Equal("Mac OS X", RuntimeEnvironment.OperatingSystem); |
| 32 | + |
| 33 | + VerifyOperatingSystemVersionEqualsEnvironmentOSVersion(); |
| 34 | + } |
| 35 | + |
| 36 | + private void VerifyOperatingSystemVersionEqualsEnvironmentOSVersion() |
| 37 | + { |
| 38 | + Version osVersion = Version.Parse(RuntimeEnvironment.OperatingSystemVersion); |
| 39 | + Version expectedOSVersion = Environment.OSVersion.Version; |
| 40 | + |
| 41 | + Assert.Equal(expectedOSVersion.Major, osVersion.Major); |
| 42 | + Assert.Equal(expectedOSVersion.Minor, osVersion.Minor); |
| 43 | + Assert.Equal(expectedOSVersion.Build, osVersion.Build); |
| 44 | + } |
| 45 | + |
| 46 | + [LinuxOnlyFact] |
| 47 | + public void VerifyLinux() |
| 48 | + { |
| 49 | + Assert.Equal(Platform.Linux, RuntimeEnvironment.OperatingSystemPlatform); |
| 50 | + |
| 51 | + // ensure OperatingSystem and OperatingSystemVersion are aligned with the current RID |
| 52 | + Assert.StartsWith( |
| 53 | + $"{RuntimeEnvironment.OperatingSystem.ToLowerInvariant()}.{RuntimeEnvironment.OperatingSystemVersion}", |
| 54 | + RuntimeInformation.RuntimeIdentifier); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments