Share via


2008 Advent Calendar December 11th

 

   1:      public class Advent11 : IDisposable
   2:      {
   3:          private IFileUtil m_file;
   4:   
   5:          private void SetUp(string content)
   6:          {
   7:              m_file = new FileUtil("SomeFile.txt");
   8:              m_file.Create(content);
   9:          }
  10:   
  11:          public void Dispose()
  12:          {
  13:              m_file.Delete();
  14:          }
  15:   
  16:          [Fact]
  17:          public void TestReadOK()
  18:          {
  19:              SetUp("CONTENT");
  20:              string content = m_file.Read();
  21:              Assert.Equal<string>("CONTENT", content);
  22:          }
  23:   
  24:          [Fact]
  25:          public void TestReadFails()
  26:          {
  27:              SetUp("SHOULD NOT BE ABLE TO READ THIS");
  28:              m_file.Readable = false;
  29:              Assert.Throws<AccessViolationException>(() => { m_file.Read(); });
  30:          }
  31:      }

OK, now let's take a look at the test names again. TestReadOK is actually a pretty decent name since it says "Reading works". TestReadFails is not a good name since it does not say anything about why the read operation is expected to fail. Next refactoring step will just be a rename of the test methods.