2008 Advent Calendar December 24th
1: namespace Advent24
2: {
3: public class FileUtil_Tests
4: {
5: public FileUtilWithDelete Given_A_Readable_File(string content)
6: {
7: FileUtilWithDelete file = new FileUtilWithDelete("SomeFile.txt");
8: file.Create(content);
9: return file;
10: }
11: }
12:
13: public class FileUtil_Tests_With_Readable_File : FileUtil_Tests
14: {
15: [Fact]
16: public void Reading_A_Readable_File_Returns_File_Content()
17: {
18: using (FileUtilWithDelete file = Given_A_Readable_File("CONTENT"))
19: {
20: string content = file.Read();
21: Assert.Equal<string>("CONTENT", content);
22: }
23: }
24: }
25:
26: public class FileUtil_Tests_With_Unreadable_File : FileUtil_Tests
27: {
28: private FileUtilWithDelete Given_An_Unreadable_File()
29: {
30: FileUtilWithDelete file = Given_A_Readable_File("SHOULD NOT BE ABLE TO READ THIS");
31: file.Readable = false;
32: return file;
33: }
34:
35: [Fact]
36: public void Reading_An_Unreadable_File_Throws_Correct_Exception()
37: {
38: using (FileUtilWithDelete file = Given_An_Unreadable_File())
39: {
40: Assert.Throws<AccessViolationException>(() => { file.Read(); });
41: }
42: }
43: }
44: }
This is the final version of this test. Tomorrow you'll get my final thoughts on this advent calendar.