2008 Advent Calendar December 1st
1: public class Advent1
2: {
3: [Fact]
4: public void TestRead()
5: {
6: // Create a test file
7: IFileUtil file = new FileUtil("SomeFile.txt");
8: file.Create("CONTENT");
9:
10: // Should be able to read file
11: try
12: {
13: file.Read();
14: }
15: catch (Exception)
16: {
17: throw new AssertException("Unexpected exception thrown");
18: }
19:
20: file.Readable = false;
21:
22: // Should NOT be able to read file.
23: try
24: {
25: file.Read();
26: throw new AssertException("No exception thrown");
27: }
28: catch (AccessViolationException)
29: {
30: }
31:
32: // Clean up
33: file.Delete();
34: }
35: }
With this first version of the test there I have not utilized all the features of Xunit.net. I basically do all the verification my self and create test failures by explicitly throwing AssertFailure exceptions. There are several problems with this code but the only problem that will be addressed in the next version of this test is if line 25 throws another exception than AccessViolationException. Xunit.net will save the day but it is quite ugly So in tomorrows version we'll fix that.
Comments
- Anonymous
December 24, 2008
For easier reference, here are the 2008 advent calendar links: Why and advent calendar? What problem?