public void IsOSPlatformOrLater_ReturnsTrue_ForCurrentOS(OSPlatform osPlatform) { // IsOSPlatformOrLater("xyz1.2.3.4") running as "xyz1.2.3.4" should return true bool isCurrentPlatfom = RuntimeInformation.IsOSPlatform(osPlatform); Version current = Environment.OSVersion.Version; Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{current}")); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, current.Major)); if (current.Minor >= 0) { Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, current.Major, current.Minor)); if (current.Build >= 0) { Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, current.Major, current.Minor, current.Build)); if (current.Revision >= 0) { Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, current.Major, current.Minor, current.Build, current.Revision)); } } } }
public void IsOSPlatformOrLater_ReturnsTrue_ForOlderVersionOfCurrentOS(OSPlatform osPlatform) { // IsOSPlatformOrLater("xyz10.0") running as "xyz11.0" should return true bool isCurrentPlatfom = RuntimeInformation.IsOSPlatform(osPlatform); Version current = Environment.OSVersion.Version; Version older = new Version(current.Major - 1, 0); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{older}")); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, older.Major)); if (current.Minor > 0) { older = new Version(current.Major, current.Minor - 1); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{older}")); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, older.Major, older.Minor)); } if (current.Build > 0) { older = new Version(current.Major, current.Minor, current.Build - 1); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{older}")); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, older.Major, older.Minor, older.Build)); } if (current.Revision > 0) { older = new Version(current.Major, current.Minor, current.Build, current.Revision - 1); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{older}")); Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformOrLater(osPlatform, older.Major, older.Minor, older.Build, older.Revision)); } }
public void IsOSPlatformOrLater_ReturnsFalse_ForNewerVersionOfCurrentOS(OSPlatform osPlatform) { // IsOSPlatformOrLater("xyz11.0") running as "xyz10.0" should return false Version currentVersion = Environment.OSVersion.Version; Version newer = new Version(currentVersion.Major + 1, 0); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform.ToString().ToLower()}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform.ToString().ToUpper()}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater(osPlatform, newer.Major)); newer = new Version(currentVersion.Major, currentVersion.Minor + 1); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater(osPlatform, newer.Major, newer.Minor)); newer = new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build + 1); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater(osPlatform, newer.Major, newer.Minor, newer.Build)); newer = new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build, currentVersion.Revision + 1); Assert.False(RuntimeInformation.IsOSPlatformOrLater($"{osPlatform}{newer}")); Assert.False(RuntimeInformation.IsOSPlatformOrLater(osPlatform, newer.Major, newer.Minor, newer.Build, newer.Revision)); }
[InlineData("numbers1.2inplatformname1.2")] // numbers in platform names are not supported https://github.com/dotnet/runtime/pull/39005#discussion_r452644601 public void IsOSPlatformOrLater_InvalidVersionNumber_ThrowsArgumentExceptionWithArgumentName(string platformName) { Assert.Throws <ArgumentException>("platformName", () => RuntimeInformation.IsOSPlatformOrLater(platformName)); }
public void IsOSPlatformOrLater_Empty_ThrowsArgumentNullExceptionWithArgumentName() { Assert.Throws <ArgumentException>("platformName", () => RuntimeInformation.IsOSPlatformOrLater(string.Empty)); }
public void IsOSPlatformOrLater_Null_ThrowsArgumentNullExceptionWithArgumentName() { Assert.Throws <ArgumentNullException>("platformName", () => RuntimeInformation.IsOSPlatformOrLater(null)); }