2008 Advent Calendar December 15th




1: public class Advent15
2: {
3: private FileUtilWithDelete SetUpReadable(string content)
4: {
5: FileUtilWithDelete file = new FileUtilWithDelete(“SomeFile.txt”);
6: file.Create(content);
7: return file;
8: }
9:  
10: private FileUtilWithDelete SetUpUnreadable(string content)
11: {
12: FileUtilWithDelete file = SetUpReadable(content);
13: file.Readable = false;
14: return file;
15: }
16:  
17: [Fact]
18: public void TestReadReadableFile()
19: {
20: using (FileUtilWithDelete file = SetUpReadable(“CONTENT”))
21: {
22: string content = file.Read();
23: Assert.Equal<string>(“CONTENT”, content);
24: }
25: }
26:  
27: [Fact]
28: public void TestReadUnreadableFile()
29: {
30: using (FileUtilWithDelete file = SetUpUnreadable(“SHOULD NOT BE ABLE TO READ THIS”))
31: {
32: Assert.Throws<AccessViolationException>(() => { file.Read(); });
33: }
34: }
35: }

The two setup methods does not really feel necessary. Why not add another parameter to it and control readability that way?

Comments (0)