@@ -2,6 +2,101 @@ $function = $MyInvocation.MyCommand.Name.Split('.')[0]
22
33Describe - Name $function - Fixture {
44
5+ Context - Name ' Stream input (non-MemoryStream)' - Fixture {
6+ It - Name ' Converts FileStream using -Stream parameter' - Test {
7+ $string = ' ThisIsMyString'
8+ $tempFile = [System.IO.Path ]::GetTempFileName()
9+ $fileStream = $null
10+ try {
11+ [System.IO.File ]::WriteAllText($tempFile , $string )
12+ $fileStream = [System.IO.File ]::OpenRead($tempFile )
13+
14+ $assertion = ConvertFrom-MemoryStreamToString - Stream $fileStream
15+
16+ $assertion | Should - BeExactly $string
17+ } finally {
18+ if ($fileStream ) { $fileStream.Dispose () }
19+ if (Test-Path $tempFile ) { Remove-Item $tempFile - Force }
20+ }
21+ }
22+
23+ It - Name ' Converts FileStream from Pipeline' - Test {
24+ $string = ' ThisIsMyString'
25+ $tempFile = [System.IO.Path ]::GetTempFileName()
26+ $fileStream = $null
27+ try {
28+ [System.IO.File ]::WriteAllText($tempFile , $string )
29+ $fileStream = [System.IO.File ]::OpenRead($tempFile )
30+
31+ $assertion = $fileStream | ConvertFrom-MemoryStreamToString
32+
33+ $assertion | Should - BeExactly $string
34+ } finally {
35+ if ($fileStream ) { $fileStream.Dispose () }
36+ if (Test-Path $tempFile ) { Remove-Item $tempFile - Force }
37+ }
38+ }
39+
40+ It - Name ' Converts BufferedStream to string' - Test {
41+ $string = ' ThisIsMyString'
42+ $memStream = [System.IO.MemoryStream ]::new()
43+ $writer = [System.IO.StreamWriter ]::new($memStream )
44+ $writer.Write ($string )
45+ $writer.Flush ()
46+
47+ $bufferedStream = [System.IO.BufferedStream ]::new($memStream )
48+
49+ $assertion = ConvertFrom-MemoryStreamToString - Stream $bufferedStream
50+
51+ $assertion | Should - BeExactly $string
52+
53+ $bufferedStream.Dispose ()
54+ $writer.Dispose ()
55+ $memStream.Dispose ()
56+ }
57+
58+ It - Name ' Converts array of FileStreams from Pipeline' - Test {
59+ $string = ' ThisIsMyString'
60+ $tempFile1 = [System.IO.Path ]::GetTempFileName()
61+ $tempFile2 = [System.IO.Path ]::GetTempFileName()
62+ $stream1 = $null
63+ $stream2 = $null
64+ try {
65+ [System.IO.File ]::WriteAllText($tempFile1 , $string )
66+ [System.IO.File ]::WriteAllText($tempFile2 , $string )
67+
68+ $stream1 = [System.IO.File ]::OpenRead($tempFile1 )
69+ $stream2 = [System.IO.File ]::OpenRead($tempFile2 )
70+
71+ $assertion = @ ($stream1 , $stream2 ) | ConvertFrom-MemoryStreamToString
72+
73+ $assertion | Should - HaveCount 2
74+ } finally {
75+ if ($stream1 ) { $stream1.Dispose () }
76+ if ($stream2 ) { $stream2.Dispose () }
77+ if (Test-Path $tempFile1 ) { Remove-Item $tempFile1 - Force }
78+ if (Test-Path $tempFile2 ) { Remove-Item $tempFile2 - Force }
79+ }
80+ }
81+ }
82+
83+ Context - Name ' Alias' - Fixture {
84+ It - Name ' ConvertFrom-StreamToString alias works' - Test {
85+ $string = ' ThisIsMyString'
86+ $stream = [System.IO.MemoryStream ]::new()
87+ $writer = [System.IO.StreamWriter ]::new($stream )
88+ $writer.Write ($string )
89+ $writer.Flush ()
90+
91+ $assertion = ConvertFrom-StreamToString - Stream $stream
92+
93+ $assertion | Should - BeExactly $string
94+
95+ $stream.Dispose ()
96+ $writer.Dispose ()
97+ }
98+ }
99+
5100 Context - Name ' Input/Output' - Fixture {
6101 It - Name " Converts a MemoryStream to a string" - Test {
7102 $string = ' ThisIsMyString'
0 commit comments