Merge branch 'update-e2e-tests' into add-latest-patch-syntax
commit
e0a32d6459
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace test_csproj
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class Test
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void TestMethod()
|
||||||
|
{
|
||||||
|
Console.WriteLine("TestMethod");
|
||||||
|
int calculatedResult = 1000 / 25;
|
||||||
|
int expectedResult = 40;
|
||||||
|
Assert.AreEqual(calculatedResult, expectedResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>$(TEST_TARGET_FRAMEWORK)</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- These packages will be downloaded over the network for testing proxy settings -->
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0-preview-20170810-02" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -1,18 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFrameworks>netcoreapp3.1;netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
|
|
||||||
<RootNamespace>sample_csproj</RootNamespace>
|
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- These packages will be downloaded over the network for testing proxy settings -->
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
|
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
|
|
||||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,73 +1,117 @@
|
|||||||
if (!$args[0])
|
<#
|
||||||
{
|
.DESCRIPTION
|
||||||
throw "Must supply dotnet version argument"
|
Verifies that installed on the machine .NET SDK versions match the input patterns.
|
||||||
|
Optionally checks that the nuget.config file is generated correctly.
|
||||||
|
|
||||||
|
.PARAMETER Patterns
|
||||||
|
Specifies the regular expression patterns that should be matched with the installed
|
||||||
|
on the machine .NET SDK versions. The number of patterns should be equal to the number
|
||||||
|
of installed .NET versions.
|
||||||
|
|
||||||
|
.PARAMETER CheckNugetConfig
|
||||||
|
Switches the check for the existence of the nuget.config file.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
PS> .\verify-dotnet.ps1 -Paterns "^3.1.200$", "^6.0" -CheckNugetConfig
|
||||||
|
#>
|
||||||
|
|
||||||
|
param(
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string[]]$Patterns,
|
||||||
|
[switch]$CheckNugetConfig
|
||||||
|
)
|
||||||
|
|
||||||
|
$PatternsList = [System.Collections.ArrayList]($Patterns)
|
||||||
|
|
||||||
|
if ($CheckNugetConfig.IsPresent -and !(Test-Path "../nuget.config")) {
|
||||||
|
throw "The nuget.config file is not generated correctly."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-Host "These patterns were supplied to the script: $($PatternsList -join ', ')."
|
||||||
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
|
$dotnet = Get-Command dotnet | Select-Object -First 1 | ForEach-Object { $_.Path }
|
||||||
Write-Host "Found '$dotnet'"
|
Write-Host "Found: '$dotnet'"
|
||||||
|
|
||||||
if($args.count -eq 1)
|
# SDKs are listed on multiple lines with the path afterwards in square brackets
|
||||||
{
|
$Versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
|
||||||
$version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() }
|
Write-Host "Found installed versions: $($Versions -join ', ')."
|
||||||
Write-Host "Version $version"
|
$InstalledVersionCount = $Versions.Count
|
||||||
if (-not ($version.StartsWith($args[0].ToString())))
|
|
||||||
{
|
|
||||||
Write-Host "PATH='$env:PATH'"
|
|
||||||
throw "Unexpected version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args[1])
|
foreach($version in $Versions)
|
||||||
{
|
{
|
||||||
# SDKs are listed on multiple lines with the path afterwards in square brackets
|
foreach($pattern in $PatternsList)
|
||||||
$versions = & $dotnet --list-sdks | ForEach-Object { $_.SubString(0, $_.IndexOf('[')).Trim() }
|
|
||||||
Write-Host "Installed versions: $versions"
|
|
||||||
$InstalledVersionCount = 0
|
|
||||||
foreach($arg in $args){
|
|
||||||
foreach ($version in $versions)
|
|
||||||
{
|
{
|
||||||
if ($version.StartsWith($arg.ToString()))
|
if ($version -match $pattern)
|
||||||
{
|
{
|
||||||
$InstalledVersionCount++
|
$PatternsList.Remove($pattern)
|
||||||
}
|
$InstalledVersionCount--
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $InstalledVersionCount -ne $args.Count)
|
|
||||||
{
|
|
||||||
Write-Host "PATH='$env:PATH'"
|
|
||||||
throw "Unexpected version"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Building sample csproj"
|
if ( $InstalledVersionCount -ne 0)
|
||||||
& $dotnet build __tests__/sample-csproj/ --no-cache
|
|
||||||
if ($LASTEXITCODE -ne 0)
|
|
||||||
{
|
{
|
||||||
throw "Unexpected exit code $LASTEXITCODE"
|
throw "An unexpected version of Dotnet is found on the machine, please check the correctness of the -Patterns input."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Testing compiled app"
|
$workingDir = Get-Location
|
||||||
$sample_output = "$(dotnet test __tests__/sample-csproj/ --no-build)"
|
$testProjectDir = "./__tests__/e2e-test-csproj"
|
||||||
Write-Host "Sample output: $sample_output"
|
Write-Host "Changing directory to the $testProjectDir"
|
||||||
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
|
Set-Location $testProjectDir
|
||||||
if ($args[1])
|
|
||||||
|
$targetFrameworkVersionMap = @{
|
||||||
|
"1.0" = "netcoreapp1.0";
|
||||||
|
"1.1" = "netcoreapp1.1";
|
||||||
|
"2.0" = "netcoreapp2.0";
|
||||||
|
"2.1" = "netcoreapp2.1";
|
||||||
|
"2.2" = "netcoreapp2.2";
|
||||||
|
"3.0" = "netcoreapp3.0";
|
||||||
|
"3.1" = "netcoreapp3.1";
|
||||||
|
"5.0" = "net5.0";
|
||||||
|
"6.0" = "net6.0";
|
||||||
|
"7.0" = "net7.0";
|
||||||
|
"8.0" = "net8.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($version in $Versions)
|
||||||
{
|
{
|
||||||
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*")
|
# Creating temporary global.json file inside e2e-test-csproj dir and setting exact version of .NET inside allows to override default behavior of .NET and run build and tests on that exact version.
|
||||||
|
Write-Host "Creating temporary global.json file for $version .NET version."
|
||||||
|
& $dotnet new globaljson --sdk-version $version --force | Out-Null
|
||||||
|
if (!(Test-Path "./global.json"))
|
||||||
{
|
{
|
||||||
throw "Unexpected output"
|
throw "An error occured while creating the global.json file. Exit code: $LASTEXITCODE"
|
||||||
}
|
}
|
||||||
}
|
Write-Host "The global.json file for the version $version is created. Currently used .NET version is: $(& $dotnet --version)."
|
||||||
if ($args[2])
|
|
||||||
{
|
# Environment variable TEST_TARGET_FRAMEWORK is used inside the test.csproj file to target required framework version
|
||||||
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*Test Run Successful.*")
|
$version -match "^(?<key>\d+\.\d+)" | Out-Null
|
||||||
|
if (!($targetFrameworkVersionMap.ContainsKey($Matches.key)))
|
||||||
{
|
{
|
||||||
throw "Unexpected output"
|
throw "The map with the framework targets doesn't contain a target name for the version $version."
|
||||||
}
|
}
|
||||||
}
|
Write-Host "Setting the TEST_TARGET_FRAMEWORK environment variable to $($targetFrameworkVersionMap[$Matches.key])"
|
||||||
else
|
[Environment]::SetEnvironmentVariable('TEST_TARGET_FRAMEWORK', $($targetFrameworkVersionMap[$Matches.key]))
|
||||||
{
|
|
||||||
if ($sample_output -notlike "*Test Run Successful.*")
|
Write-Host "Building test C# project with $version .NET version."
|
||||||
|
& $dotnet build --no-cache
|
||||||
|
if ($LASTEXITCODE -ne 0)
|
||||||
|
{
|
||||||
|
throw "Building process is not successful, exit code: $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Testing compiled C# project with $version .NET version."
|
||||||
|
& $dotnet test --no-build
|
||||||
|
if ($LASTEXITCODE -ne 0)
|
||||||
{
|
{
|
||||||
throw "Unexpected output"
|
throw "Testing process is not successful, exit code: $LASTEXITCODE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-Host "Tests are completed successfully!"
|
||||||
|
|
||||||
|
Write-Host "Removing temporary global.json file."
|
||||||
|
Remove-Item ./global.json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set-Location $workingDir
|
@ -1,44 +0,0 @@
|
|||||||
if [ -z "$1" ]; then
|
|
||||||
echo "Must supply dotnet version argument"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "../nuget.config" ]; then
|
|
||||||
echo "nuget file not generated correctly"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
dotnet_version="$(dotnet --version)"
|
|
||||||
echo "Found dotnet version '$dotnet_version'"
|
|
||||||
if [ -z "$(echo $dotnet_version | grep $1)" ]; then
|
|
||||||
echo "Unexpected version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$2" ]; then
|
|
||||||
dotnet_version="$(dotnet --list-sdks)"
|
|
||||||
echo "Found dotnet version '$dotnet_version'"
|
|
||||||
if [ -z "$(echo $dotnet_version | grep $2)" ]; then
|
|
||||||
echo "Unexpected version"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Building sample csproj"
|
|
||||||
dotnet build __tests__/sample-csproj/ --no-cache || exit 1
|
|
||||||
|
|
||||||
echo "Testing compiled app"
|
|
||||||
sample_output=$(dotnet test __tests__/sample-csproj/ --no-build)
|
|
||||||
echo "Sample output: $sample_output"
|
|
||||||
# For Side-by-Side installs we want to run the tests twice, for a single install the tests will run once
|
|
||||||
if [ -n "$2" ]; then
|
|
||||||
if [ -z "$(echo $sample_output | grep "Test Run Successful.*Test Run Successful.")" ]; then
|
|
||||||
echo "Unexpected output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ -z "$(echo $sample_output | grep "Test Run Successful.")" ]; then
|
|
||||||
echo "Unexpected output"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
Loading…
Reference in New Issue