2008 Advent Calendar December 17th
1: public class Advent17
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 TestReadReadableFileReturnsFileContent()
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 TestReadUnreadableFileThrowsCorrectException()
23: {
24: using (FileUtilWithDelete file = SetUp("SHOULD NOT BE ABLE TO READ THIS", false))
25: {
26: Assert.Throws<AccessViolationException>(() => { file.Read(); });
27: }
28: }
29: }
Starting all test methods with "Test" does not really add any value to the name either. Naming the tests something that sounds like a real sentence is something I prefer.
Comments
Anonymous
December 17, 2008
Guess I was a little bit too impatient in my comment on the 12th :-). Keep up the good work.Anonymous
December 17, 2008
@Eivind: Just wait... There will be more...