Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/powershell/engine/Api/BasicEngine.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
Describe 'Basic engine APIs' -Tags "CI" {
Context 'powershell::Create' {
It 'can create default instance' {
[powershell]::Create() | Should Not Be $null
[powershell]::Create() | Should -Not -BeNullOrEmpty
}

It "can load the default snapin 'Microsoft.WSMan.Management'" -skip:(-not $IsWindows) {
$ps = [powershell]::Create()
$ps.AddScript("Get-Command -Name Test-WSMan") > $null

$result = $ps.Invoke()
$result.Count | Should Be 1
$result[0].Source | Should Be "Microsoft.WSMan.Management"
$result.Count | Should -Be 1
$result[0].Source | Should -BeExactly "Microsoft.WSMan.Management"
}
}

Context 'executioncontext' {
It 'args are passed correctly' {
$result = $ExecutionContext.SessionState.InvokeCommand.InvokeScript('"`$args:($args); `$input:($input)"', 1, 2, 3)
$result | Should BeExactly '$args:(1 2 3); $input:()'
$result | Should -BeExactly '$args:(1 2 3); $input:()'
}
}
}
Expand All @@ -41,9 +41,9 @@ exit
$expect = "powershell process exits in 5 seconds"
if (-not $process.HasExited) {
Stop-Process -InputObject $process -Force -ErrorAction SilentlyContinue
"powershell process doesn't exit in 5 seconds" | Should Be $expect
"powershell process doesn't exit in 5 seconds" | Should -Be $expect
} else {
$expect | Should Be $expect
$expect | Should -Be $expect
}
}
}
8 changes: 4 additions & 4 deletions test/powershell/engine/Api/GetNewClosure.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ Describe "ScriptBlock.GetNewClosure()" -tags "CI" {
}

It "Parameter attributes should not get evaluated again in GetNewClosure - SimpleFunction" {
SimpleFunction_GetNewClosure | Should Be "OK"
SimpleFunction_GetNewClosure | Should -BeExactly "OK"
}

It "Parameter attributes should not get evaluated again in GetNewClosure - ScriptCmdlet" {
$result = ScriptCmdlet_GetNewClosure
$result.Count | Should Be 2
$result[0] | Should Be 4
$result[1] | Should Be ""
$result.Count | Should -Be 2
$result[0] | Should -Be 4
$result[1] | Should -BeNullOrEmpty
}
}
38 changes: 15 additions & 23 deletions test/powershell/engine/Api/InitialSessionState.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ Describe "InitialSessionState capacity" -Tags CI {
}

It "function capacity in initial session state should not be limited" {
$ps.AddCommand('f4999').Invoke() | Should Be "fn f4999"
$ps.Streams.Error | Should Be $null
$ps.AddCommand('f4999').Invoke() | Should -Be "fn f4999"
$ps.Streams.Error | Should -BeNullOrEmpty
}

It "alias capacity in initial session state should not be limited" {
$ps.AddCommand('a4999').Invoke() | Should Be "fn f4999"
$ps.Streams.Error | Should Be $null
$ps.AddCommand('a4999').Invoke() | Should -Be "fn f4999"
$ps.Streams.Error | Should -BeNullOrEmpty
}

It "variable capacity in initial session state should not be limited" {
$ps.AddScript('$v4999').Invoke() | Should Be "var v4999"
$ps.Streams.Error | Should Be $null
$ps.AddScript('$v4999').Invoke() | Should -Be "var v4999"
$ps.Streams.Error | Should -BeNullOrEmpty
}

It "function capacity should not be limited after runspace is opened" {
$ps.AddScript('function f5000 { "in f5000" } f5000').Invoke() | Should Be "in f5000"
$ps.Streams.Error | Should Be $null
$ps.AddScript('function f5000 { "in f5000" } f5000').Invoke() | Should -Be "in f5000"
$ps.Streams.Error | Should -BeNullOrEmpty
}

It "variable capacity should not be limited after runspace is opened" {
$ps.AddScript('$v5000 = "var v5000"; $v5000').Invoke() | Should Be "var v5000"
$ps.Streams.Error | Should Be $null
$ps.AddScript('$v5000 = "var v5000"; $v5000').Invoke() | Should -Be "var v5000"
$ps.Streams.Error | Should -BeNullOrEmpty
}

It "alias capacity should not be limited after runspace is opened" {
$ps.AddScript('New-Alias -Name a5000 -Value f1; a5000').Invoke() | Should Be "fn f1"
$ps.Streams.Error | Should Be $null
$ps.AddScript('New-Alias -Name a5000 -Value f1; a5000').Invoke() | Should -Be "fn f1"
$ps.Streams.Error | Should -BeNullOrEmpty
}
}

Expand Down Expand Up @@ -91,7 +91,7 @@ Describe "TypeTable duplicate types in reused runspace InitialSessionState TypeT

It "Verifies that a reused InitialSessionState object created from a TypeTable object does not have duplicate types" {

{ $rs2.Open() } | Should Not Throw
{ $rs2.Open() } | Should -Not -Throw
}
}

Expand All @@ -115,16 +115,8 @@ Describe "TypeTable duplicate types in reused runspace InitialSessionState TypeT
It "Verifies that shared TypeTable is not allowed in ISS" {

# Process TypeTable types from ISS.
$errorId = ""
try
{
$rs.Open()
throw "No Exception!"
}
catch
{
$_.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should Be "ErrorsUpdatingTypes"
}
$e = { $rs.Open() } | Should -Throw -ErrorId "RuntimeException" -PassThru
$e.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ErrorsUpdatingTypes"
}
}
}
12 changes: 6 additions & 6 deletions test/powershell/engine/Api/LanguagePrimitive.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ Describe "Language Primitive Tests" -Tags "CI" {
It "Equality comparison with string and non-numeric type should not be culture sensitive" {
$date = [datetime]'2005,3,10'
$val = [System.Management.Automation.LanguagePrimitives]::Equals($date, "3/10/2005")
$val | Should Be $true
$val | Should -BeTrue
}

It "Test conversion of an PSObject with Null Base Object to bool" {
$mshObj = New-Object psobject
{ [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [bool]) } | Should Be $true
{ [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [bool]) } | Should -BeTrue
}

It "Test conversion of an PSObject with Null Base Object to string" {
$mshObj = New-Object psobject
{ [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [string]) -eq "" } | Should Be $true
{ [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [string]) -eq "" } | Should -BeTrue
}

It "Test conversion of an PSObject with Null Base Object to object" {
$mshObj = New-Object psobject
{ $mshObj -eq [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [Object]) } | Should Be $true
{ $mshObj -eq [System.Management.Automation.LanguagePrimitives]::ConvertTo($mshObj, [Object]) } | Should -BeTrue
}

It "Test Conversion of an IEnumerable to object[]" {
$col = [System.Diagnostics.Process]::GetCurrentProcess().Modules
$ObjArray = [System.Management.Automation.LanguagePrimitives]::ConvertTo($col, [object[]])
$ObjArray.Length | Should Be $col.Count
$ObjArray.Length | Should -Be $col.Count
}

It "Casting recursive array to bool should not cause crash" {
$a[0] = $a = [PSObject](,1)
[System.Management.Automation.LanguagePrimitives]::IsTrue($a) | Should Be $true
[System.Management.Automation.LanguagePrimitives]::IsTrue($a) | Should -BeTrue
}
}
20 changes: 10 additions & 10 deletions test/powershell/engine/Api/ProxyCommand.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,34 @@ Describe 'ProxyCommand Tests' -Tags "CI" {
$helpObjText = NormalizeCRLF -helpObj $helpObj
$newHelpObjText = NormalizeCRLF -helpObj $newHelpObj

$helpObjText | Should Be $newHelpObjText
$helpObjText | Should -Be $newHelpObjText
$oldDespText = GetSectionText $helpObj.description
$newDespText = GetSectionText $newHelpObj.description
$oldDespText | Should Be $newDespText
$oldDespText | Should -Be $newDespText

$oldParameters = @($helpObj.parameters.parameter)
$newParameters = @($newHelpObj.parameters.parameter)
$oldParameters.Length | Should Be $newParameters.Length
$oldParameters.name -join "," | Should Be ($newParameters.name -join ",")
$oldParameters.Length | Should -Be $newParameters.Length
$oldParameters.name -join "," | Should -Be ($newParameters.name -join ",")

$oldExamples = @($helpObj.examples.example)
$newExamples = @($newHelpObj.examples.example)
$oldExamples.Length | Should Be $newExamples.Length
$oldExamples.Length | Should -Be $newExamples.Length
}

It "Test generate proxy command" {
$cmdInfo = Get-Command -Name Get-Content
$cmdMetadata = [CommandMetadata]::new($cmdInfo)
$proxyBody = [ProxyCommand]::Create($cmdMetadata, "--DummyHelpContent--")
$proxyBody | Should Match '--DummyHelpContent--'
$proxyBody | Should -Match '--DummyHelpContent--'

$proxyBodySB = [scriptblock]::Create($proxyBody)
Set-Item -Path function:\MyGetContent -Value $proxyBodySB

$expectedContent = "Hello World"
Set-Content -Path $TestDrive\content.txt -Value $expectedContent -Encoding Unicode
$myContent = MyGetContent -Path $TestDrive\content.txt -Encoding Unicode
$myContent | Should Be $expectedContent
$myContent | Should -Be $expectedContent
}

It "Test generate individual components" {
Expand Down Expand Up @@ -171,12 +171,12 @@ End {{

$cmdMyProxyTest = Get-Command MyProxyTest
$dyParam = $cmdMyProxyTest.Parameters.GetEnumerator() | Where-Object { $_.Value.IsDynamic }
$dyParam.Key | Should Be 'LastName'
$dyParam.Key | Should -Be 'LastName'

$result = "Msg1", "Msg2" | MyProxyTest -Name Apple -LastName Last
$result | Should Be "Apple,Last - Msg1;Msg2"
$result | Should -Be "Apple,Last - Msg1;Msg2"

$result = "Msg1", "Msg2" | MyProxyTest -Id 3 -LastName Last
$result | Should Be "3,Last - Msg1;Msg2"
$result | Should -Be "3,Last - Msg1;Msg2"
}
}
14 changes: 7 additions & 7 deletions test/powershell/engine/Api/Serialization.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ Describe "Serialization Tests" -tags "CI" {

It 'Test DateTimeUtc serialize and deserialize work as expected.' {
$inputObject = [System.DateTime]::UtcNow;
SerializeAndDeserialize($inputObject) | Should be $inputObject
SerializeAndDeserialize($inputObject) | Should -Be $inputObject
}

It 'Test DateTime stamps serialize and deserialize work as expected.' {
$objs = [System.DateTime]::MaxValue, [System.DateTime]::MinValue, [System.DateTime]::Today, (new-object System.DateTime), (new-object System.DateTime 123456789)
foreach($inputObject in $objs)
{
SerializeAndDeserialize($inputObject) | Should be $inputObject
SerializeAndDeserialize($inputObject) | Should -Be $inputObject
}
}

Expand All @@ -50,7 +50,7 @@ Describe "Serialization Tests" -tags "CI" {
foreach($uristring in $uristrings)
{
$inputObject = new-object System.Uri $uristring
SerializeAndDeserialize($inputObject) | Should be $inputObject
SerializeAndDeserialize($inputObject) | Should -Be $inputObject
}
}

Expand All @@ -74,20 +74,20 @@ Describe "Serialization Tests" -tags "CI" {
$outputs = SerializeAndDeserialize($inputObject);
for($i=0;$i -lt $inputObject.Length;$i++)
{
$outputs[$i] | Should be $inputObject[$i]
$outputs[$i] | Should -Be $inputObject[$i]
}
}
}

It 'Test Enum serialize and deserialize work as expected.' {
$inputObject = [MyColorFlag]::RED
SerializeAndDeserialize($inputObject).ToString() | Should be $inputObject.ToString()
SerializeAndDeserialize($inputObject).ToString() | Should -Be $inputObject.ToString()
}

It 'Test SecureString serialize and deserialize work as expected.' {
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
$inputObject = Convertto-Securestring -String "PowerShellRocks!" -AsPlainText -Force
SerializeAndDeserialize($inputObject).Length | Should be $inputObject.Length
SerializeAndDeserialize($inputObject).Length | Should -Be $inputObject.Length

}

Expand All @@ -96,7 +96,7 @@ Describe "Serialization Tests" -tags "CI" {
$versionObject | Add-Member -MemberType NoteProperty -Name TestNote -Value "TestNote"
$versionObject | Add-Member -MemberType ScriptProperty -Name TestScriptProperty -Value { ($this.TestNote) }

SerializeAndDeserialize($versionObject).TestScriptProperty | Should be $versionObject.TestScriptProperty
SerializeAndDeserialize($versionObject).TestScriptProperty | Should -Be $versionObject.TestScriptProperty
}
}

Loading