title: Set System.Diagnostics.Activity.Current in MS Unit Tests (.NET Core)
body: <p>I have domain classes that reference System.Diagnostics.Activity.Current.Id in my web api.  It uses this value as a correlation Id once the object is serialized and stored in Cosmos.  I have no issue getting this value when making calls into the API.  However if I try to reference this value in my domain unit tests, the System.Diagnostics.Activity.Current is null.  I have tried setting it in my unit test functions but it is still always null in my domain.  </p>
  
  <pre><code>System.Diagnostics.Activity.Current = new System.Diagnostics.Activity("MyUnitTests");
  </code></pre>
  
  <p>I know System.Diagnostics.Activity.Current is driven from the current HttpContext but there also is no current http context in my domain unit tests.  How can I make this work with my unit tests?</p>
  
  <p>Example:
  <strong>Domain Class</strong></p>
  
  <pre><code>public class Company
  {  
      public int CompanyId { get; private set; }        
      public string Name { get; private set; }
      public string CorrelationId { get { return System.Diagnostics.Activity.Current.Id; } }
  }
  </code></pre>
  
  <p><strong>Unit Test</strong></p>
  
  <pre><code>    [TestMethod]
      public void MyTest()
      {
          Company c = new Company();
          Assert.AreNotEqual(string.Empty, c.CorrelationId);
      }
  </code></pre>
  
  <p>This unit test throws a null reference exception because System.Diagnostics.Activity.Current is null.</p>