I have my unit test cases written which tests the Powershell cmdlets built in same solution. All test cases works fine and passes successfully when running locally but once I push it in my Azure devops pipeline, the test cases fails. the error I get is
"CosmosScript.ps1 cannot be loaded because running scripts is disabled on this system.For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170."
. How can I fix this? what wrong am i doing ?
here is my unit test project code:
public class CosmosDataFixture : IDisposable
{
public static readonly string CosmosEndpoint = "https://localhost:8081";
public static readonly string EmulatorKey = "testkey";
public static readonly string DatabaseId = "testdb";
public static readonly string RecordingCollection = "testcollection";
public static string Root = Directory.GetParent( Directory.GetCurrentDirectory() ).Parent.Parent.FullName;
public static DocumentClient client { get; private set; }
public void ReadConfigAsync()
{
client = new DocumentClient( new Uri( CosmosEndpoint ), EmulatorKey,
new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
} );
}
public void ReadAllData(Document client){}
public void CreateDatabaseFromPowerShell()
{
string path = Path.Combine( Root, @"TestData\CosmosScript.ps1" );
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript( path );
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
ReadAllData( client );
}
public CosmosDataFixture()
{
ReadConfigAsync();
CreateDatabaseFromPowerShell();
ReadAllData( client );
}
public void Dispose()
{
DeleteDatabaseFromPowerShell();
}
}
public class CosmosDataTests : IClassFixture<CosmosDataFixture>
{
[fact]
....test cases...