title: Object reference not set to an instance of an object when trying to xUnit tests
body: <p>I have a class where I implement a timer. I want to make xUnit tests for that class. When i try to run the tests i have the following error</p>
  <blockquote>
  <p>System.NullReferenceException : Object reference not set to an instance of an object.</p>
  </blockquote>
  <p>What i am doing in the constructor shouldn't fixed the specific error? Why not? Can someone explain to me why I got that error?</p>
  <p>GuessingGameTimerTests.cs</p>
  <pre><code>private readonly GuessingGameTimer t;
  
          public GuessingGameTimerTests(GuessingGameTimer t)
          {
              this.t = t;
          }
  
          [Fact]
          public void StartTimerTest()
          {
              t.SetTimer(30000);
              bool expected = t.IsEnabled();
              Assert.True(expected);
          }
  ....
  </code></pre>
  <p>GuessingGameTimer.cs</p>
  <pre><code>public class GuessingGameTimer 
      {
          public event EventHandler OnNumberChanged;
          private System.Timers.Timer NumberGeneratorTimer;
          private int replacetime; // Time in seconds
          private int reSetValue; // Time in seconds
  
          //constractor starts the timer
          public GuessingGameTimer(int replacetime)
          {
              this.replacetime = replacetime;
              reSetValue = replacetime;
              SetTimer(replacetime);
          }
          public void SetTimer(int replacetime)
          {
              NumberGeneratorTimer = new System.Timers.Timer(replacetime);
              NumberGeneratorTimer.Elapsed += OnTick;
              NumberGeneratorTimer.AutoReset = true;
              NumberGeneratorTimer.Enabled = true;
              this.replacetime = getSeconds();
              reSetValue = getSeconds();
          }
          public void ResetTimer()
          {
              NumberGeneratorTimer.AutoReset = true;
              NumberGeneratorTimer.Enabled = true;
              replacetime = reSetValue;
          }
  
          public void StopTimer()
          {
              NumberGeneratorTimer.Enabled = false;
          }
  
          public int getSeconds()
          {
              return replacetime;
          }
  
          public Boolean IsEnabled()
          {
              return NumberGeneratorTimer.Enabled;
          }
  </code></pre>