@@ -35,93 +35,94 @@ public sealed class WriterAsOutputStreamTest
35
35
[ Fact ]
36
36
public void WritesContentToFile ( )
37
37
{
38
- var dir = "artifacts/WriterAsOutputStreamTest" ; var inputFile = "large-text.txt" ;
39
- var inputPath = Path . GetFullPath ( Path . Combine ( dir , inputFile ) ) ;
40
- var outputFile = "text-copy.txt" ;
41
- var outputPath = Path . GetFullPath ( Path . Combine ( dir , outputFile ) ) ;
38
+ var inputFile = new TempFile ( "large-text.txt" ) ;
39
+ var outputFile = new TempFile ( "copy-text.txt" ) ;
40
+ using ( inputFile )
41
+ {
42
+ using ( outputFile )
43
+ {
44
+ var inputPath = Path . GetFullPath ( inputFile . Value ( ) ) ;
45
+ var outputPath = Path . GetFullPath ( outputFile . Value ( ) ) ;
42
46
43
- Directory . CreateDirectory ( dir ) ;
44
- if ( File . Exists ( inputPath ) ) File . Delete ( inputPath ) ;
45
- if ( File . Exists ( outputPath ) ) File . Delete ( outputPath ) ;
47
+ //Create large file
48
+ new LengthOf (
49
+ new InputOf (
50
+ new TeeInputStream (
51
+ new MemoryStream (
52
+ new BytesOf (
53
+ new Text . Joined ( "," ,
54
+ new HeadOf < string > (
55
+ new Endless < string > ( "Hello World" ) ,
56
+ 1000
57
+ )
58
+ )
59
+ ) . AsBytes ( )
60
+ ) ,
61
+ new OutputTo (
62
+ new Uri ( inputPath )
63
+ ) . Stream ( )
64
+ )
65
+ )
66
+ ) . Value ( ) ;
46
67
47
- //Create large file
48
- new LengthOf (
49
- new InputOf (
50
- new TeeInputStream (
51
- new MemoryStream (
52
- new BytesOf (
53
- new Text . Joined ( ", " ,
54
- new HeadOf < string > (
55
- new Endless < string > ( "Hello World" ) ,
56
- 1000
68
+ Assert . True (
69
+ new LengthOf (
70
+ new InputOf (
71
+ new TeeInputStream (
72
+ new InputOf (
73
+ inputPath
74
+ ) . Stream ( ) ,
75
+ new WriterAsOutputStream (
76
+ new StreamWriter ( outputPath )
77
+ )
57
78
)
58
79
)
59
- ) . AsBytes ( )
60
- ) ,
61
- new OutputTo (
62
- new Uri ( inputPath )
63
- ) . Stream ( )
64
- )
65
- )
66
- ) . Value ( ) ;
67
-
68
- //Read from large file and write to output file (make a copy)
69
- var filestream = new FileStream ( outputPath , FileMode . OpenOrCreate , FileAccess . Write , FileShare . Write ) ;
70
-
71
- long left =
72
- new LengthOf (
73
- new InputOf (
74
- new TeeInputStream (
75
- new InputStreamOf (
76
- new Uri ( Path . GetFullPath ( inputPath ) )
77
- ) ,
78
- new WriterAsOutputStream (
79
- new StreamWriter ( filestream )
80
- )
81
- )
82
- )
83
-
84
- ) . Value ( ) ;
85
-
86
- long right =
87
- new LengthOf (
88
- new InputOf (
89
- new Uri ( Path . GetFullPath ( outputPath ) )
90
- )
91
- ) . Value ( ) ;
92
-
93
- Assert . True ( left == right , "input and output are not the same size" ) ;
80
+ ) . Value ( ) ==
81
+ new LengthOf (
82
+ new InputOf (
83
+ new Uri ( Path . GetFullPath ( outputPath ) )
84
+ )
85
+ ) . Value ( ) ,
86
+ "input and output are not the same size"
87
+ ) ;
88
+ }
89
+ }
94
90
}
95
91
96
92
[ Fact ]
97
- public void TryRead ( )
93
+ public void RejectsReading ( )
98
94
{
99
- byte [ ] bytes = { } ;
100
- var stream = new WriterAsOutputStream (
101
- new StreamWriter ( new MemoryStream ( ) )
102
- ) ;
103
95
Assert . ThrowsAny < NotImplementedException > (
104
- ( ) => stream . Read ( bytes , 0 , 1 ) ) ;
96
+ ( ) => new WriterAsOutputStream (
97
+ new StreamWriter (
98
+ new MemoryStream ( )
99
+ )
100
+ ) . Read ( new byte [ ] { } , 0 , 1 )
101
+ ) ;
105
102
}
106
103
107
104
[ Fact ]
108
- public void TrySeek ( )
105
+ public void RejectsSeeking ( )
109
106
{
110
- var stream = new WriterAsOutputStream (
111
- new StreamWriter ( new MemoryStream ( ) )
112
- ) ;
113
107
Assert . ThrowsAny < NotImplementedException > (
114
- ( ) => stream . Seek ( 3L , SeekOrigin . Begin ) ) ;
108
+ ( ) => new WriterAsOutputStream (
109
+ new StreamWriter (
110
+ new MemoryStream ( )
111
+ )
112
+ ) . Seek ( 3L , SeekOrigin . Begin )
113
+ ) ;
115
114
}
116
115
117
116
[ Fact ]
118
- public void TrySetLength ( )
117
+ public void RejectsSettingLength ( )
119
118
{
120
- var stream = new WriterAsOutputStream (
121
- new StreamWriter ( new MemoryStream ( ) )
122
- ) ;
123
119
Assert . ThrowsAny < NotImplementedException > (
124
- ( ) => stream . SetLength ( 5L ) ) ;
120
+ ( ) => new WriterAsOutputStream (
121
+ new StreamWriter (
122
+ new MemoryStream ( )
123
+ )
124
+ ) . SetLength ( 5L )
125
+ ) ;
125
126
}
126
127
}
127
128
}
0 commit comments