Skip to content

Commit

Permalink
Add unit tests for Get-VSPath for VSBuildV1 (#15293)
Browse files Browse the repository at this point in the history
* add test

Co-authored-by: annaOpareva <[email protected]>
  • Loading branch information
AnnaOpareva and annaOpareva authored Sep 20, 2021
1 parent c436714 commit 140cb7e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tasks/VSBuildV1/Tests/Get-VSPath-Use-RegKey.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[CmdletBinding()]
param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
. $PSScriptRoot\..\Get-VSPath.ps1

Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\12.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\11.0 -Name ShellFolder -ErrorAction Ignore
Register-Mock Get-ItemProperty { @{ShellFolder = 'use_reg_key'} } -- -LiteralPath HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\10.0 -Name ShellFolder -ErrorAction Ignore

# Aсt.
$path_14 = Get-VSPath '14.0'
$path_12 = Get-VSPath '12.0'
$path_11 = Get-VSPath '11.0'
$path_10 = Get-VSPath '10.0'

# Assert.
Assert-AreEqual 'use_reg_key' $path_14
Assert-AreEqual 'use_reg_key' $path_12
Assert-AreEqual 'use_reg_key' $path_11
Assert-AreEqual 'use_reg_key' $path_10
23 changes: 23 additions & 0 deletions Tasks/VSBuildV1/Tests/Get-VSPath-Use-VsWhere.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[CmdletBinding()]
param()

# Arrange.
. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1
. $PSScriptRoot\..\Get-VSPath.ps1

$instance = New-Object Object
Add-Member -NotePropertyName installationPath -NotePropertyValue 'use_vswhere' -inputObject $instance

Register-Mock Get-VisualStudio { $instance } -- '17'
Register-Mock Get-VisualStudio { $instance } -- '16'
Register-Mock Get-VisualStudio { $instance } -- '15'

# Act.
$path_17 = Get-VSPath '17.0'
$path_16 = Get-VSPath '16.0'
$path_15 = Get-VSPath '15.0'

# Assert.
Assert-AreEqual 'use_vswhere' $path_17
Assert-AreEqual 'use_vswhere' $path_16
Assert-AreEqual 'use_vswhere' $path_15
6 changes: 6 additions & 0 deletions Tasks/VSBuildV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('VSBuild Suite', function () {
});

if (psm.testSupported()) {
it('Get-VSPath use Reg Key', (done) => {
psr.run(path.join(__dirname, 'Get-VSPath-Use-RegKey.ps1'), done);
})
it('Get-VSPath use vswhere', (done) => {
psr.run(path.join(__dirname, 'Get-VSPath-Use-VsWhere.ps1'), done);
})
it('(Select-VSVersion) falls back from 14', (done) => {
psr.run(path.join(__dirname, 'Select-VSVersion.FallsBackFrom14.ps1'), done);
})
Expand Down

0 comments on commit 140cb7e

Please sign in to comment.