Pentia.Get-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
# Requires https://github.com/pester/Pester: Install-Module Pester -Force -SkipPublisherCheck
#Requires -Modules Pester
Import-Module "$PSScriptRoot\Pentia.Get-MSBuild.psm1" -Force

InModuleScope "Pentia.Get-MSBuild" {
    
    Describe "Get-MSBuild" {
        It "should throw an exception when MSBuild does not exist" {
            # Arrange
            Mock Invoke-hMSBuildBat { return "C:\notvalid"} -ModuleName "Pentia.Get-MSBuild"
    
            # Act
            $invocation = { Get-MSBuild }
    
            # Assert
            $invocation | Should throw "Didn't find MSBuild.exe."
        }
    }
    
    Describe "Get-MSBuild" {
        It "should return the path to MSBuild.exe" {
            # Act
            $msbuildPath = Get-MSBuild
    
            # Assert
            $msbuildPath | Should Not Be $null
            $msbuildPath | Should BeOfType System.String
            $msbuildPath | Should BeLike "*\MSbuild.exe"
            $msbuildPath | Should Exist
        }
    }
}