diff --git a/test/MusicStore.Test/project.json b/test/MusicStore.Test/project.json index 302312f267..ec1db8d6c6 100644 --- a/test/MusicStore.Test/project.json +++ b/test/MusicStore.Test/project.json @@ -12,6 +12,7 @@ "test": "xunit.runner.aspnet" }, "frameworks": { - "dnx451": { } + "dnx451": { }, + "dnxcore50": { } } } diff --git a/test/RemoteTest.cmd b/test/RemoteTest.cmd new file mode 100644 index 0000000000..e191f59451 --- /dev/null +++ b/test/RemoteTest.cmd @@ -0,0 +1,3 @@ +@Echo off + +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0RemoteTest.ps1' %*" \ No newline at end of file diff --git a/test/RemoteTest.ps1 b/test/RemoteTest.ps1 new file mode 100644 index 0000000000..43aad53202 --- /dev/null +++ b/test/RemoteTest.ps1 @@ -0,0 +1,40 @@ +param( + [string] $server = $env:TEST_SERVER, + [string] $userName = $env:TEST_SERVER_USER, + [string] $password = $env:TEST_SERVER_PASS, + [string] $serverFolder = "dev" +) +$ErrorActionPreference = "Stop" + +$projectFile = "MusicStore.Test\project.json" + +Write-Host "Test server: $server" +Write-Host "Test folder: $serverFolder" + +$projectName = (get-item $projectFile).Directory.Name +Write-Host "Test project: $projectName" + +Invoke-Expression "..\tools\BundleAndDeploy.ps1 -projectFile $projectFile -server $server -serverFolder $serverFolder -userName $userName -password $password" + +$pass = ConvertTo-SecureString $password -AsPlainText -Force +$cred = New-Object System.Management.Automation.PSCredential ($userName, $pass); + +Set-Item WSMan:\localhost\Client\TrustedHosts "$server" -Force + +#This block of code will be executed remotely +$remoteScript = { + $ErrorActionPreference = "Continue" + cd C:\$using:serverFolder\$using:projectName + dir + $env:DNX_TRACE=1 + $testResult = & .\test.cmd 2>&1 + $testResult +} + +Write-Host ">>>> Remote code execution started <<<<" +$result = Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock $remoteScript +$result +Write-Host "<<<< Remote execution code completed >>>>" + +$testExitCode = $result[$result.length-1]; +exit $testExitCode diff --git a/tools/BundleAndDeploy.cmd b/tools/BundleAndDeploy.cmd new file mode 100644 index 0000000000..362120e9cc --- /dev/null +++ b/tools/BundleAndDeploy.cmd @@ -0,0 +1,3 @@ +@Echo off + +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0BundleAndDeploy.ps1' %*" \ No newline at end of file diff --git a/tools/BundleAndDeploy.ps1 b/tools/BundleAndDeploy.ps1 new file mode 100644 index 0000000000..77d1404441 --- /dev/null +++ b/tools/BundleAndDeploy.ps1 @@ -0,0 +1,89 @@ +param( + [Parameter(Mandatory=$true)] + [string] $projectFile, + [Parameter(Mandatory=$true)] + [string] $server, + [Parameter(Mandatory=$true)] + [string] $serverFolder, + [Parameter(Mandatory=$true)] + [string] $userName, + [Parameter(Mandatory=$true)] + [string] $password, + [bool] $remoteInvoke = $false +) +$ErrorActionPreference = "Stop" + +function UpdateHostInProjectJson($projectFile, $newhost) +{ + (Get-Content $projectFile) | + Foreach-Object { + $_ -replace "http://localhost", "http://$newhost" + } | + Set-Content $projectFile +} + +if (-not (Test-Path $projectFile)) { + Write-Error "Couldn't find $projectFile" + exit 1 +} + +$projectName = (get-item $projectFile).Directory.Name +$workDir = (get-item $projectFile).Directory.FullName +$remoteRoot = "\\" + $server +$remoteDir = Join-Path $remoteRoot -ChildPath $serverFolder + +try +{ + if ($userName) { + net use $remoteRoot $password /USER:$userName + if ($lastexitcode -ne 0) { + exit 1 + } + } + + if (-not (Test-Path $remoteDir)) { + Write-Error "Remote directory $remoteDir does not exist or it is not accessible" + exit 1 + } + + $packDir = Join-Path $workDir -ChildPath "bin\output" + if (Test-Path $packDir) { + Write-Host "$packDir already exists. Removing it..." + rmdir -Recurse "$packDir" + } + + Write-Host "Bundling the application..." + cd "$workDir" + dnvm use default -r CoreCLR -arch x64 + dnu publish --runtime active + if ($lastexitcode -ne 0) { + Write-Error "Failed to bundle the application" + exit 1 + } + + if ($remoteInvoke) { + $packedProjectJsonFile = Join-Path $packDir -ChildPath "approot\src\$projectName\project.json" + Write-Host "Setting host to $server in $packedProjectJsonFile" + if (-not (Test-Path $packedProjectJsonFile)) { + Write-Error "Couldn't find $packedProjectJsonFile" + exit 1 + } + + UpdateHostInProjectJson $packedProjectJsonFile $server + } + + $destDir = Join-Path $remoteDir -ChildPath $projectName + if (Test-Path $destDir) { + Write-Host "$destDir already exists. Removing it..." + rmdir -Recurse "$destDir" + } + + Write-Host "Copying bundled application to $destDir ..." + Copy-Item "$packDir" -Destination "$destDir" -Recurse +} +finally +{ + if ($userName -and $remoteRoot) { + net use $remoteRoot /delete + } +} \ No newline at end of file