diff --git a/src/Helper/Resolve-Dependency.ps1 b/src/Helper/Resolve-Dependency.ps1 index 1687275..59cfc5f 100644 --- a/src/Helper/Resolve-Dependency.ps1 +++ b/src/Helper/Resolve-Dependency.ps1 @@ -53,11 +53,12 @@ function Resolve-Dependency { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [string]$Name ) begin { - $ModuleRootDir = $MyInvocation.MyCommand.Module.ModuleBase + $ModuleRootDir = Get-ModuleBase $DepFilePath = Join-Path -Path $ModuleRootDir -ChildPath "Dependency.json" if (Test-Path -Path $DepFilePath) { $Dependency = Get-Content -Path $DepFilePath -Raw -Encoding UTF8 | ConvertFrom-Json diff --git a/tests/Helper/01_Resolve-Dependendy.Tests.ps1 b/tests/Helper/01_Resolve-Dependendy.Tests.ps1 new file mode 100644 index 0000000..013c65b --- /dev/null +++ b/tests/Helper/01_Resolve-Dependendy.Tests.ps1 @@ -0,0 +1,31 @@ +#region HEADER +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +#. (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName +#endregion HEADER + +Describe "Resolve-Dependency" { + Context "Basic syntax check" { + Mock Get-ModuleBase {return "{0}\resources" -f $PWD} + Mock Test-Module {return $true} + It "Test1: Should not throw" { + { Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw + } + It "Test2: Output type should be bool" { + Resolve-Dependency -Name 'foobar2000' | Should -BeOfType system.bool + } + } +}