<commit_before>$ErrorActionPreference = "Stop"

function testExitCode(){
    If($LASTEXITCODE -ne 0) {
        write-host -f green "lastexitcode: $LASTEXITCODE"
        exit $LASTEXITCODE
    }
}

#cleanup
$importBeforeTargetFileName="%USERPROFILE%\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\SonarAnalyzer.Testing.ImportBefore.targets" 
If (Test-Path $importBeforeTargetFileName){
  Remove-Item $importBeforeTargetFileName
}

#nuget restore
& $env:NUGET_PATH restore .\src\SonarLint.VisualStudio.Integration.sln
testExitCode

#build tests
& $env:MSBUILD_PATH .\src\SonarLint.VisualStudio.Integration.sln /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m /p:defineConstants=SignAssembly /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$env:CERT_PATH
testExitCode

#download VSIX
$ARTIFACTORY_SRC_REPO="sonarsource-public-qa/org/sonarsource/dotnet/SonarLint.VSIX"
[xml]$versionProps = Get-Content .\build\Version.props
$version  = $versionProps.Project.PropertyGroup.MainVersion+".$env:CI_BUILD_NUMBER"
$fileName = "SonarLint.VSIX-$version.vsix"
$url = "$env:ARTIFACTORY_URL/$ARTIFACTORY_SRC_REPO/$version/$fileName"
Write-Host "Downloading $url"
$pair = "$($env:REPOX_QAPUBLICADMIN_USERNAME):$($env:REPOX_QAPUBLICADMIN_PASSWORD)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{Authorization = $basicAuthValue}
Invoke-WebRequest -UseBasicParsing -Uri "$url" -Headers $Headers -OutFile $fileName

#write the version to a property file for promotion job
$s="ARTIFACT=org/sonarsource/dotnet/SonarLint.VSIX/$version"
$s | out-file -encoding utf8 -append ".\artifact.properties"
#convert property file to unix for jenkins compatiblity
Get-ChildItem .\artifact.properties | ForEach-Object {
  $contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n"
  $utf8 = New-Object System.Text.UTF8Encoding $false
  [IO.File]::WriteAllText($_, $contents, $utf8)
}

#unzip VSIX package
$zipName="SonarLint.VSIX-$version.zip"
Move-Item $fileName $zipName -force
$shell_app=new-object -com shell.application
$baseDir=(Get-Item -Path ".\" -Verbose).FullName
$destination = $shell_app.NameSpace($baseDir)
$zip_file = $shell_app.NameSpace("$baseDir\$zipName")
Write-Host "Unzipping $baseDir\$zipName"
$destination.CopyHere($zip_file.Items(), 0x14) 

#move dlls to correct locations
Write-Host "Copying DLLs"
Copy-Item *.dll .\src\Integration.UnitTests\bin\Release\ -force
Copy-Item *.dll .\src\Integration.Vsix.UnitTests\bin\Release\ -force
Copy-Item *.dll .\src\Progress.UnitTests\bin\Release\ -force

#run tests
Write-Host "Start tests"
& $env:VSTEST_PATH .\src\Integration.UnitTests\bin\Release\SonarLint.VisualStudio.Integration.UnitTests.dll
testExitCode
& $env:VSTEST_PATH .\src\Integration.Vsix.UnitTests\bin\Release\SonarLint.VisualStudio.Integration.Vsix.UnitTests.dll
testExitCode
& $env:VSTEST_PATH .\src\Progress.UnitTests\bin\Release\SonarLint.VisualStudio.Progress.UnitTests.dll
testExitCode<commit_msg>Fix QA script to test renamed VS2015 build<commit_after>$ErrorActionPreference = "Stop"

function testExitCode(){
    If($LASTEXITCODE -ne 0) {
        write-host -f green "lastexitcode: $LASTEXITCODE"
        exit $LASTEXITCODE
    }
}

#cleanup
$importBeforeTargetFileName="%USERPROFILE%\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\SonarAnalyzer.Testing.ImportBefore.targets" 
If (Test-Path $importBeforeTargetFileName){
  Remove-Item $importBeforeTargetFileName
}

#nuget restore
& $env:NUGET_PATH restore .\src\SonarLint.VisualStudio.Integration.sln
testExitCode

#build tests
& $env:MSBUILD_PATH .\src\SonarLint.VisualStudio.Integration.sln /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m /p:defineConstants=SignAssembly /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=$env:CERT_PATH
testExitCode

#download VSIX
$ARTIFACTORY_SRC_REPO="sonarsource-public-qa/org/sonarsource/dotnet/SonarLint.VSIX"
[xml]$versionProps = Get-Content .\build\Version.props
$version  = $versionProps.Project.PropertyGroup.MainVersion+".$env:CI_BUILD_NUMBER"
$fileName = "SonarLint.VSIX-$version-2015.vsix"
$url = "$env:ARTIFACTORY_URL/$ARTIFACTORY_SRC_REPO/$version/$fileName"
Write-Host "Downloading $url"
$pair = "$($env:REPOX_QAPUBLICADMIN_USERNAME):$($env:REPOX_QAPUBLICADMIN_PASSWORD)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{Authorization = $basicAuthValue}
Invoke-WebRequest -UseBasicParsing -Uri "$url" -Headers $Headers -OutFile $fileName

#write the version to a property file for promotion job
$s="ARTIFACT=org/sonarsource/dotnet/SonarLint.VSIX/$version"
$s | out-file -encoding utf8 -append ".\artifact.properties"
#convert property file to unix for jenkins compatiblity
Get-ChildItem .\artifact.properties | ForEach-Object {
  $contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n"
  $utf8 = New-Object System.Text.UTF8Encoding $false
  [IO.File]::WriteAllText($_, $contents, $utf8)
}

#unzip VSIX package
$zipName="SonarLint.VSIX-$version-2015.zip"
Move-Item $fileName $zipName -force
$shell_app=new-object -com shell.application
$baseDir=(Get-Item -Path ".\" -Verbose).FullName
$destination = $shell_app.NameSpace($baseDir)
$zip_file = $shell_app.NameSpace("$baseDir\$zipName")
Write-Host "Unzipping $baseDir\$zipName"
$destination.CopyHere($zip_file.Items(), 0x14) 

#move dlls to correct locations
Write-Host "Copying DLLs"
Copy-Item *.dll .\src\Integration.UnitTests\bin\Release\ -force
Copy-Item *.dll .\src\Integration.Vsix.UnitTests\bin\Release\ -force
Copy-Item *.dll .\src\Progress.UnitTests\bin\Release\ -force

#run tests
Write-Host "Start tests"
& $env:VSTEST_PATH .\src\Integration.UnitTests\bin\Release\SonarLint.VisualStudio.Integration.UnitTests.dll
testExitCode
& $env:VSTEST_PATH .\src\Integration.Vsix.UnitTests\bin\Release\SonarLint.VisualStudio.Integration.Vsix.UnitTests.dll
testExitCode
& $env:VSTEST_PATH .\src\Progress.UnitTests\bin\Release\SonarLint.VisualStudio.Progress.UnitTests.dll
testExitCode
{'fraction_non_alphanumeric': 0.13798675068670221, 'fraction_numerical': 0.006139925674583939, 'mean_word_length': 6.265258215962441, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1140981', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2155, 'n_words': 344}