#RunSomething.psm1function Run-Something { import-module .\RunSomethingElse.psm1 Run-SomethingElse}
#RunSomethingElse.psm1function Run-SomethingElse { throw "Run-SomethingElse has executed!"}
Import-Module -Name .\RunSomething.psm1
Describe "MyTest" { It "successfully mocks DoSomethingElse" { Mock -ModuleName RunSomethingElse -CommandName Run-SomethingElse {} Run-Something Assert-MockCalled -ModuleName RunSomethingElse Run-SomethingElse -Exactly 0 } }Remove-Module -Name RunSomething
Describing Run-Something[-] MyTest 0.99sCould not find Command Run-SomethingElse
Import-Module -Name .\RunSomething.psm1Import-Module -Name .\RunSomethingElse.psm1 #added this line
Describe "Run-Something" { It "MyTest" { Mock -ModuleName RunSomethingElse -CommandName Run-SomethingElse {} Run-Something Assert-MockCalled -ModuleName RunSomethingElse Run-SomethingElse -Exactly 0 } }Remove-Module -Name RunSomethingElse #added this lineRemove-Module -Name RunSomething
[-] MyTest 1.21sRun-SomethingElse has executed!
#RunSomething.psm1import-module .\RunSomethingElse.psm1 #import-module command moved out of the functionfunction Run-Something { Run-SomethingElse}
Import-Module -Name .\RunSomething.psm1
Describe "Run-Something" { It "MyTest" { Mock -ModuleName RunSomethingElse -CommandName Run-SomethingElse {} Run-Something Assert-MockCalled -ModuleName RunSomethingElse Run-SomethingElse -Exactly 0 } }
[-] MyTest 1.74sRun-SomethingElse has executed!
#RunSomething.psm1import-module .\RunSomethingElse.psm1 #import-module command moved out of the functionfunction Run-Something { Run-SomethingElse}
#RunSomethingElse.psm1function Run-SomethingElse { throw "Run-SomethingElse has executed!"}
Import-Module .\RunSomething.psm1
Describe "Run-Something" { It "MyTest" {
Mock -ModuleName RunSomething -CommandName Run-SomethingElse {}
Run-Something Assert-MockCalled -ModuleName RunSomething Run-SomethingElse -Exactly 1 }}Remove-Module RunSomething
function Set-NLSHDFSStore (){ [CmdletBinding()] Param([Parameter(Mandatory=$true)][string]$environment,[string]$sourceFolderName="hdfs") Import-Module (Get-ChildItem . -Recurse | Where-Object {$_.Name -eq "DeployUtilities.psm1"} | Sort-Object $_.FullName -Descending | Select-Object FullName -First 1 | foreach {$_.FullName}) Import-Module (Get-ChildItem . -Recurse | Where-Object {$_.Name -eq "$environment.environmentproperties.psm1"} | Sort-Object $_.FullName -Descending | Select-Object FullName -First 1 | foreach {$_.FullName})#etc...
}