I am using XUnit test framework and have below Test case created to test my powershell cmndlets and there is no error on build. My PowerShell project is also built in same solution and has been referenced correctly in my test project.
below PowerShell command works locally and give me desired result(as shown below)
$rec = Get-Recording -Project 'Demo'
$rec.Count
64
I am trying to test the same in my unit test case and here is my code. I am not getting any result here, one message which I get in Invoke() line is "Cmdlets derived from PSCmdlet cannot be invoked directly.". can anyone help me in completing this test case and get me the result as I am getting in above Powershell window.
[Fact]
public void TestGetRecordings()
{
// Arrange.
var cmdlet = new GetRecordingsCmd()
{
Project = "Demo"
};
// Act.
var result = cmdlet.Invoke().OfType<List<string>>();
// Assert.True( result, 64 );
My Powershell cmndlet is defined like this. I am just mentioning the class here and how my actual class is inherited:
public class TorgCmd : PSCmdlet
public abstract class GetDocumentsBaseCmd : TorgCmd {}
public class GetRecordingsCmd
: GetDocumentsBaseCmd
{}