2008 Advent Calendar December 22nd

 

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

So now we have a better name for our specification. But why should everything that has to do with FileUtil be in the same specification?