Skip to content

Commit 7bc0868

Browse files
committed
test: correcting test for WriterAsOutputStream
1 parent e11a7f3 commit 7bc0868

File tree

1 file changed

+69
-68
lines changed

1 file changed

+69
-68
lines changed

tests/Yaapii.Atoms.Tests/IO/WriterAsOutputStreamTest.cs

+69-68
Original file line numberDiff line numberDiff line change
@@ -35,93 +35,94 @@ public sealed class WriterAsOutputStreamTest
3535
[Fact]
3636
public void WritesContentToFile()
3737
{
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());
4246

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();
4667

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+
)
5778
)
5879
)
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+
}
9490
}
9591

9692
[Fact]
97-
public void TryRead()
93+
public void RejectsReading()
9894
{
99-
byte[] bytes = {};
100-
var stream = new WriterAsOutputStream(
101-
new StreamWriter(new MemoryStream())
102-
);
10395
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+
);
105102
}
106103

107104
[Fact]
108-
public void TrySeek()
105+
public void RejectsSeeking()
109106
{
110-
var stream = new WriterAsOutputStream(
111-
new StreamWriter(new MemoryStream())
112-
);
113107
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+
);
115114
}
116115

117116
[Fact]
118-
public void TrySetLength()
117+
public void RejectsSettingLength()
119118
{
120-
var stream = new WriterAsOutputStream(
121-
new StreamWriter(new MemoryStream())
122-
);
123119
Assert.ThrowsAny<NotImplementedException>(
124-
() => stream.SetLength(5L));
120+
() => new WriterAsOutputStream(
121+
new StreamWriter(
122+
new MemoryStream()
123+
)
124+
).SetLength(5L)
125+
);
125126
}
126127
}
127128
}

0 commit comments

Comments
 (0)