在 MSTest 测试中使用具有 DynamicData 属性的结构时数据无效?

the*_*ist 6 .net c# unit-testing mstest

我使用 MSTest.Framework/MSTest.TestAdapter 2.2.10。

Test_Method我正在尝试使用属性传递测试数据DynamicData。当struct和我 debugMyDateTime时,的字段有错误的日期。但是,当我转到class,我得到了正确的日期。可能是什么问题?我的装箱/拆箱有问题吗?Test_Method_datetestDataMyDateTimeMyDateTime

[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 };
    }
}
Run Code Online (Sandbox Code Playgroud)

the*_*ist 2

在使用 .net 反编译器一段时间后,似乎结构应该实现ISerializableMSTest 框架的接口,以便通过 .net 正确返回数据DynamicDataAttribute。的主体ISerializable.GetObjectData甚至可以是空的(!)。我找不到负责加载的代码DynamicDataAttribute来解释这一点,但如果我只添加接口,它似乎就可以工作ISerializable