MegaBites-AI/Windows-powershell
0308
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Write-Output DRT Unit Tests" -Tags "CI" {4 It "Simple Write Object Test" {5 $objectWritten = 1, 2.2, @("John", "Smith", 10), "abc"6 $results = Write-Output $objectWritten7 $results.Length | Should -Be $objectWritten.Length8 9 $results[0] | Should -Be $objectWritten[0]10 $results[1] | Should -Be $objectWritten[1]11 12 $results[2] | Should -Be $objectWritten[2]13 $results[2] -is [System.Array] | Should -BeTrue14 15 $results[3] | Should -Be $objectWritten[3]16 $results[3] -is [System.String] | Should -BeTrue17 }18 19 It "Works with NoEnumerate switch" {20 $objectWritten = 1, 2.2, @("John", "Smith", 10), "abc"21 [string]$s = Write-Output $objectWritten -NoEnumerate 6>&122 $s | Should -Be '1 2.2 System.Object[] abc'23 }24 25 It "Preserves the input collection type and contents with -NoEnumerate" {26 $List = [System.Collections.Generic.List[string]]::new( [string[]]@("test", "one", "two") )27 $ObjectWritten = Write-Output $List -NoEnumerate28 29 $ObjectWritten.GetType() | Should -Be ([System.Collections.Generic.List[string]])30 $ObjectWritten[0] | Should -BeExactly "test"31 $ObjectWritten[1] | Should -BeExactly "one"32 $ObjectWritten[2] | Should -BeExactly "two"33 }34}35 36Describe "Write-Output" -Tags "CI" {37 $testString = $testString38 Context "Input Tests" {39 It "Should allow piped input" {40 { $testString | Write-Output } | Should -Not -Throw41 }42 43 It "Should write output to the output stream when using piped input" {44 $testString | Write-Output | Should -Be $testString45 }46 47 It "Should use inputobject switch" {48 { Write-Output -InputObject $testString } | Should -Not -Throw49 }50 51 It "Should write output to the output stream when using inputobject switch" {52 Write-Output -InputObject $testString | Should -Be $testString53 }54 55 It "Should be able to write to a variable" {56 Write-Output -InputObject $testString -OutVariable var57 $var | Should -Be $testString58 }59 }60 61 Context "Pipeline Command Tests" {62 It "Should send object to the next command in the pipeline" {63 Write-Output -InputObject (1 + 1) | Should -Be 264 }65 66 It "Should have the same result between inputobject switch and piped input" {67 Write-Output -InputObject (1 + 1) | Should -Be 268 69 1 + 1 | Write-Output | Should -Be 270 }71 }72 73 Context "Enumerate Objects" {74 $enumerationObject = @(1, 2, 3)75 It "Should see individual objects when not using the NoEnumerate switch" {76 $singleCollection = $(Write-Output $enumerationObject| Measure-Object).Count77 78 $singleCollection | Should -Be $enumerationObject.length79 }80 81 It "Should be able to treat a collection as a single object using the NoEnumerate switch" {82 $singleCollection = $(Write-Output $enumerationObject -NoEnumerate | Measure-Object).Count83 84 $singleCollection | Should -Be 185 }86 }87}88 