2008 Advent Calendar December 19th
1: public class Advent19
2: {
3: private FileUtilWithDelete SetUp(string content, bool readable)
4: {
5: FileUtilWithDelete file = new FileUtilWithDelete("SomeFile.txt");
6: file.Create(content);
7: file.Readable = readable;
8: return file;
9: }
10:
11: [Fact]
12: public void Reading_A_Readable_File_Returns_File_Content()
13: {
14: using (FileUtilWithDelete file = SetUp("CONTENT", true))
15: {
16: string content = file.Read();
17: Assert.Equal<string>("CONTENT", content);
18: }
19: }
20:
21: [Fact]
22: public void Reading_An_Unreadable_File_Throws_Correct_Exception()
23: {
24: using (FileUtilWithDelete file = SetUp("SHOULD NOT BE ABLE TO READ THIS", false))
25: {
26: Assert.Throws<AccessViolationException>(() => { file.Read(); });
27: }
28: }
29: }
With such good test names, the name of the setup-method embarrasses me. Let's change it!