I use MSTest.Framework/MSTest.TestAdapter 2.2.10.
I'm trying to pass test data to Test_Method by using DynamicData attribute. When MyDateTime is struct and I debug Test_Method, the _date field of testData has wrong date. But, when I change MyDateTime to class, then I get the correct date. What can be the problem? Is there any issue with boxing/unboxing of my MyDateTime?
[TestMethod]
[DynamicData(nameof(DataForTestMethod), DynamicDataSourceType.Property)]
public void Test_Method(MyDateTime testData)
{
}
public struct MyDateTime
{
private DateTime _date;
public MyDateTime(DateTime dt)
{
_date = dt;
}
}
public static IEnumerable<object[]> DataForTestMethod
{
get
{
var dt = new DateTime(2022,04,30,21,04,22);
var myDate = new MyDateTime(dt);
yield return new object[] { myDate };
}
}
After spending some time with a .net decompiler, it seems that a struct should implement ISerializable interface for the MSTest framework to correctly return data through DynamicDataAttribute. The body of ISerializable.GetObjectData can even be empty(!). I cannot find what code is responsible for loading DynamicDataAttribute to explain this, but it seems to work if I just add ISerializable interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With