'MS Test is testing only last two items in DynamicData object

I have following code

private static IEnumerable<object[]> GetTestData() 
{
    return new List<object[]>()
    {
        new object[]{ new XmlConfig { test1 = "test1"}, false },
        new object[]{ new XmlConfig { test1 = "test1", test2 = "test2"}, false },
        new object[]{ new XnlConfig { test1 = "test1", test2 = "test2", test3 = "test3" }, true }
        //and this list continues
    };
}

[DynamicData(nameof(GetTestData), DynamicDataSourceType.Property)]
[TestMethod()]
public void TestConfig(XmlConfig xmlConfig, bool expectedResult)
{
    //act
    // some logic to validate if xmlConfig is ok

    //assert
    Assert.AreEqual(expectedResult, actualResult);
}

Strangely the TestMethod here is always testing only last two objects being returned by Dynamic Data property (for example in above case it is testing only for those objects which had test2 and test3 properties in XmlConfig). While debugging I could see DynamicData property itself is being populated correctly with list of objects I set in get accessor.

Could anyone please let me know if I am missing something here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source