Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Update e2e tests
IvanZosimov
committed
Apr 13, 2023
1 parent
920b830
commit b72f430
Showing
6 changed files
with
117 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace test_csproj | ||
{ | ||
[TestClass] | ||
public class Test | ||
{ | ||
[TestMethod] | ||
public void TestMethod() | ||
{ | ||
Assert.AreEqual((1 + 1), 2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(TEST_TARGET_FRAMEWORK)</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<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> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,96 @@ | ||
if (!$args[0]) | ||
param( | ||
[ValidateNotNullOrEmpty()] | ||
[string[]]$Patterns, | ||
[ValidateNotNullOrEmpty()] | ||
[string]$ContainedPattern, | ||
[switch]$CheckNugetConfig | ||
) | ||
|
||
if ($CheckNugetConfig.IsPresent) { | ||
if (!(Test-Path "../nuget.config")) | ||
{ | ||
throw "The nuget.config file is not generated correctly." | ||
} | ||
} | ||
|
||
if (!$Patterns.Count) | ||
{ | ||
throw "Must supply dotnet version argument" | ||
throw "At least 1 dotnet-version pattern should be supplied to script." | ||
} | ||
|
||
Write-Host "Those patterns were supplied to the script: $($Patterns -join ', ')." | ||
$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() } | ||
Write-Host "Installed versions: $($versions -join ', ')." | ||
$InstalledVersionCount = 0 | ||
foreach($pattern in $Patterns) | ||
{ | ||
$version = & $dotnet --version | Out-String | ForEach-Object { $_.Trim() } | ||
Write-Host "Version $version" | ||
if (-not ($version.StartsWith($args[0].ToString()))) | ||
foreach ($version in $versions) | ||
{ | ||
Write-Host "PATH='$env:PATH'" | ||
throw "Unexpected version" | ||
} | ||
} | ||
|
||
if ($args[1]) | ||
{ | ||
# SDKs are listed on multiple lines with the path afterwards in square brackets | ||
$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 ($ContainedPattern) | ||
{ | ||
if ($version.StartsWith($arg.ToString())) | ||
if ($version.StartsWith($pattern.ToString()) -and $version.Contains($ContainedPattern)) | ||
{ | ||
$InstalledVersionCount++ | ||
} | ||
} | ||
elseif ($version.StartsWith($pattern.ToString())) | ||
{ | ||
$InstalledVersionCount++ | ||
} | ||
} | ||
} | ||
if ( $InstalledVersionCount -ne $args.Count) | ||
{ | ||
Write-Host "PATH='$env:PATH'" | ||
throw "Unexpected version" | ||
} | ||
} | ||
|
||
Write-Host "Building sample csproj" | ||
& $dotnet build __tests__/sample-csproj/ --no-cache | ||
if ($LASTEXITCODE -ne 0) | ||
if ( $InstalledVersionCount -ne $Patterns.Count) | ||
{ | ||
throw "Unexpected exit code $LASTEXITCODE" | ||
throw "An unexpected version of Dotnet is found on the machine, please check the script's dotnet-version patterns." | ||
} | ||
|
||
Write-Host "Testing compiled app" | ||
$sample_output = "$(dotnet test __tests__/sample-csproj/ --no-build)" | ||
Write-Host "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 ($args[1]) | ||
{ | ||
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*") | ||
{ | ||
throw "Unexpected output" | ||
} | ||
} | ||
if ($args[2]) | ||
Write-Host "Changing directory to the ./__tests__/e2e-test-csproj" | ||
Set-Location ./__tests__/e2e-test-csproj | ||
|
||
$targetFrameworkVersionMapping = @{ | ||
"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"; | ||
} | ||
|
||
foreach ($version in $versions) | ||
{ | ||
if ($sample_output -notlike "*Test Run Successful.*Test Run Successful.*Test Run Successful.*") | ||
Write-Host "Creating temporary global.json file for $version .NET version." | ||
& $dotnet new globaljson --sdk-version $version --force | ||
Write-Host "The global.json file for the version $version is created. Currently used .NET version is: $(& $dotnet --version)" | ||
$version -match "^(?<key>\d+\.\d+)" | ||
Write-Host "Setting the TEST_TARGET_FRAMEWORK environment variable to $($targetFrameworkVersionMapping[$Matches.key])" | ||
[Environment]::SetEnvironmentVariable('TEST_TARGET_FRAMEWORK', $($targetFrameworkVersionMapping[$Matches.key])) | ||
|
||
Write-Host "Building test C# project with $version .NET version." | ||
& $dotnet build --no-cache | ||
if ($LASTEXITCODE -ne 0) | ||
{ | ||
throw "Unexpected output" | ||
throw "Building process is not successful, exit code: $LASTEXITCODE" | ||
} | ||
} | ||
else | ||
{ | ||
if ($sample_output -notlike "*Test Run Successful.*") | ||
|
||
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 temprary global.json file." | ||
Remove-Item ./global.json | ||
} | ||
|
||
Set-Location ../.. |