コード例 #1
0
        public void WriteAll()
        {
            var context = new PsCommandContext();
            var output  = RunCommand(ps =>
            {
                ps.AddCommand("Test-TTRiderPSAWriteAll");
                ps.AddParameter("Verbose");
                ps.AddParameter("Debug");
            }, context);

            Assert.AreEqual("WriteObject00\r\nWriteObject01\r\nWriteObject02\r\nWriteObject03",
                            string.Join("\r\n", output));

            Assert.AreEqual("WriteDebug",
                            string.Join("\r\n", context.DebugLines));


            Assert.AreEqual("WriteWarning",
                            string.Join("\r\n", context.WarningLines));

            Assert.AreEqual("WriteVerbose",
                            string.Join("\r\n", context.VerboseLines));

            Assert.AreEqual(1, context.ProgressRecords.Count);
        }
コード例 #2
0
        public void SynchronizationContext()
        {
            var context = new PsCommandContext();
            var output  = RunCommand(ps => ps.AddCommand("Test-TTRiderPSSynchronisationContext"), context);

            Assert.AreEqual(2, output.Count);

            var initialProcessId = output[0];
            var finalProcessId   = output[1];

            Assert.AreEqual(initialProcessId.ToString(), finalProcessId.ToString());
        }
コード例 #3
0
        public static List <PSObject> RunCommand(Action <PowerShell> prepareAction, PsCommandContext context = null)
        {
            var ps = PowerShell.Create();

            ps.Runspace = runspace;

            prepareAction(ps);

            var ret = new List <PSObject>();

            var settings = new PSInvocationSettings
            {
                Host = new TestPsHost(context ?? new PsCommandContext())
            };

            foreach (var result in ps.Invoke(new Object[0], settings))
            {
                Trace.WriteLine(result);
                ret.Add(result);
            }
            return(ret);
        }
コード例 #4
0
 public TestPsHostUserInterface(PsCommandContext host)
 {
     this.host = host;
 }