0

In the following code, GetTestCaseData is not able to map to ProcessFilterRecords_ReturnsData(). The test explorer does show the yield return value but the debugger never enters ProcessFilterRecords_ReturnsData(). If I pass string directly to JArray.Parse(), that works.

public class SampleClass
{
  private static IEnumerable<TestCaseData> GeTestCaseData
  {
    get
    {
         yield return new TestCaseData("arg1val1", JArray.Parse(JsonConvert.SerializeObject(GenerateList(4))));
         yield return new TestCaseData("arg1val2", JArray.Parse(JsonConvert.SerializeObject(GenerateList(5))));
    }
  }

  [TestCaseSource(typeof(SampleClass), "GeTestCaseData_List")]
  public void ProcessFilterRecords_ReturnsData(string arg1, JArray testdata)
  {
    //Arrange 

    //Act

    //Assert
    Assert.IsTrue(true);
  }

  public static GenerateList(int n)
  {
    var data = new List<int>();
    for(int i=0;i<n;i++)
    {
        data.Add(i);
    }
    return data;    
  }
}
Abhishek Jain
  • 445
  • 2
  • 6
  • 19
  • I feel like I'm getting lost in your (seemingly) circular logic. Can you explain the big picture here? What exactly are you trying to accomplish? – Casey Crookston Dec 02 '19 at 21:47
  • @CaseyCrookston So, I am writing a unit test ProcessFilterRecords_ReturnsData, which accepts arguments - arg1 and testdata and I am trying to set these using yield statements. The yield statements prepare the arguments and one of these arguments is JArray which contains the elements as generated by some method - GenerateList(). Let me know if I need to make it more clear. – Abhishek Jain Dec 02 '19 at 22:24
  • I've never seen code where the unit test is called from another method. – Casey Crookston Dec 03 '19 at 14:12
  • @CaseyCrookston The flow is: ProcessFilterRecords_ReturnData() is the test, but its test data is provided by GetTestCaseData, which, on each yield statement calls GenerateList() and returns new TestCaseData – Abhishek Jain Dec 03 '19 at 19:18

0 Answers0