Beispiel #1
0
        public void AppendInstallResultVariable()
        {
            using (var ps = PS.Create())
            {
                var value = new Result()
                {
                    RebootInitiated = true,
                    RebootRequired  = true,
                };

                var variable = new PSVariable("a", value, ScopedItemOptions.AllScope);
                ps.Runspace.SessionStateProxy.PSVariable.Set(variable);

                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);
                ps.AddCommand("test-install").AddArgument("verbose").AddParameter("ResultVariable", "+a").Invoke();

                variable = ps.Runspace.SessionStateProxy.PSVariable.Get("a");
                Assert.IsNotNull(variable);

                value = variable.Value as Result;
                Assert.IsNotNull(value);
                Assert.IsTrue(value.RebootInitiated);
                Assert.IsTrue(value.RebootRequired);
            }
        }
Beispiel #2
0
        public void ExecuteSimulatedProgress()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                ps.AddCommand("test-install").AddArgument("progress").Invoke();

                Assert.AreEqual <int>(8, ps.Streams.Progress.Count, "The number of progress messages returned is incorrect.");

                // Phase 1: No product name or total tick count yet.
                var progress = ps.Streams.Progress[0];
                Assert.AreEqual("Testing", progress.Activity, "The phase 1 activity is incorrect.");
                Assert.AreEqual("Please wait...", progress.StatusDescription, "The phase 1 status description is incorrect.");

                // Phase 2: With product name, estimated tick count, generating script.
                for (int i = 1; i < 4; ++i)
                {
                    progress = ps.Streams.Progress[i];
                    Assert.AreEqual("Testing INSTALL", progress.Activity, "The phase 2 step {0:d} activity is incorrect.", i);

                    if (1 == i)
                    {
                        // ActionStart not run yet.
                        Assert.AreEqual("Please wait...", progress.StatusDescription, "The phase 2 step 1 activity is incorrect.");
                    }
                    else
                    {
                        Assert.AreEqual("Generating script...", progress.StatusDescription, "The phase 2 step {0:d} status description is incorrect.", i);
                    }
                }

                Assert.AreEqual <int>(0, ps.Streams.Progress[1].PercentComplete, "The phase 2 step 1 % complete is incorrect.");
                Assert.AreEqual <int>(7, ps.Streams.Progress[2].PercentComplete, "The phase 2 step 2 % complete is incorrect.");
                Assert.AreEqual <int>(5, ps.Streams.Progress[3].PercentComplete, "the phase 2 step 3 % complete is incorrect.");

                // Phase 3: With product name, estimated tick count, executing script.
                progress = ps.Streams.Progress[4];
                Assert.AreEqual("Testing INSTALL", progress.Activity, "The phase 3 step 1 activity is incorrect.");
                Assert.AreEqual("Generating script...", progress.StatusDescription, "The phase 3 step 1 status description is incorrect.");
                Assert.AreEqual <int>(15, progress.PercentComplete, "The phase 3 step 1 % complete is incorrect.");
                Assert.IsNull(progress.CurrentOperation, "The phase 3 step 1 operation is incorrect.");

                progress = ps.Streams.Progress[5];
                Assert.AreEqual("Testing INSTALL", progress.Activity, "The phase 3 step 2 activity is incorrect.");
                Assert.AreEqual("Testing", progress.StatusDescription, "The phase 3 step 2 status description is incorrect.");
                Assert.AreEqual <int>(15, progress.PercentComplete, "The phase 3 step 2 % complete is incorrect.");
                Assert.IsNull(progress.CurrentOperation, "The phase 3 step 2 operation is incorrect.");

                progress = ps.Streams.Progress[6];
                Assert.AreEqual("Testing INSTALL", progress.Activity, "The phase 3 step 3 activity is incorrect.");
                Assert.AreEqual("Testing", progress.StatusDescription, "The phase 3 step 3 status description is incorrect.");
                Assert.AreEqual <int>(55, progress.PercentComplete, "The phase 3 step 3 % complete is incorrect.");
                Assert.AreEqual("Testing: ActionData", progress.CurrentOperation, "The phase 3 step 2 operation is incorrect.");

                // Make sure progress was completed.
                Assert.AreEqual <ProgressRecordType>(ProgressRecordType.Completed, ps.Streams.Progress[7].RecordType, "Progress not completed.");
            }
        }
Beispiel #3
0
        public void ExecuteVerboseMessage()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                ps.AddCommand("test-install").AddArgument("verbose").AddParameter("verbose").Invoke();

                Assert.AreEqual <int>(1, ps.Streams.Verbose.Count, "The number of verbose messages returned is incorrect.");
                Assert.AreEqual("verbose", ps.Streams.Verbose[0].Message, "The verbose message is incorrect.");
            }
        }
Beispiel #4
0
        public void ExecuteWarningMessage()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                ps.AddCommand("test-install").AddArgument("warning").Invoke();

                Assert.AreEqual <int>(1, ps.Streams.Warning.Count, "The number of warnings returned is incorrect.");
                Assert.AreEqual("warning", ps.Streams.Warning[0].Message, "The warning message is incorrect.");
            }
        }
Beispiel #5
0
        public void ExecuteQueuedActions()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                var objs = ps.AddScript("@('foo', 'bar')").AddCommand("test-install").Invoke();

                Assert.AreEqual <int>(2, objs.Count, "The number of objects returned is incorrect.");
                Assert.AreEqual <int>(2, (int)objs[0].BaseObject, "The execute count is incorrect.");
                Assert.AreEqual <int>(1, (int)objs[1].BaseObject, "The maximum queue count is incorrect.");
            }
        }
Beispiel #6
0
        public void ExecuteErrorMessage()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                ps.AddCommand("test-install").AddArgument("error").Invoke();

                Assert.AreEqual <int>(1, ps.Streams.Error.Count, "The number of errors returned is incorrect.");

                var error = ps.Streams.Error[0];
                Assert.AreEqual <ErrorCategory>(ErrorCategory.WriteError, error.CategoryInfo.Category, "The error category is incorrect.");
                Assert.AreEqual("error", error.TargetObject as string, "The error target is incorrect.");
            }
        }
Beispiel #7
0
        public void ExecuteInstallFailure()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                ps.AddCommand("test-install").AddArgument("fail").Invoke();

                Assert.AreEqual <int>(1, ps.Streams.Error.Count, "The number of errors returned is incorrect.");

                var error = ps.Streams.Error[0];
                Assert.AreEqual <ErrorCategory>(ErrorCategory.NotSpecified, error.CategoryInfo.Category, "The error category is incorrect.");
                Assert.AreEqual("Simulated install failure.", error.Exception.Message, "The exception message is incorrect.");
            }
        }
Beispiel #8
0
        public void AppendNonexistentInstallResultVariable()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);
                ps.AddCommand("test-install").AddArgument("verbose").AddParameter("ResultVariable", "+a").Invoke();

                var variable = ps.Runspace.SessionStateProxy.PSVariable.Get("a");
                Assert.IsNotNull(variable);

                var value = variable.Value as Result;
                Assert.IsNotNull(value);
                Assert.IsFalse(value.RebootInitiated);
                Assert.IsFalse(value.RebootRequired);
            }
        }
Beispiel #9
0
        public void ExecuteQueuedActionsAsChain()
        {
            using (var ps = PS.Create())
            {
                TestInstallCommand.Register(ps.Runspace.RunspaceConfiguration);

                try
                {
                    SystemRestorePoint.DefaultServiceProvider = new SystemRestoreTestService();
                    var objs = ps.AddScript("@('foo', 'bar')").AddCommand("test-install").AddParameter("chain").Invoke();

                    Assert.AreEqual <int>(2, objs.Count, "The number of objects returned is incorrect.");
                    Assert.AreEqual <int>(2, (int)objs[0].BaseObject, "The execute count is incorrect.");
                    Assert.AreEqual <int>(2, (int)objs[1].BaseObject, "The maximum queue count is incorrect.");
                }
                finally
                {
                    SystemRestorePoint.DefaultServiceProvider = null;
                }
            }
        }