title: How can I pass dynamic objects into an NUnit TestCase function?
body: <p>I am writing a data-intensive application. I have the following tests. They work, but they're pretty redundant.</p>
  <pre><code>[Test]
  public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InMerchantAggregateTotals_SetsWarning()
  {
      report.Merchants[5461324658456716].AggregateTotals.ItemCount = 0;
      report.Merchants[5461324658456716].AggregateTotals._volume = 0;
      report.Merchants[5461324658456716].AggregateTotals._houseGross = 1;
  
      report.DoSanityCheck();
  
      Assert.IsTrue(report.FishyFlag);
      Assert.That(report.DataWarnings.Where(x=&gt; x is Reports.WarningObjects.ImbalancedVariables &amp;&amp; x.mid == 5461324658456716 &amp;&amp; x.lineitem == &quot;AggregateTotals&quot;).Count() &gt; 0);
  }
  
  
  [Test]
  public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InAggregateTotals_SetsWarning()
  {
      report.AggregateTotals.ItemCount = 0;
      report.AggregateTotals._volume = 0;
      report.AggregateTotals._houseGross = 1;
  
      report.DoSanityCheck();
  
      Assert.IsTrue(report.FishyFlag);
      Assert.That(report.DataWarnings.Where(x=&gt; x is Reports.WarningObjects.ImbalancedVariables &amp;&amp; x.mid == null &amp;&amp; x.lineitem == &quot;AggregateTotals&quot;).Count() &gt; 0);
  }
  
  
  [Test]
  public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InAggregateTotalsLineItem_SetsWarning()
  {
      report.AggregateTotals.LineItem[&quot;WirelessPerItem&quot;].ItemCount = 0;
      report.AggregateTotals.LineItem[&quot;WirelessPerItem&quot;]._volume = 0;
      report.AggregateTotals.LineItem[&quot;WirelessPerItem&quot;]._houseGross = 1;
  
      report.DoSanityCheck();
  
      Assert.IsTrue(report.FishyFlag);
      Assert.That(report.DataWarnings.Where(x=&gt; x is Reports.WarningObjects.ImbalancedVariables &amp;&amp; x.mid == null &amp;&amp; x.lineitem == &quot;WirelessPerItem&quot;).Count() &gt; 0);
  }
  </code></pre>
  <p>The same properties are modified at the beginning, just as children of different container objects, and a couple of values in the assertion change at the end.</p>
  <p>I need to write a few dozen of these, checking different properties. So I want to parameterize the test. The trick is passing the container object as a parameter to the test. The container object is instantiated in the test fixture SetUp.</p>
  <p>I want to achieve something like this:</p>
  <pre><code>[TestCase(report.AggregateTotals.LineItem[&quot;WirelessPerItem&quot;], 0, &quot;WirelessPerItem&quot;)]
  [TestCase(report.AggregateTotals, 4268435971532164, &quot;AggregateTotals&quot;)]
  [TestCase(report.Merchants[5461324658456716].AggregateTotals, 5461324658456716, &quot;WirelessPerItem&quot;)]
  [TestCase(report.Merchants[4268435971532164].LineItem[&quot;EBTPerItem&quot;], 4268435971532164, &quot;EBTPerItem&quot;)]
  public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_TestCase_SetsWarning(object container, long mid, string field)
  {
      container.ItemCount = 0;
      container._volume = 0;
      container._houseGross = 1;
  
      report.DoSanityCheck();
  
      Assert.IsTrue(report.FishyFlag);
      Assert.That(report.DataWarnings.Where(x=&gt; x is Reports.WarningObjects.ImbalancedVariables &amp;&amp; x.mid == mid &amp;&amp; x.lineitem == field).Count() &gt; 0);
  }
  </code></pre>
  <p>But that doesn't work and I'm not sure how to make it work, or if it's possible.</p>