Merge branch 'master' into merge/release/3.1-to-master\n\nCommit migrated from cf0d404196

This commit is contained in:
Pranav K 2019-12-04 17:30:50 -08:00 committed by GitHub
commit 6eef198ad0
42 changed files with 1025 additions and 531 deletions

View File

@ -34,7 +34,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
/// <summary> /// <summary>
/// Gets a <see cref="HealthStatus"/> representing the aggregate status of all the health checks. The value of <see cref="Status"/> /// Gets a <see cref="HealthStatus"/> representing the aggregate status of all the health checks. The value of <see cref="Status"/>
/// will be the most servere status reported by a health check. If no checks were executed, the value is always <see cref="HealthStatus.Healthy"/>. /// will be the most severe status reported by a health check. If no checks were executed, the value is always <see cref="HealthStatus.Healthy"/>.
/// </summary> /// </summary>
public HealthStatus Status { get; } public HealthStatus Status { get; }

View File

@ -2,7 +2,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" /> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.props))\Directory.Build.props" />
<PropertyGroup> <PropertyGroup>
<PackageId>@dotnet/jsinterop</PackageId> <PackageId>@microsoft/dotnet-js-interop</PackageId>
<IsPackable>true</IsPackable> <IsPackable>true</IsPackable>
<IsTestProject>false</IsTestProject> <IsTestProject>false</IsTestProject>
<IsShipping>true</IsShipping> <IsShipping>true</IsShipping>

View File

@ -1,6 +1,6 @@
{ {
"name": "@dotnet/jsinterop", "name": "@microsoft/dotnet-js-interop",
"version": "3.0.0-dev", "version": "5.0.0-dev",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@dotnet/jsinterop", "name": "@microsoft/dotnet-js-interop",
"version": "3.0.0-dev", "version": "5.0.0-dev",
"description": "Provides abstractions and features for interop between .NET and JavaScript code.", "description": "Provides abstractions and features for interop between .NET and JavaScript code.",
"main": "dist/Microsoft.JSInterop.js", "main": "dist/Microsoft.JSInterop.js",
"types": "dist/Microsoft.JSInterop.d.js", "types": "dist/Microsoft.JSInterop.d.js",

View File

@ -0,0 +1,3 @@
@ECHO OFF
%~dp0..\..\startvs.cmd %~dp0JSInterop.slnf

View File

@ -101,9 +101,8 @@ namespace Microsoft.Extensions.Localization
else else
{ {
// This expectation is defined by dotnet's automatic resource storage. // This expectation is defined by dotnet's automatic resource storage.
// We have to conform to "{RootNamespace}.{ResourceLocation}.{FullTypeName - AssemblyName}". // We have to conform to "{RootNamespace}.{ResourceLocation}.{FullTypeName - RootNamespace}".
var assemblyName = new AssemblyName(typeInfo.Assembly.FullName).Name; return baseNamespace + "." + resourcesRelativePath + TrimPrefix(typeInfo.FullName, baseNamespace + ".");
return baseNamespace + "." + resourcesRelativePath + TrimPrefix(typeInfo.FullName, assemblyName + ".");
} }
} }

View File

@ -0,0 +1,5 @@
using System.Reflection;
using Microsoft.Extensions.Localization;
[assembly: ResourceLocation("Resources")]
[assembly: RootNamespace("LocalizationTest.Abc")]

View File

@ -0,0 +1,9 @@
// 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.
namespace LocalizationTest.Abc.Controllers
{
public class ValuesController
{
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultNetCoreTargetFramework);net472</TargetFrameworks>
<RootNamespace>LocalizationTest.Abc</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Remove="NewFolder\**" />
<EmbeddedResource Remove="NewFolder\**" />
<None Remove="NewFolder\**" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Localization.Abstractions" />
<Reference Include="Microsoft.Extensions.Localization" />
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />
<Reference Include="Microsoft.Extensions.Logging.Testing" />
<Reference Include="Microsoft.Extensions.Options" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="ValuesController.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ValuesController.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="String1" xml:space="preserve">
<value>ValFromResource</value>
</data>
</root>

View File

@ -0,0 +1,26 @@
// 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 LocalizationTest.Abc.Controllers;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
namespace Microsoft.Extensions.Localization.RootNamespace.Tests
{
public class StringLocalizerOfTRootNamespaceTest
{
[Fact]
public void RootNamespace()
{
var locOptions = new LocalizationOptions();
var options = new Mock<IOptions<LocalizationOptions>>();
options.Setup(o => o.Value).Returns(locOptions);
var factory = new ResourceManagerStringLocalizerFactory(options.Object, NullLoggerFactory.Instance);
var valuesLoc = factory.Create(typeof(ValuesController));
Assert.Equal("ValFromResource", valuesLoc["String1"]);
}
}
}

View File

@ -0,0 +1,8 @@
// This namespace for test resources with alternative RootNamespace
namespace MyNamespace
{
public class Model
{
}
}

View File

@ -7,6 +7,7 @@ using System.Reflection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using MyNamespace;
using Moq; using Moq;
using Xunit; using Xunit;
@ -132,7 +133,7 @@ namespace Microsoft.Extensions.Localization.Tests
var loggerFactory = NullLoggerFactory.Instance; var loggerFactory = NullLoggerFactory.Instance;
var resourcePath = Path.Combine("My", "Resources"); var resourcePath = Path.Combine("My", "Resources");
var rootNamespace = "MyNamespace"; var rootNamespace = nameof(MyNamespace);
var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace); var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace);
var typeFactory = new TestResourceManagerStringLocalizerFactory( var typeFactory = new TestResourceManagerStringLocalizerFactory(
@ -141,12 +142,13 @@ namespace Microsoft.Extensions.Localization.Tests
rootNamespaceAttribute: rootNamespaceAttribute, rootNamespaceAttribute: rootNamespaceAttribute,
loggerFactory: loggerFactory); loggerFactory: loggerFactory);
var type = typeof(ResourceManagerStringLocalizerFactoryTest); var type = typeof(Model);
// Act // Act
typeFactory.Create(type); typeFactory.Create(type);
// Assert // Assert
Assert.Equal($"Microsoft.Extensions.Localization.Tests.ResourceManagerStringLocalizerFactoryTest", typeFactory.BaseName); Assert.Equal($"{rootNamespace}.{nameof(Model)}", typeFactory.BaseName);
} }
[Fact] [Fact]
@ -159,7 +161,7 @@ namespace Microsoft.Extensions.Localization.Tests
var loggerFactory = NullLoggerFactory.Instance; var loggerFactory = NullLoggerFactory.Instance;
var resourcePath = Path.Combine("My", "Resources"); var resourcePath = Path.Combine("My", "Resources");
var rootNamespace = "MyNamespace"; var rootNamespace = nameof(MyNamespace);
var resourceLocationAttribute = new ResourceLocationAttribute(resourcePath); var resourceLocationAttribute = new ResourceLocationAttribute(resourcePath);
var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace); var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace);
@ -169,12 +171,13 @@ namespace Microsoft.Extensions.Localization.Tests
rootNamespaceAttribute, rootNamespaceAttribute,
loggerFactory); loggerFactory);
var type = typeof(ResourceManagerStringLocalizerFactoryTest); var type = typeof(Model);
// Act // Act
typeFactory.Create(type); typeFactory.Create(type);
// Assert // Assert
Assert.Equal($"MyNamespace.My.Resources.ResourceManagerStringLocalizerFactoryTest", typeFactory.BaseName); Assert.Equal($"{rootNamespace}.My.Resources.{nameof(Model)}", typeFactory.BaseName);
} }
[Fact] [Fact]

View File

@ -34,6 +34,8 @@ namespace BenchmarkDotNet.Attributes
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.0", null, ".NET Core 3.0"))) .With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.0", null, ".NET Core 3.0")))
#elif NETCOREAPP3_1 #elif NETCOREAPP3_1
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.1", null, ".NET Core 3.1"))) .With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp3.1", null, ".NET Core 3.1")))
#elif NETCOREAPP5_0
.With(CsProjCoreToolchain.From(new NetCoreAppSettings("netcoreapp5.0", null, ".NET Core 5.0")))
#else #else
#error Target frameworks need to be updated. #error Target frameworks need to be updated.
#endif #endif

View File

@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace Microsoft.Extensions.Internal namespace Microsoft.Extensions.Internal
{ {
internal class TypeNameHelper internal static class TypeNameHelper
{ {
private const char DefaultNestedTypeDelimiter = '+'; private const char DefaultNestedTypeDelimiter = '+';

View File

@ -170,6 +170,13 @@ namespace Microsoft.AspNetCore.Testing
System.Threading.Tasks.Task OnTestStartAsync(Microsoft.AspNetCore.Testing.TestContext context, System.Threading.CancellationToken cancellationToken); System.Threading.Tasks.Task OnTestStartAsync(Microsoft.AspNetCore.Testing.TestContext context, System.Threading.CancellationToken cancellationToken);
} }
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)] [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public partial class MaximumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
{
public MaximumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string maxVersion) { }
public bool IsMet { get { throw null; } }
public string SkipReason { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public partial class MinimumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition public partial class MinimumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
{ {
public MinimumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string minVersion) { } public MinimumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string minVersion) { }
@ -319,9 +326,11 @@ namespace Microsoft.AspNetCore.Testing
public static partial class WindowsVersions public static partial class WindowsVersions
{ {
public const string Win10 = "10.0"; public const string Win10 = "10.0";
public const string Win10_19H1 = "10.0.18362";
public const string Win10_19H2 = "10.0.18363"; public const string Win10_19H2 = "10.0.18363";
public const string Win10_20H1 = "10.0.18990"; public const string Win10_20H1 = "10.0.19033";
public const string Win10_RS4 = "10.0.17134"; public const string Win10_RS4 = "10.0.17134";
public const string Win10_RS5 = "10.0.17763";
public const string Win2008R2 = "6.1"; public const string Win2008R2 = "6.1";
public const string Win7 = "6.1"; public const string Win7 = "6.1";
public const string Win8 = "6.2"; public const string Win8 = "6.2";

View File

@ -170,6 +170,13 @@ namespace Microsoft.AspNetCore.Testing
System.Threading.Tasks.Task OnTestStartAsync(Microsoft.AspNetCore.Testing.TestContext context, System.Threading.CancellationToken cancellationToken); System.Threading.Tasks.Task OnTestStartAsync(Microsoft.AspNetCore.Testing.TestContext context, System.Threading.CancellationToken cancellationToken);
} }
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)] [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public partial class MaximumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
{
public MaximumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string maxVersion) { }
public bool IsMet { get { throw null; } }
public string SkipReason { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public partial class MinimumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition public partial class MinimumOSVersionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
{ {
public MinimumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string minVersion) { } public MinimumOSVersionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, string minVersion) { }
@ -319,9 +326,11 @@ namespace Microsoft.AspNetCore.Testing
public static partial class WindowsVersions public static partial class WindowsVersions
{ {
public const string Win10 = "10.0"; public const string Win10 = "10.0";
public const string Win10_19H1 = "10.0.18362";
public const string Win10_19H2 = "10.0.18363"; public const string Win10_19H2 = "10.0.18363";
public const string Win10_20H1 = "10.0.18990"; public const string Win10_20H1 = "10.0.19033";
public const string Win10_RS4 = "10.0.17134"; public const string Win10_RS4 = "10.0.17134";
public const string Win10_RS5 = "10.0.17763";
public const string Win2008R2 = "6.1"; public const string Win2008R2 = "6.1";
public const string Win7 = "6.1"; public const string Win7 = "6.1";
public const string Win8 = "6.2"; public const string Win8 = "6.2";

View File

@ -0,0 +1,83 @@
// 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
{
/// <summary>
/// Skips a test if the OS is the given type (Windows) and the OS version is greater than specified.
/// E.g. Specifying Window 8 skips on Win 10, but not on Linux. Combine with OSSkipConditionAttribute as needed.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
public class MaximumOSVersionAttribute : Attribute, ITestCondition
{
private readonly OperatingSystems _targetOS;
private readonly Version _maxVersion;
private readonly OperatingSystems _currentOS;
private readonly Version _currentVersion;
private readonly bool _skip;
public MaximumOSVersionAttribute(OperatingSystems operatingSystem, string maxVersion) :
this(operatingSystem, Version.Parse(maxVersion), GetCurrentOS(), GetCurrentOSVersion())
{
}
// to enable unit testing
internal MaximumOSVersionAttribute(OperatingSystems targetOS, Version maxVersion, OperatingSystems currentOS, Version currentVersion)
{
if (targetOS != OperatingSystems.Windows)
{
throw new NotImplementedException("Max version support is only implemented for Windows.");
}
_targetOS = targetOS;
_maxVersion = maxVersion;
_currentOS = currentOS;
// We drop the 4th field because it is not significant and it messes up the comparisons.
_currentVersion = new Version(currentVersion.Major, currentVersion.Minor,
// Major and Minor are required by the parser, but if Build isn't specified then it returns -1
// which the constructor rejects.
currentVersion.Build == -1 ? 0 : currentVersion.Build);
// Do not skip other OS's, Use OSSkipConditionAttribute or a separate MaximumOsVersionAttribute for that.
_skip = _targetOS == _currentOS && _maxVersion < _currentVersion;
SkipReason = $"This test requires {_targetOS} {_maxVersion} or earlier.";
}
// Since a test would be executed only if 'IsMet' is true, return false if we want to skip
public bool IsMet => !_skip;
public string SkipReason { get; set; }
private static 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 implemented, but this will still be called before the OS check happens so don't throw.
return new Version(0, 0);
}
}
}
}

View File

@ -23,14 +23,24 @@ namespace Microsoft.AspNetCore.Testing
/// </summary> /// </summary>
public const string Win10_RS4 = "10.0.17134"; public const string Win10_RS4 = "10.0.17134";
/// <summary>
/// 1809, RS5, 17763
/// </summary>
public const string Win10_RS5 = "10.0.17763";
/// <summary>
/// 1903, 19H1, 18362
/// </summary>
public const string Win10_19H1 = "10.0.18362";
/// <summary> /// <summary>
/// 1909, 19H2, 18363 /// 1909, 19H2, 18363
/// </summary> /// </summary>
public const string Win10_19H2 = "10.0.18363"; public const string Win10_19H2 = "10.0.18363";
/// <summary> /// <summary>
/// _, 20H2, 18990 /// 2004, 20H1, 19033
/// </summary> /// </summary>
public const string Win10_20H1 = "10.0.18990"; public const string Win10_20H1 = "10.0.19033";
} }
} }

View File

@ -0,0 +1,89 @@
// 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 Xunit;
namespace Microsoft.AspNetCore.Testing
{
public class MaximumOSVersionAttributeTest
{
[Fact]
public void Linux_ThrowsNotImplemeneted()
{
Assert.Throws<NotImplementedException>(() => new MaximumOSVersionAttribute(OperatingSystems.Linux, "2.5"));
}
[Fact]
public void Mac_ThrowsNotImplemeneted()
{
Assert.Throws<NotImplementedException>(() => new MaximumOSVersionAttribute(OperatingSystems.MacOSX, "2.5"));
}
[Fact]
public void WindowsOrLinux_ThrowsNotImplemeneted()
{
Assert.Throws<NotImplementedException>(() => new MaximumOSVersionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, "2.5"));
}
[Fact]
public void DoesNotSkip_ShortVersions()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5"),
OperatingSystems.Windows,
new Version("2.0"));
Assert.True(osSkipAttribute.IsMet);
}
[Fact]
public void DoesNotSkip_EarlierVersions()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5.9"),
OperatingSystems.Windows,
new Version("2.0.10.12"));
Assert.True(osSkipAttribute.IsMet);
}
[Fact]
public void DoesNotSkip_SameVersion()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5.10"),
OperatingSystems.Windows,
new Version("2.5.10.12"));
Assert.True(osSkipAttribute.IsMet);
}
[Fact]
public void Skip_LaterVersion()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5.11"),
OperatingSystems.Windows,
new Version("3.0.10.12"));
Assert.False(osSkipAttribute.IsMet);
}
[Fact]
public void DoesNotSkip_WhenOnlyVersionsMatch()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5.10.12"),
OperatingSystems.Linux,
new Version("2.5.10.12"));
Assert.True(osSkipAttribute.IsMet);
}
}
}

View File

@ -0,0 +1,90 @@
// 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;
using Microsoft.Win32;
using Xunit;
namespace Microsoft.AspNetCore.Testing
{
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public class MaximumOSVersionTest
{
[ConditionalFact]
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
public void RunTest_Win7DoesRunOnWin7()
{
Assert.True(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.ToString().StartsWith("6.1"),
"Test should only be running on Win7 or Win2008R2.");
}
[ConditionalTheory]
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
[InlineData(1)]
public void RunTheory_Win7DoesRunOnWin7(int arg)
{
Assert.True(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.ToString().StartsWith("6.1"),
"Test should only be running on Win7 or Win2008R2.");
}
[ConditionalFact]
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_RS4)]
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public void RunTest_Win10_RS4()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
var versionKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
Assert.NotNull(versionKey);
var currentVersion = (string)versionKey.GetValue("CurrentBuildNumber");
Assert.NotNull(currentVersion);
Assert.True(17134 >= int.Parse(currentVersion));
}
[ConditionalFact]
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H2)]
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public void RunTest_Win10_19H2()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
var versionKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
Assert.NotNull(versionKey);
var currentVersion = (string)versionKey.GetValue("CurrentBuildNumber");
Assert.NotNull(currentVersion);
Assert.True(18363 >= int.Parse(currentVersion));
}
}
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
public class OSMaxVersionClassTest
{
[ConditionalFact]
public void TestSkipClass_Win7DoesRunOnWin7()
{
Assert.True(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
Environment.OSVersion.Version.ToString().StartsWith("6.1"),
"Test should only be running on Win7 or Win2008R2.");
}
}
// Let this one run cross plat just to check the constructor logic.
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
public class OSMaxVersionCrossPlatTest
{
[ConditionalFact]
public void TestSkipClass_Win7DoesRunOnWin7()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.True(Environment.OSVersion.Version.ToString().StartsWith("6.1"),
"Test should only be running on Win7 or Win2008R2.");
}
}
}
}