Share via


The 2008 Advent Calendar situation

So for this year's Advent calendar I'll focus on a made up file utility object. The object is called FileUtil and it implements an interface called IFileUtil which looks like this:

     public interface IFileUtil
    {
        void Create(string content);
        void Delete();
        string Read();
        string Path { get; }
        bool Readable { get; set; }
    }

I think the methods are quite straight forward but a quick walk-through:

  • Create creates a file with given content.
  • Delete deletes the file.
  • Read returns the content of the file.
  • Path returns the path to the file.
  • Readable indicates if the file is readable or not. It is also possible to change permissions (i.e. readable or not) using this property.

The test I will write (in 24 different ways) is a test where I want to verify that the correct exception is thrown when I try to read a file that is not readable. And before I do that I want to make sure the file actually exists and is readable. So basically the test consist of the following steps:

  • Create a test file.
  • Make sure I can read that file.
  • Change the file from readable to not readable.
  • Make sure I can no longer read the file.
  • Remove the test file.

All the tests are written using Xunit.net

Comments

  • Anonymous
    November 30, 2008
    The comment has been removed
  • Anonymous
    December 24, 2008
    For easier reference, here are the 2008 advent calendar links: Why and advent calendar? What problem?