Share via


2008 Advent Calendar December 8th

 

   1:      public class Advent8 : IDisposable
   2:      {
   3:          private IFileUtil m_file;
   4:   
   5:          private void SetUp()
   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();
  20:              Assert.DoesNotThrow(() => { m_file.Read(); });
  21:          }
  22:   
  23:          [Fact]
  24:          public void TestReadFails()
  25:          {
  26:              SetUp();
  27:              m_file.Readable = false;
  28:              Assert.Throws<AccessViolationException>(() => { m_file.Read(); });
  29:          }
  30:      }

Unfortunately I've reintroduced the fact that the actual content is not verified for TestReadOK. And using a constant isn't something I want to do again. But since I'm calling the setup method explicitly I can modify it to accept the desired content. Wouldn't that be neat?