Пример #1
0
        public void DelayBeforeKillingTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.AreEqual(target.DelayBeforeKilling, 10, "The property 'DelayBeforeKilling' is not properly initialized.");

            int expected = 1;
            int actual;

            target.DelayBeforeKilling = expected;
            actual = target.DelayBeforeKilling;
            Assert.AreEqual(expected, actual, "The property 'DelayBeforeKilling' is not properly set.");
            Assert.IsTrue(target.GetXMLAction().Contains("<DelayBeforeKilling>" + expected.ToString() + "</DelayBeforeKilling>"), "The property 'DelayBeoreKilling' is not correctly encoded in the XmlAction string.");

            expected = 120;
            target.DelayBeforeKilling = expected;
            actual = target.DelayBeforeKilling;
            Assert.AreEqual(expected, actual, "The property 'DelayBeforeKilling' is not properly set.");
            Assert.IsTrue(target.GetXMLAction().Contains("<DelayBeforeKilling>" + expected.ToString() + "</DelayBeforeKilling>"), "The property 'DelayBeoreKilling' is not correctly encoded in the XmlAction string.");

            expected = 120;
            target.DelayBeforeKilling = 121;
            actual = target.DelayBeforeKilling;
            Assert.AreEqual(expected, actual, "The property 'DelayBeforeKilling' doesn't respect maximum.");

            expected = 120;
            target.DelayBeforeKilling = 0;
            actual = target.DelayBeforeKilling;
            Assert.AreEqual(expected, actual, "The property 'DelayBeforeKilling' doesn't respect minimum.");
        }
Пример #2
0
        public void GetXMLActionTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            target.FullPath           = @"C:\Windows\System32\Config.ps1";
            target.Parameters         = @"\u AC76BA86-7AD7-1036-7B44-AB0000000001 \qn \norestart";
            target.KillProcess        = true;
            target.DelayBeforeKilling = 5;
            target.StoreToVariable    = true;

            string expected = "<Action>\r\n<ElementType>CustomActions.RunPowershellScriptAction</ElementType>\r\n<FullPath>" + target.FullPath +
                              "</FullPath>\r\n<Parameters>" + target.Parameters +
                              "</Parameters>\r\n<KillProcess>" + "true" +
                              "</KillProcess>\r\n<DelayBeforeKilling>" + target.DelayBeforeKilling.ToString() + "</DelayBeforeKilling>\r\n<StoreToVariable>true</StoreToVariable>\r\n</Action>";
            string actual;

            actual = target.GetXMLAction();
            Assert.AreEqual(expected, actual, true, "The 'GetXMLAction' method doesn't return the good string");

            target.FullPath = @"  C:\Windows\System32\Config.ps1   ";
            expected        = "<Action>\r\n<ElementType>CustomActions.RunPowershellScriptAction</ElementType>\r\n<FullPath>" + target.FullPath +
                              "</FullPath>\r\n<Parameters>" + target.Parameters +
                              "</Parameters>\r\n<KillProcess>" + "true" +
                              "</KillProcess>\r\n<DelayBeforeKilling>" + target.DelayBeforeKilling.ToString() + "</DelayBeforeKilling>\r\n<StoreToVariable>true</StoreToVariable>\r\n</Action>";
            actual = target.GetXMLAction();
            Assert.AreEqual(expected, actual, true, "The 'GetXMLAction' method doesn't return the good string");
        }
Пример #3
0
        public void ValidateDataTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized");
            target.FullPath = @"C:\Windows\System32\file.vbs";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");
            target.FullPath = string.Empty;
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' doesn't revert back to Misconfigured");
        }
Пример #4
0
        public void RunPowershellScriptActionConstructorTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.AreEqual(55, target.Height, "The property 'Height' is not properly initialized");
            Assert.IsTrue(target.IsTemplate, "The property 'IsTemplate' is not properly initialized");
            Assert.IsFalse(target.IsSelected, "The property 'IsSelected' is not properly initialized");
            Assert.AreEqual(string.Empty, target.FullPath, "The property 'FullPath' is not properly initialized");
            Assert.AreEqual(string.Empty, target.Parameters, "The property 'Parameters' is not properly initialized");
            Assert.IsFalse(target.KillProcess, "The property 'KillProcess' is not properly initialized.");
            Assert.AreEqual(10, target.DelayBeforeKilling, "The property 'DelayBeforeKilling' is not properly initialized.");
            Assert.IsFalse(target.StoreToVariable, "The property 'StoreToVariable' is not properly initialized.");
        }
Пример #5
0
        public void KillProcessTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.IsFalse(target.KillProcess, "The property is not properly initialized.");

            bool expected = true;
            bool actual;

            target.KillProcess = expected;
            actual             = target.KillProcess;
            Assert.AreEqual(expected, actual, "The property is not properly set.");
            Assert.IsTrue(target.GetXMLAction().Contains("<KillProcess>" + expected.ToString() + "</KillProcess>"), "The property 'KillProcess' is not correctly encoded in the XmlAction string.");
        }
Пример #6
0
        public void StoreToVariableTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            bool expected = false;
            bool actual;

            target.StoreToVariable = expected;
            actual = target.StoreToVariable;
            Assert.AreEqual(expected, actual, "The property 'StoreToVariable' is not properly initialized.");
            Assert.IsTrue(target.GetXMLAction().Contains("<StoreToVariable>" + expected.ToString() + "</StoreToVariable>"), "The property 'StoreToVariable' is not correctly encoded in the XmlAction string.");

            expected = true;
            target.StoreToVariable = expected;
            actual = target.StoreToVariable;
            Assert.AreEqual(expected, actual, "The property 'StoreToVariable' is not properly set.");
            Assert.IsTrue(target.GetXMLAction().Contains("<StoreToVariable>" + expected.ToString() + "</StoreToVariable>"), "The property 'StoreToVariable' is not correctly encoded in the XmlAction string.");
        }
Пример #7
0
        public void ParametersTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();
            string expected = "/Uninstall /NoRestart";
            string actual;

            target.Parameters = expected;
            actual            = target.Parameters;
            Assert.AreEqual(expected, actual, "The property 'Parameters' is not properly initialized.");

            target.Parameters = string.Empty;
            actual            = target.Parameters;
            Assert.AreEqual(string.Empty, actual, "The property 'Parameters' can not be set to string.Empty.");

            target.Parameters = "  /Uninstall /NoRestart  ";
            actual            = target.Parameters;
            Assert.AreEqual(expected, actual, "The property 'Parameters' is not properly trimed.");
        }
Пример #8
0
        public void UserProfileNotificationTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.IsFalse(target.RefersToUserProfile, "The property 'RefersToUserProfile' is not properly initialized");

            foreach (string folder in CommonData.userProfileRelatedFolders)
            {
                target.FullPath = folder;
                Assert.IsTrue(target.RefersToUserProfile, folder + " should set 'RefersToUserProfile' to true.");
            }

            target.FullPath = @"C:\Temp";
            Assert.IsFalse(target.RefersToUserProfile);

            foreach (string folder in CommonData.otherFolders)
            {
                target.FullPath = folder;
                Assert.IsFalse(target.RefersToUserProfile, folder + " should not set 'RefersToUserProfile' to true.");
            }
        }
Пример #9
0
        public void FullPathTest()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized");
            string expected = @"C:\Windows\System32\Config.vbs";
            string actual;

            target.FullPath = expected;
            actual          = target.FullPath;
            Assert.AreEqual(expected, actual, "The property 'FullPath' is not properly initialized.");
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");

            target.FullPath = string.Empty;
            actual          = target.FullPath;
            Assert.AreEqual(string.Empty, actual, "The property 'FullPath' cannot be set to string.Empty.");
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' is not properly updated");

            target.FullPath = @"  C:\Windows\System32\Config.vbs   ";
            actual          = target.FullPath;
            Assert.AreEqual(expected, actual, "The property 'FullPath' is not not properly trimed.");
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");
        }
Пример #10
0
        public void FullPathToNullText()
        {
            RunPowershellScriptAction target = new RunPowershellScriptAction();

            target.FullPath = null;
        }
Пример #11
0
        private GenericAction GetElementFromXML(XmlReader reader)
        {
            GenericAction element = null;

            string elementType = reader.ReadElementContentAsString();

            switch (elementType)
            {
            case "CustomActions.AddRegKeyAction":
                element = new AddRegKeyAction();
                break;

            case "CustomActions.AddRegValueAction":
                element = new AddRegValueAction();
                break;

            case "CustomActions.ChangeRegDataAction":
                element = new ChangeRegDataAction();
                break;

            case "CustomActions.ChangeServiceAction":
                element = new ChangeServiceAction();
                break;

            case "CustomActions.CopyFileAction":
                element = new CopyFileAction();
                break;

            case "CustomActions.CreateFolderAction":
                element = new CreateFolderAction();
                break;

            case "CustomActions.CreateShortcutAction":
                element = new CreateShortcutAction();
                break;

            case "CustomActions.CreateTextFileAction":
                element = new CreateTextFileAction();
                break;

            case "CustomActions.DeleteFileAction":
                element = new DeleteFileAction();
                break;

            case "CustomActions.DeleteFolderAction":
                element = new DeleteFolderAction();
                break;

            case "CustomActions.DeleteRegKeyAction":
                element = new DeleteRegKeyAction();
                break;

            case "CustomActions.DeleteRegValueAction":
                element = new DeleteRegValueAction();
                break;

            case "CustomActions.DeleteTaskAction":
                element = new DeleteTaskAction();
                break;

            case "CustomActions.ExecutableAction":
                element = new ExecutableAction();
                break;

            case "CustomActions.ImportRegFileAction":
                element = new ImportRegFileAction();
                break;

            case "CustomActions.KillProcessAction":
                element = new KillProcessAction();
                break;

            case "CustomActions.RebootAction":
                element = new RebootAction();
                break;

            case "CustomActions.RegisterDLLAction":
                element = new RegisterDLLAction();
                break;

            case "CustomActions.RenameFileAction":
                element = new RenameFileAction();
                break;

            case "CustomActions.RenameFolderAction":
                element = new RenameFolderAction();
                break;

            case "CustomActions.RenameRegKeyAction":
                element = new RenameRegKeyAction();
                break;

            case "CustomActions.RenameRegValueAction":
                element = new RenameRegValueAction();
                break;

            case "CustomActions.RunPowershellScriptAction":
                element = new RunPowershellScriptAction();
                break;

            case "CustomActions.RunVbScriptAction":
                element = new RunVbScriptAction();
                break;

            case "CustomActions.ShutdownAction":
                element = new ShutdownAction();
                break;

            case "CustomActions.StartServiceAction":
                element = new StartServiceAction();
                break;

            case "CustomActions.StopServiceAction":
                element = new StopServiceAction();
                break;

            case "CustomActions.UninstallMsiProductByGuidAction":
                element = new UninstallMsiProductByGuidAction();
                break;

            case "CustomActions.UninstallMsiProductByNameAction":
                element = new UninstallMsiProductByNameAction();
                break;

            case "CustomActions.UnregisterDLLAction":
                element = new UnregisterDLLAction();
                break;

            case "CustomActions.UnregisterServiceAction":
                element = new UnregisterServiceAction();
                break;

            case "CustomActions.WaitAction":
                element = new WaitAction();
                break;

            case "CustomActions.InstallMsiAction":
                element = new InstallMsiAction();
                break;

            case "CustomActions.ReturnCode":
                try
                {
                    this.SetReturnCodeFromXml(reader);
                }
                catch (Exception ex)
                {
                    if (this.IsUIEnable)
                    {
                        System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message);
                    }
                    else
                    {
                        throw new Exception(Localizator.Getinstance().GetLocalizedString("UnableToSetReturnCodeFromXmlFile") + "\r\n" + ex.Message);
                    }
                }
                break;

            default:
                if (this.IsUIEnable)
                {
                    System.Windows.Forms.MessageBox.Show(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType);
                }
                else
                {
                    throw new Exception(Localizator.Getinstance().GetLocalizedString("ThisActionHasNotBeenRecognized") + elementType);
                }
                break;
            }

            return(element);
        }