コード例 #1
0
        public void FilenameTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized");
            string expected = "Config.txt";
            string actual;

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

            target.FilePath = @"C:\Windows\System32\";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");

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

            target.Filename = "   Config.txt   ";
            actual          = target.Filename;
            Assert.AreEqual(expected, actual, "The property 'Filename' is not not properly trimed.");
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");
        }
コード例 #2
0
        public void FilePathTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

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

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

            target.Filename = "Config.txt";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");

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

            target.FilePath = @"  C:\Windows\System32\Config.ini   ";
            actual          = target.FilePath;
            Assert.AreEqual(target.FilePath, actual, "The property 'DestinationFile' is not not properly trimed.");
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");

            Assert.IsFalse(target.RefersToUserProfile);
            target.FilePath = @"%appData%\Borland";
            Assert.IsTrue(target.RefersToUserProfile);
        }
コード例 #3
0
        public void CreateTextFileActionConstructorTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            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.FilePath, "The Property 'FilePath' is not properly initialized");
            Assert.AreEqual(string.Empty, target.Filename, "The Property 'Filename' is not properly initialized");
            Assert.AreEqual(string.Empty, target.Content, "The Property 'Content' is not properly initialized");
            Assert.IsFalse(target.RefersToUserProfile);
        }
コード例 #4
0
        public void GetXMLActionTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            target.FilePath = @"C:\Windows\System32";
            target.Filename = "Config.ini";
            target.Content  = "This is a test for CreateTextFileAction.";

            string expected = "<Action>\r\n<ElementType>CustomActions.CreateTextFileAction</ElementType>\r\n<FilePath>" + target.FilePath + "</FilePath>\r\n<Filename>" + target.Filename + "</Filename>\r\n<Content>" + target.Content + "</Content>\r\n</Action>";
            string actual;

            actual = target.GetXMLAction();
            Assert.AreEqual(expected, actual, "The GetXMLAction method doesn't return the expected string.");
        }
コード例 #5
0
        public void ContentTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();
            string expected             = "   This is a test for the 'Content' property. Some special characters @|éèöûîñ   ";
            string actual;

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

            target.Content = string.Empty;
            actual         = target.Content;
            Assert.AreEqual(string.Empty, actual, "The property 'Content' can not be set to string.Empty.");
        }
コード例 #6
0
        public void ValidateDataTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized");
            target.FilePath = @"C:\Windows\System32";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' is not properly updated");
            target.Filename = "file.ini";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");
            target.FilePath = string.Empty;
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' doesn't revert back to Misconfigured");
            target.FilePath = @"C:\Windows\System32";
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated");
            target.Filename = string.Empty;
            Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' doesn't revert back to Misconfigured");
        }
コード例 #7
0
        public void UserProfileNotificationTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

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

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

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

            foreach (string folder in CommonData.otherFolders)
            {
                target.FilePath = folder;
                Assert.IsFalse(target.RefersToUserProfile, folder + " should not set 'RefersToUserProfile' to true.");
            }
        }
コード例 #8
0
        public void FilenameToNullTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            target.Filename = null;
        }
コード例 #9
0
        public void ContentToNullTest()
        {
            CreateTextFileAction target = new CreateTextFileAction();

            target.Content = null;
        }
コード例 #10
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);
        }