Example #1
0
        public void IsOSPlatformEarlierThan_ReturnsFalse_ForOlderVersionOfCurrentOS(OSPlatform osPlatform)
        {
            // IsOSPlatformEarlierThan("xyz10.0") running as "xyz11.0" should return false

            Version current = Environment.OSVersion.Version;

            Version older = new Version(current.Major - 1, 0);

            Assert.False(RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{older}"));
            Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, older.Major));

            if (current.Minor > 0)
            {
                older = new Version(current.Major, current.Minor - 1);
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{older}"));
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, older.Major, older.Minor));
            }

            if (current.Build > 0)
            {
                older = new Version(current.Major, current.Minor, current.Build - 1);
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{older}"));
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, older.Major, older.Minor, older.Build));
            }

            if (current.Revision > 0)
            {
                older = new Version(current.Major, current.Minor, current.Build, current.Revision - 1);
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{older}"));
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, older.Major, older.Minor, older.Build, older.Revision));
            }
        }
Example #2
0
        public void IsOSPlatformEarlierThan_ReturnsFalse_ForCurrentOS(OSPlatform osPlatform)
        {
            // IsOSPlatformEarlierThan("xyz1.2.3.4") running as "xyz1.2.3.4" should return false

            Version current = Environment.OSVersion.Version;

            Assert.False(RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{current}"));

            Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, current.Major));

            if (current.Minor >= 0)
            {
                Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, current.Major, current.Minor));

                if (current.Build >= 0)
                {
                    Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, current.Major, current.Minor, current.Build));

                    if (current.Revision >= 0)
                    {
                        Assert.False(RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, current.Major, current.Minor, current.Build, current.Revision));
                    }
                }
            }
        }
Example #3
0
        public void IsOSPlatformEarlierThan_ReturnsTrue_ForNewerVersionOfCurrentOS(OSPlatform osPlatform)
        {
            // IsOSPlatformEarlierThan("xyz11.0") running as "xyz10.0" should return true

            bool    isCurrentPlatfom = RuntimeInformation.IsOSPlatform(osPlatform);
            Version current          = Environment.OSVersion.Version;

            Version newer = new Version(current.Major + 1, 0);

            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform.ToString().ToLower()}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform.ToString().ToUpper()}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, newer.Major));

            newer = new Version(current.Major, current.Minor + 1);
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, newer.Major, newer.Minor));

            newer = new Version(current.Major, current.Minor, current.Build + 1);
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, newer.Major, newer.Minor, newer.Build));

            newer = new Version(current.Major, current.Minor, current.Build, current.Revision + 1);
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan($"{osPlatform}{newer}"));
            Assert.Equal(isCurrentPlatfom, RuntimeInformation.IsOSPlatformEarlierThan(osPlatform, newer.Major, newer.Minor, newer.Build, newer.Revision));
        }
Example #4
0
 [InlineData("numbers1.2inplatformname1.2")] // numbers in platform names are not supported https://github.com/dotnet/runtime/pull/39005#discussion_r452644601
 public void IsOSPlatformEarlierThan_InvalidVersionNumber_ThrowsArgumentExceptionWithArgumentName(string platformName)
 {
     Assert.Throws <ArgumentException>("platformName", () => RuntimeInformation.IsOSPlatformEarlierThan(platformName));
 }
Example #5
0
 public void IsOSPlatformEarlierThan_Empty_ThrowsArgumentNullExceptionWithArgumentName()
 {
     Assert.Throws <ArgumentException>("platformName", () => RuntimeInformation.IsOSPlatformEarlierThan(string.Empty));
 }