如何在 .Net Core 中对 ADF PipeLineRun 进行单元测试?

How to unit test ADF PipeLineRun in .Net Core?

Net 核心应用程序,我正在使用 ADF SDK。我有一些方法可以执行如下 ADF 操作

public PipelineRun GetADFPipeLineMetaData(IDataFactoryManagementClient dataFactoryManagementClient, string RunId)
{
  PipelineRun pipelineRun = dataFactoryManagementClient.PipelineRuns.Get(_adfClient.ResourceGroupName, _adfClient.DataFactoryName, RunId);
                return pipelineRun;
}

我正在为上面的 returns PipelineRun:

写一个单元测试用例
 PipelineRun pipelineRun = new PipelineRun();
 _azureDataFactoryRepository.Setup(x => x.GetADFPipeLineMetaData(It.IsAny<IDataFactoryManagementClient>(), It.IsAny<string>())).Returns(pipelineRun);

在上面的代码中,问题是我想为 PipelineRun 设置一些值,如果我尝试这样的事情

 PipelineRun pipelineRun = new PipelineRun() { Status = ""};

它将 return 属性 或无法分配索引器 PipeLineRun.Status - 它是只读的。所以我在 returning PipeLineRun 中遇到了一个问题。有什么办法可以处理上面的单元测试用例吗?

如有任何帮助,我们将不胜感激。谢谢。

您需要使用其他构造函数而不是默认构造函数

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.datafactory.models.pipelinerun.-ctor

public PipelineRun (System.Collections.Generic.IDictionary<string,object> additionalProperties = default, 
    string runId = default, string runGroupId = default, bool? isLatest = default, 
    string pipelineName = default, System.Collections.Generic.IDictionary<string,string> parameters = default,
    System.Collections.Generic.IDictionary<string,string> runDimensions = default, 
    Microsoft.Azure.Management.DataFactory.Models.PipelineRunInvokedBy invokedBy = default, 
    DateTime? lastUpdated = default, DateTime? runStart = default, DateTime? runEnd = default, 
    int? durationInMs = default, string status = default, string message = default);

这将允许设置特定成员。

并且由于这些构造函数参数是可选的,因此您可以只显式声明要设置的参数

//...

PipelineRun pipelineRun = new PipelineRun(status = "YourStatusHere");

//...