我正在尝试为 .NET Core 应用程序创建 MSTest 方法

I'm trying to create MSTest method for .NET Core application

[TestMethod]
[DataRow("connectionstringvalue",
"[{'ColumName':'neid','Value':'1','Operator':'Equal'}]",
"neid",
Sort.ASC,

what value should be given here for model binding. PaginationDto in the method parameter is >model class having page and recordsperpage properties

) ]

public void MethodTest(string connectionString,string? filters, string sortColumn, Sort sort, PaginationDto? pagination)
{
var serviceProvider = new ServiceCollection()
.AddLogging()
.BuildServiceProvider();



var mediator = new Mock<IMediator>();



var factory = serviceProvider.GetService<ILoggerFactory>();



var logger = factory.CreateLogger<HController>();



HController controller = new HController (logger, **mediator.Object**, _configuration);
Task<ActionResult<List<basicDto>>> result = controller.methodname(connectionString, filters, sortColumn, sort, pagination);

// 1. how to handle the value returned from my controller Assert.AreEqual("", "Hi! Reader"); }

1.how to handle the value returned from my controller

2.how to pass input value for model class property

由于属性只允许常量表达式,因此您不能在此处使用 DataRow(因为我假设 PaginationDto 实际上不是 enum,而是 classstruct ).

但是,您可以使用 DynamicData。在“简而言之”中,它是这样工作的:

[TestClass]
public class Test
{
   [TestMethod]
   [DynamicData(nameof(MethodTestData), DynamicDataSourceType = DynamicDataSourcetype.Property)]
   public void Method(string connectionString,
       string? filters, string sortColumn, Sort sort, 
       PaginationDto? pagination)
   {
        // test code
   }

   // The property must be public, static and have return type IEnumerable<object[]>
   public static IEnumerable<object[]> MethodTestData
   {
       get
       {
            // Return one array/set of arguments per call of Method()
            yield return new object[]
            { 
               // each item of the array is a parameter (value) to Method()
               "the connection string",
               "the filters",
               "the sort column",
               Sort.Asc,
               new PaginationDto()
            };
       }
   }

}

至于你的其他问题,我建议你post单独提问。一个提示,你也可以有异步测试方法(如果你的控制器方法也是异步的)。