I use Visual Studio 2022 and MS Test. To generate code from proto file I use Grpc.Tools (2.69.0) and Google.Protobuf (3.29.3) nugets.
I don't know how DynamicData
feature works under the hood, but it seems it doesn't populate correctly the step object when the code is generated with protobuf compiler.
Case1:
Step
, Element1
and Element2
are generated with protobuf compiler. When TestMethod
is invoked the step
's Elements are null (see image below).
Case2:
I manually create Step
and Element1
and Element2
classes without protobuf compiler. In this case the step
's elements are not null.
MS Test
namespace TestProject
{
[TestClass]
public class UnitTest
{
[TestMethod]
[DynamicData(nameof(GetTestData), typeof(UnitTest), DynamicDataSourceType.Method)]
public void TestMethod(Step step)
{
}
public static IEnumerable<object[]> GetTestData()
{
yield return new object[] { Step_Element1() };
yield return new object[] { Step_Element2() };
}
private static Step Step_Element1()
{
var step = new Step();
step.Elements.Add(new Element { Element1 = new Element1() });
return step;
}
private static Step Step_Element2()
{
var step = new Step();
step.Elements.Add(new Element { Element2 = new Element2() });
return step;
}
}
}
command.proto
syntax = "proto3";
message Step {
repeated Element elements = 1;
}
message Element1 {
}
message Element2 {
}
message Element {
oneof value {
Element1 element1 = 1;
Element2 element2 = 2;
}
}