2008 Advent Calendar December 23rd




1: namespace Advent23
2: {
3: public class FileUtil_Tests_With_Readable_File
4: {
5: private 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: [Fact]
13: public void Reading_A_Readable_File_Returns_File_Content()
14: {
15: using (FileUtilWithDelete file = Given_A_Readable_File(“CONTENT”))
16: {
17: string content = file.Read();
18: Assert.Equal<string>(“CONTENT”, content);
19: }
20: }
21: }
22:  
23: public class FileUtil_Tests_With_Unreadable_File
24: {
25: private FileUtilWithDelete Given_An_Unreadable_File()
26: {
27: FileUtilWithDelete file = new FileUtilWithDelete(“SomeFile.txt”);
28: file.Create(“SHOULD NOT BE ABLE TO READ THIS”);
29: file.Readable = false;
30: return file;
31: }
32:  
33: [Fact]
34: public void Reading_An_Unreadable_File_Throws_Correct_Exception()
35: {
36: using (FileUtilWithDelete file = Given_An_Unreadable_File())
37: {
38: Assert.Throws<AccessViolationException>(() => { file.Read(); });
39: }
40: }
41: }
42: }

Once again we’ve ended up with the same code in different places. That should be fixed.

Comments (0)