Exemple #1
0
        public void InitialTest()
        {
            // Test Tab collection content
            MainViewModel mainViewModel = new MainViewModel();

            Assert.AreEqual(false, mainViewModel.Tabs[0] == null);
            Assert.AreEqual(true, mainViewModel.Tabs[0].GetType() == typeof(PsExecViewModel));

            // Test config file and directory existance
            PsExecViewModel psExecViewModel = (PsExecViewModel)mainViewModel.Tabs[0];

            Assert.AreEqual(true, psExecViewModel.ModulePath.Equals(".\\Scripts\\"));
            Assert.AreEqual(true, psExecViewModel.ScriptCategoryBrowser.Count > 0);

            // Test exceptions if folders does not exist

            // Test category directories and script files, demands an existing ps script file
            Assert.AreEqual(true, psExecViewModel.ScriptCategoryBrowser.Count > 0);
            Assert.AreEqual(true, psExecViewModel.SelectedScriptCategory.Length > 0);
            Assert.AreEqual(true, psExecViewModel.ScriptFileBrowser.Count > 0);
            Assert.AreEqual("", psExecViewModel.SelectedScriptFile);
            Assert.AreEqual(true, psExecViewModel.ScriptCategoryBrowser[0].FriendlyName.Equals("Category1"));
            Assert.AreEqual(true, psExecViewModel.ScriptFileBrowser[0].Equals("test1"));

            // Test exception if script files does not exist

            Assert.AreEqual(false, psExecViewModel.IsBusy);
            Assert.AreEqual(true, psExecViewModel.CanInteract);

            // Test execute button (input field contents)
            Assert.AreEqual(false, ExecuteButtonIsActive(psExecViewModel));
        }
Exemple #2
0
        public void NewCategoryChosenTest()
        {
            MainViewModel   mainViewModel   = new MainViewModel();
            PsExecViewModel psExecViewModel = (PsExecViewModel)mainViewModel.Tabs[0];

            // Change category
            psExecViewModel.SelectedScriptCategory = "Category2";

            // Test new script and category data
            Assert.AreEqual(true, psExecViewModel.ScriptVariables.Count == 0);
            Assert.AreEqual("", psExecViewModel.SelectedScriptFile);
            Assert.AreEqual(true, psExecViewModel.ScriptCategoryBrowser[1].FriendlyName.Equals("Category2"));
            Assert.AreEqual(true, psExecViewModel.SelectedScriptCategory.Equals("Category2"));
            Assert.AreEqual(true, psExecViewModel.ScriptFileBrowser[0].Equals("test3"));

            // Test if output strings are not yet defined
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionOutputRaw);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionOutputCustom);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionErrorException);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionErrorDetails);

            Assert.AreEqual(false, psExecViewModel.IsBusy);
            Assert.AreEqual(true, psExecViewModel.CanInteract);

            // Test execute button
            Assert.AreEqual(false, ExecuteButtonIsActive(psExecViewModel));
        }
Exemple #3
0
        public void ScriptExecutedResetStatus()
        {
            MainViewModel   mainViewModel   = new MainViewModel();
            PsExecViewModel psExecViewModel = (PsExecViewModel)mainViewModel.Tabs[0];

            psExecViewModel.SelectedScriptFile = "test2";

            // Ensures script input details are deleted when script has been executed
            psExecViewModel.SelectedScriptFile = "";
            psExecViewModel.ClearScriptSession(); // Shall be called after execution
            Assert.AreEqual(true, psExecViewModel.IsScriptSelected == false);
            Assert.AreEqual(true, psExecViewModel.ScriptTextVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptUsernameVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptPasswordVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptMultiLineVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptVariables.Count == 0);


            // Test if output strings are not yet defined
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionOutputRaw);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionOutputCustom);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionErrorException);
            Assert.AreEqual(null, psExecViewModel.ScriptExecutionErrorDetails);

            // Test execute button
            Assert.AreEqual(false, ExecuteButtonIsActive(psExecViewModel));
        }
Exemple #4
0
        public void ScriptChosenInCurrentCategoryTest()
        {
            MainViewModel   mainViewModel   = new MainViewModel();
            PsExecViewModel psExecViewModel = (PsExecViewModel)mainViewModel.Tabs[0];

            Assert.AreEqual(true, psExecViewModel.ScriptFileBrowser.Count > 0);
            Assert.AreEqual("", psExecViewModel.SelectedScriptFile);

            // Test selecting a new script with two string input fields,
            // one int input field and one multiline input field
            psExecViewModel.SelectedScriptFile = "test2";
            Assert.AreEqual(true, psExecViewModel.SelectedScriptPath.Equals(".\\Scripts\\Category1\\test2.ps1")); // tenkt feil?
            Assert.AreEqual(true, psExecViewModel.ScriptExecutionErrorException == null);
            Assert.AreEqual(true, psExecViewModel.ScriptExecutionErrorDetails == null);
            Assert.AreEqual(true, psExecViewModel.ScriptExecutionOutputRaw == null);
            Assert.AreEqual(true, psExecViewModel.ScriptExecutionOutputCustom == null);
            Assert.AreEqual(true, psExecViewModel.ScriptUsernameVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptPasswordVariables.Count == 0);
            Assert.AreEqual(true, psExecViewModel.ScriptTextVariables.Count == 3);
            Assert.AreEqual(true, psExecViewModel.ScriptMultiLineVariables.Count == 1);

            Assert.AreEqual(false, psExecViewModel.IsBusy);
            Assert.AreEqual(true, psExecViewModel.CanInteract);

            // Test execute button
            Assert.AreEqual(false, ExecuteButtonIsActive(psExecViewModel));
        }
Exemple #5
0
 // Returns true if all conditions are met to activate the execute button.
 private bool ExecuteButtonIsActive(PsExecViewModel psExecViewModel)
 {
     if (psExecViewModel.IsScriptSelected == false)
     {
         return(false);
     }
     foreach (PsGui.Models.PowershellExecuter.ScriptArgument arg in psExecViewModel.ScriptTextVariables)
     {
         if (arg.InputValue != null && arg.InputValue.Equals(""))
         {
             return(false);
         }
     }
     foreach (PsGui.Models.PowershellExecuter.ScriptArgument arg in psExecViewModel.ScriptUsernameVariables)
     {
         if (arg.InputValue != null && arg.InputValue.Equals(""))
         {
             return(false);
         }
     }
     foreach (PsGui.Models.PowershellExecuter.ScriptArgument arg in psExecViewModel.ScriptPasswordVariables)
     {
         if (arg.InputValue != null && arg.InputValue.Equals(""))
         {
             return(false);
         }
     }
     foreach (PsGui.Models.PowershellExecuter.ScriptArgument arg in psExecViewModel.ScriptMultiLineVariables)
     {
         if (arg.InputValue != null && arg.InputValue.Equals(""))
         {
             return(false);
         }
     }
     return(true);
 }