Pentia.Invoke-MSBuild.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# Requires https://github.com/pester/Pester: Install-Module Pester -Force -SkipPublisherCheck #Requires -Modules Pester Import-Module "$PSScriptRoot\Pentia.Invoke-MSBuild.psm1" -Force Import-Module "$PSScriptRoot\..\Pentia.Get-MSBuild\Pentia.Get-MSBuild.psm1" -Force Import-Module "$PSScriptRoot\..\Pentia.Publish-NuGetPackage\Pentia.Publish-NuGetPackage.psm1" -Force Import-Module "$PSScriptRoot\..\TestContent\TestSolution\Copy-TestSolution.psm1" -Force Describe "Invoke-MSBuild" { It "should compile the solution" { # Arrange $solutionRootPath = $TestDrive $solutionFilePath = "$solutionRootPath\TestSolution.sln" Copy-TestSolution -SolutionRootPath $solutionRootPath Push-Location $solutionRootPath try { Install-NuGetExe Restore-NuGetPackage -SolutionDirectory "." } finally { Pop-Location } # Act $solutionFilePath | Invoke-MSBuild # Assert $LASTEXITCODE | Should Be 0 } It "should throw an error when the solution can't be built" { # Arrange $solutionRootPath = $TestDrive $solutionFilePath = "$solutionRootPath\TestSolution.sln" Copy-TestSolution -SolutionRootPath $solutionRootPath # Act $invocation = { $solutionFilePath | Invoke-MSBuild } # Assert $invocation | Should Throw "Failed to build '$solutionFilePath'." } } Describe "Invoke-MSBuild" { It "should accept an array of additional build arguments" { # Arrange $solutionRootPath = $TestDrive Copy-TestSolution -SolutionRootPath $solutionRootPath Push-Location $solutionRootPath try { Install-NuGetExe Restore-NuGetPackage -SolutionDirectory "." } finally { Pop-Location } $webProjectFilePath = "$solutionRootPath\src\Feature\WebProject\Code\Feature.WebProject.csproj" $buildArgs = @( "/t:Build,WebPublish", "/m", "/p:Configuration=Debug", "/p:PublishUrl=$TestDrive\output", "/p:WebPublishMethod=FileSystem" ) # Act $webProjectFilePath | Invoke-MSBuild -BuildArgs $buildArgs # Assert $LASTEXITCODE | Should Be 0 Test-Path -Path "$TestDrive\output\bin\Feature.WebProject.dll" | Should Be $true } } |