[automated] Merge branch 'release/3.1' => 'master'
\n\nCommit migrated from bae710c8bb
This commit is contained in:
commit
c94dc7c854
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.Win32;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
|
|
@ -14,49 +13,36 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
|
||||||
public class MinimumOSVersionAttribute : Attribute, ITestCondition
|
public class MinimumOSVersionAttribute : Attribute, ITestCondition
|
||||||
{
|
{
|
||||||
private readonly OperatingSystems _excludedOperatingSystem;
|
private readonly OperatingSystems _targetOS;
|
||||||
private readonly Version _minVersion;
|
private readonly Version _minVersion;
|
||||||
private readonly OperatingSystems _osPlatform;
|
private readonly OperatingSystems _currentOS;
|
||||||
private readonly Version _osVersion;
|
private readonly Version _currentVersion;
|
||||||
|
private readonly bool _skip;
|
||||||
|
|
||||||
public MinimumOSVersionAttribute(OperatingSystems operatingSystem, string minVersion) :
|
public MinimumOSVersionAttribute(OperatingSystems operatingSystem, string minVersion) :
|
||||||
this(
|
this(operatingSystem, Version.Parse(minVersion), GetCurrentOS(), GetCurrentOSVersion())
|
||||||
operatingSystem,
|
|
||||||
GetCurrentOS(),
|
|
||||||
GetCurrentOSVersion(),
|
|
||||||
Version.Parse(minVersion))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// to enable unit testing
|
// to enable unit testing
|
||||||
internal MinimumOSVersionAttribute(
|
internal MinimumOSVersionAttribute(OperatingSystems targetOS, Version minVersion, OperatingSystems currentOS, Version currentVersion)
|
||||||
OperatingSystems operatingSystem, OperatingSystems osPlatform, Version osVersion, Version minVersion)
|
|
||||||
{
|
{
|
||||||
if (operatingSystem != OperatingSystems.Windows)
|
if (targetOS != OperatingSystems.Windows)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException("Min version support is only implemented for Windows.");
|
throw new NotImplementedException("Min version support is only implemented for Windows.");
|
||||||
}
|
}
|
||||||
_excludedOperatingSystem = operatingSystem;
|
_targetOS = targetOS;
|
||||||
_minVersion = minVersion;
|
_minVersion = minVersion;
|
||||||
_osPlatform = osPlatform;
|
_currentOS = currentOS;
|
||||||
_osVersion = osVersion;
|
_currentVersion = currentVersion;
|
||||||
|
|
||||||
SkipReason = $"This test requires {_excludedOperatingSystem} {_minVersion} or later.";
|
// Do not skip other OS's, Use OSSkipConditionAttribute or a separate MinimumOSVersionAttribute for that.
|
||||||
|
_skip = _targetOS == _currentOS && _minVersion > _currentVersion;
|
||||||
|
SkipReason = $"This test requires {_targetOS} {_minVersion} or later.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsMet
|
// Since a test would be executed only if 'IsMet' is true, return false if we want to skip
|
||||||
{
|
public bool IsMet => !_skip;
|
||||||
get
|
|
||||||
{
|
|
||||||
// Do not skip other OS's, Use OSSkipConditionAttribute or a separate MinimumOSVersionAttribute for that.
|
|
||||||
if (_osPlatform != _excludedOperatingSystem)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _osVersion >= _minVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SkipReason { get; set; }
|
public string SkipReason { get; set; }
|
||||||
|
|
||||||
|
|
@ -77,34 +63,16 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
throw new PlatformNotSupportedException();
|
throw new PlatformNotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Version GetCurrentOSVersion()
|
static private Version GetCurrentOSVersion()
|
||||||
{
|
{
|
||||||
// currently not used on other OS's
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
// Win10+
|
|
||||||
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
|
|
||||||
var major = key.GetValue("CurrentMajorVersionNumber") as int?;
|
|
||||||
var minor = key.GetValue("CurrentMinorVersionNumber") as int?;
|
|
||||||
|
|
||||||
if (major.HasValue && minor.HasValue)
|
|
||||||
{
|
|
||||||
return new Version(major.Value, minor.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CurrentVersion doesn't work past Win8.1
|
|
||||||
var current = key.GetValue("CurrentVersion") as string;
|
|
||||||
if (!string.IsNullOrEmpty(current) && Version.TryParse(current, out var currentVersion))
|
|
||||||
{
|
|
||||||
return currentVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Environment.OSVersion doesn't work past Win8.
|
|
||||||
return Environment.OSVersion.Version;
|
return Environment.OSVersion.Version;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new Version();
|
// Not implemented, but this will still be called before the OS check happens so don't throw.
|
||||||
|
return new Version(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
|
||||||
{
|
|
||||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
|
|
||||||
public class OSMinVersionAttribute : Attribute, ITestCondition
|
|
||||||
{
|
|
||||||
private readonly OperatingSystems _targetOS;
|
|
||||||
private readonly Version _minVersion;
|
|
||||||
private readonly OperatingSystems _currentOS;
|
|
||||||
private readonly Version _currentVersion;
|
|
||||||
private readonly bool _skip;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Used to indicate the minimum version a test can run on for the given operating system.
|
|
||||||
/// Also add <see cref="OSSkipConditionAttribute"/> to skip other operating systems.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="targetOS">The OS to check for a version. Only Windows is currently supported.</param>
|
|
||||||
/// <param name="minVersion">The minimum OS version NOT to skip.</param>
|
|
||||||
public OSMinVersionAttribute(OperatingSystems targetOS, string minVersion) :
|
|
||||||
this(targetOS, Version.Parse(minVersion), GetCurrentOS(), GetCurrentOSVersion())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// to enable unit testing
|
|
||||||
internal OSMinVersionAttribute(OperatingSystems targetOS, Version minVersion, OperatingSystems currentOS, Version currentVersion)
|
|
||||||
{
|
|
||||||
if (targetOS != OperatingSystems.Windows)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException(targetOS.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
_targetOS = targetOS;
|
|
||||||
_minVersion = minVersion;
|
|
||||||
_currentOS = currentOS;
|
|
||||||
_currentVersion = currentVersion;
|
|
||||||
|
|
||||||
_skip = _targetOS == _currentOS && _minVersion > _currentVersion;
|
|
||||||
SkipReason = $"The test cannot run on this operating system version '{currentVersion}'.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since a test would be excuted only if 'IsMet' is true, return false if we want to skip
|
|
||||||
public bool IsMet => !_skip;
|
|
||||||
|
|
||||||
public string SkipReason { get; set; }
|
|
||||||
|
|
||||||
static private OperatingSystems GetCurrentOS()
|
|
||||||
{
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
return OperatingSystems.Windows;
|
|
||||||
}
|
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
{
|
|
||||||
return OperatingSystems.Linux;
|
|
||||||
}
|
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
||||||
{
|
|
||||||
return OperatingSystems.MacOSX;
|
|
||||||
}
|
|
||||||
throw new PlatformNotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
static private Version GetCurrentOSVersion()
|
|
||||||
{
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
return Environment.OSVersion.Version;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Not implmeneted, but this will still be called before the OS check happens so don't throw.
|
|
||||||
return new Version(0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,30 +6,30 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
public class OSMinVersionAttributeTest
|
public class MinimumOSVersionAttributeTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Linux_ThrowsNotImplemeneted()
|
public void Linux_ThrowsNotImplemeneted()
|
||||||
{
|
{
|
||||||
Assert.Throws<NotImplementedException>(() => new OSMinVersionAttribute(OperatingSystems.Linux, "2.5"));
|
Assert.Throws<NotImplementedException>(() => new MinimumOSVersionAttribute(OperatingSystems.Linux, "2.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Mac_ThrowsNotImplemeneted()
|
public void Mac_ThrowsNotImplemeneted()
|
||||||
{
|
{
|
||||||
Assert.Throws<NotImplementedException>(() => new OSMinVersionAttribute(OperatingSystems.MacOSX, "2.5"));
|
Assert.Throws<NotImplementedException>(() => new MinimumOSVersionAttribute(OperatingSystems.MacOSX, "2.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WindowsOrLinux_ThrowsNotImplemeneted()
|
public void WindowsOrLinux_ThrowsNotImplemeneted()
|
||||||
{
|
{
|
||||||
Assert.Throws<NotImplementedException>(() => new OSMinVersionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, "2.5"));
|
Assert.Throws<NotImplementedException>(() => new MinimumOSVersionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, "2.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DoesNotSkip_LaterVersions()
|
public void DoesNotSkip_LaterVersions()
|
||||||
{
|
{
|
||||||
var osSkipAttribute = new OSMinVersionAttribute(
|
var osSkipAttribute = new MinimumOSVersionAttribute(
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
new Version("2.0"),
|
new Version("2.0"),
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DoesNotSkip_SameVersion()
|
public void DoesNotSkip_SameVersion()
|
||||||
{
|
{
|
||||||
var osSkipAttribute = new OSMinVersionAttribute(
|
var osSkipAttribute = new MinimumOSVersionAttribute(
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
new Version("2.5"),
|
new Version("2.5"),
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Skip_EarlierVersion()
|
public void Skip_EarlierVersion()
|
||||||
{
|
{
|
||||||
var osSkipAttribute = new OSMinVersionAttribute(
|
var osSkipAttribute = new MinimumOSVersionAttribute(
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
new Version("3.0"),
|
new Version("3.0"),
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DoesNotSkip_WhenOnlyVersionsMatch()
|
public void DoesNotSkip_WhenOnlyVersionsMatch()
|
||||||
{
|
{
|
||||||
var osSkipAttribute = new OSMinVersionAttribute(
|
var osSkipAttribute = new MinimumOSVersionAttribute(
|
||||||
OperatingSystems.Windows,
|
OperatingSystems.Windows,
|
||||||
new Version("2.5"),
|
new Version("2.5"),
|
||||||
OperatingSystems.Linux,
|
OperatingSystems.Linux,
|
||||||
|
|
@ -8,10 +8,10 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
public class OSMinVersionTest
|
public class MinimumOSVersionTest
|
||||||
{
|
{
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[OSMinVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
||||||
public void RunTest_Win8DoesNotRunOnWin7()
|
public void RunTest_Win8DoesNotRunOnWin7()
|
||||||
{
|
{
|
||||||
Assert.False(
|
Assert.False(
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSMinVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
||||||
[InlineData(1)]
|
[InlineData(1)]
|
||||||
public void RunTheory_Win8DoesNotRunOnWin7(int arg)
|
public void RunTheory_Win8DoesNotRunOnWin7(int arg)
|
||||||
{
|
{
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[OSMinVersion(OperatingSystems.Windows, WindowsVersions.Win10_RS4)]
|
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_RS4)]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
public void RunTest_Win10_RS4()
|
public void RunTest_Win10_RS4()
|
||||||
{
|
{
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
[OSMinVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H2)]
|
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H2)]
|
||||||
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
|
||||||
public void RunTest_Win10_19H2()
|
public void RunTest_Win10_19H2()
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[OSMinVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win8)]
|
||||||
public class OSMinVersionClassTest
|
public class OSMinVersionClassTest
|
||||||
{
|
{
|
||||||
[ConditionalFact]
|
[ConditionalFact]
|
||||||
Loading…
Reference in New Issue