How to unit test ADF PipeLineRun in .Net Core?

Viewed 54

Net core application and I am using ADF SDK. I have some methods which will do ADF operations like below

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

I am writing a unit test case for the above which returns PipelineRun:

 PipelineRun pipelineRun = new PipelineRun();
 _azureDataFactoryRepository.Setup(x => x.GetADFPipeLineMetaData(It.IsAny<IDataFactoryManagementClient>(), It.IsAny<string>())).Returns(pipelineRun);

In the above code problem is I want to set some value to PipelineRun and If I try something like this

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

It will return Property or indexer PipeLineRun.Status cannot be assigned - it is read-only. So I am facing an issue in returning PipeLineRun. Is there any way to handle the above unit test case?

Any help would be greatly appreciated. Thank you.

1 Answers

You'll need to use the other constructor instead of the default constructor

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);

that will allow for setting specific members.

And since those constructor parameters are optional, you can explicitly state only the parameters you want to set

//...

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

//...
Related