MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
445 stars 155 forks source link

Mock appears to be broken in Add-VSTeamProject.Tests.ps1 #369

Closed jhoneill closed 3 years ago

jhoneill commented 3 years ago

Steps to reproduce

Sync with trunk, and confirm

> git log --oneline --decorate
58a5491 (HEAD -> trunk, tag: v7.1.2, upstream/trunk, origin/trunk, origin/HEAD) Updated change log
f95ce17 Fix #365 (#366)
7daec7c Fixing issue #360 (#368)
4ce0cbd Fixing issue #363 (#367)

In a clean PowerShell session (I'm on 7.0.3)

.\Tests\function\tests\add-VSTeamProject.Tests.ps1

Expected behavior

Success

Actual behavior

Starting discovery in 1 files.
Discovery finished in 285ms.
[-] VSTeamProject.Add-VSTeamProject.with tfvc should create project with tfvc 1.54s (1.48s|58ms)
 FormatException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 RuntimeException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 ParameterBindingValidationException: Cannot validate argument on parameter 'Name'. The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 at Add-VSTeamProject<Process>, C:\Users\P10506111\Documents\github\vsteam\Source\Public\Add-VSTeamProject.ps1:69
 at <ScriptBlock>, C:\Users\P10506111\Documents\github\vsteam\Tests\function\tests\Add-VSTeamProject.Tests.ps1:51
[-] VSTeamProject.Add-VSTeamProject with Agile.Should create project with Agile 185ms (182ms|2ms)
 FormatException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 RuntimeException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 ParameterBindingValidationException: Cannot validate argument on parameter 'Name'. The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 at Add-VSTeamProject<Process>, C:\Users\P10506111\Documents\github\vsteam\Source\Public\Add-VSTeamProject.ps1:69
 at <ScriptBlock>, C:\Users\P10506111\Documents\github\vsteam\Tests\function\tests\Add-VSTeamProject.Tests.ps1:74
[-] VSTeamProject.Add-VSTeamProject with CMMI.Should create project with CMMI 166ms (165ms|1ms)
 FormatException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 RuntimeException: The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 ParameterBindingValidationException: Cannot validate argument on parameter 'Name'. The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid.
 at Add-VSTeamProject<Process>, C:\Users\P10506111\Documents\github\vsteam\Source\Public\Add-VSTeamProject.ps1:69
 at <ScriptBlock>, C:\Users\P10506111\Documents\github\vsteam\Tests\function\tests\Add-VSTeamProject.Tests.ps1:94
Tests completed in 4.11s
Tests Passed: 1, Failed: 3, Skipped: 0 NotRun: 0

Past experience says The format of value 'Module/ (Windows) PowerShell/7.0.3' is invalid. happens when a call which should be mocked makes it all the way through to Invoke-RestMethod

Environment data

OS

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
jhoneill commented 3 years ago

Line 21 of the tests file.
$Uri -like "*$top=100*" -and` Top is no longer set to fix #363

Lines20 -24 of the test work if they're changed to this

      Mock Invoke-RestMethod { return [pscustomobject]@{value=@()} } -ParameterFilter {
         $Uri -like "*stateFilter=WellFormed*"
      }