pszczyg

Automatic invocation of the cmdlets from test project

May 6th, 2021
552
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using NUnit.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Management.Automation.Runspaces;
  5.  
  6. namespace CoreView.Management.PowerShell.Tests.InvokeCvApi {
  7.  
  8.     [TestFixture(Category = "Integration")]
  9.     public class InvokeCvApiIntegrationTests {
  10.         [Test]
  11.         public void Cmdlet_Must_Have_Correct_Base_Parameters_Provided() {
  12.             using (var powerShell = PSHostHelper.GetPowerShellHost()) {
  13.                 powerShell.AddCommand("Invoke-CVApi");
  14.                 powerShell.AddParameter("Username", "informix");
  15.                 powerShell.AddParameter("Password", "informix");
  16.                 powerShell.AddParameter("Function",
  17.                     new FunctionInvocationData("branchStatus",
  18.                         new List<FunctionInvocationParam> {new FunctionInvocationParam("Status", "O")}));
  19.                 dynamic results = powerShell.Invoke();
  20.                 //Assert.That(ResultOk(results));
  21.             }
  22.         }
  23.     }
  24.  
  25.     public static class PSHostHelper {
  26.         public static System.Management.Automation.PowerShell GetPowerShellHost() {
  27.             var iss = InitialSessionState.CreateDefault();
  28. #if DEBUG
  29.             iss.ImportPSModule(new[] { @"..\..\..\CoreView.Management.PowerShell\bin\Debug\net48\CoreView.Management.PowerShell.dll", "-Force" });
  30. #else
  31.             iss.ImportPSModule(new[] { @"..\..\..\CoreView.Management.PowerShell\bin\Release\net48\CoreView.Management.PowerShell.dll", "-Force" });
  32. #endif
  33.             var ps = System.Management.Automation.PowerShell.Create(iss);
  34.             return ps;
  35.         }
  36.     }
  37. }
RAW Paste Data