public void CanCreateCopyFileAction() { var copyFileAction = new CopyFileAction("MySource", "MyDestination"); Assert.IsTrue(copyFileAction.Source == "MySource", string.Format("Source is {0} instead of MySource", copyFileAction.Source)); Assert.IsTrue(copyFileAction.Destination == "MyDestination", string.Format("Destination is {0} instead of MyDestination", copyFileAction.Destination)); }
public void SourceFileTest() { CopyFileAction target = new CopyFileAction(); Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized"); string expected = @"C:\Windows\System32\Config.ini"; string actual; target.SourceFile = expected; actual = target.SourceFile; Assert.AreEqual(expected, actual, "The property 'DestinationFile' is not properly initialized."); Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' is not properly updated"); target.DestinationFolder = @"C:\Windows\System32"; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated"); target.SourceFile = string.Empty; actual = target.SourceFile; 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.SourceFile = @" C:\Windows\System32\Config.ini "; actual = target.SourceFile; Assert.AreEqual(expected, actual, "The property 'DestinationFile' is not not properly trimed."); Assert.IsFalse(target.RefersToUserProfile); target.SourceFile = @"%appdata%\config.txt"; Assert.IsTrue(target.RefersToUserProfile); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jObject = JObject.Load(reader); string actionType = (string)jObject["Action"] ?? string.Empty; ModInstallAction item = null; if (actionType.Equals("MoveFile", StringComparison.InvariantCultureIgnoreCase)) { item = new MoveFileAction(); } else if (actionType.Equals("MoveFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new MoveFilesAction(); } else if (actionType.Equals("DeleteFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new DeleteFilesAction(); } else if (actionType.Equals("ReplaceFile", StringComparison.InvariantCultureIgnoreCase)) { item = new ReplaceFileAction(); } else if (actionType.Equals("ReplaceFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new ReplaceFilesAction(); } else if (actionType.Equals("CopyFile", StringComparison.InvariantCultureIgnoreCase)) { item = new CopyFileAction(); } else if (actionType.Equals("CopyFiles", StringComparison.InvariantCultureIgnoreCase)) { item = new CopyFilesAction(); } else if (actionType.Equals("WriteToFile", StringComparison.InvariantCultureIgnoreCase)) { item = new WriteToFileAction(); } else if (actionType.Equals("QuickBMSExtract", StringComparison.InvariantCultureIgnoreCase)) { item = new QuickBMSExtractAction(); } else if (actionType.Equals("UnluacDecompile", StringComparison.InvariantCultureIgnoreCase)) { item = new UnluacDecompileAction(); } else { item = new ModInstallAction(); } serializer.Populate(jObject.CreateReader(), item); return(item); }
public void CopyFileActionConstructorTest() { CopyFileAction target = new CopyFileAction(); 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.SourceFile, "The property 'SourceFile' is not properly initialized"); Assert.AreEqual(string.Empty, target.DestinationFolder, "The property 'DestinationFile' is not properly initialized"); Assert.IsFalse(target.RefersToUserProfile); }
public void GetXMLActionTest() { CopyFileAction target = new CopyFileAction(); target.SourceFile = @"C:\Windows\Config.txt"; target.DestinationFolder = @"C:\Windows\"; string expected = "<Action>\r\n<ElementType>CustomActions.CopyFileAction</ElementType>\r\n<SourceFile>" + target.SourceFile + "</SourceFile>\r\n<DestinationFolder>" + target.DestinationFolder + "</DestinationFolder>\r\n</Action>"; string actual; actual = target.GetXMLAction(); Assert.AreEqual(expected, actual, "The method 'GetXMLAction' doesn't return the good string."); }
public void ValidateDataTest() { CopyFileAction target = new CopyFileAction(); Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.NotConfigured, "The property 'ConfigurationState' is not properly initialized"); target.SourceFile = @"C:\Windows\System32\file.txt"; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' is not properly updated"); target.DestinationFolder = @"Windows\System32\file.ini"; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated"); target.SourceFile = string.Empty; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' doesn't revert back to Misconfigured"); target.SourceFile = @"C:\Windows\System32\file.txt"; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Configured, "The property 'ConfigurationState' is not properly updated"); target.DestinationFolder = string.Empty; Assert.IsTrue(target.ConfigurationState == GenericAction.ConfigurationStates.Misconfigured, "The property 'ConfigurationState' doesn't revert back to Misconfigured"); }
public void ExecuteFailsOnException() { var copyFileAction = new CopyFileAction(Path.Combine(_sourceDirectory, "ExceptionFile.txt"), Path.Combine(_destinationDirectory, "ExceptionFile.txt")); using (StreamWriter s = File.CreateText(copyFileAction.Destination)) { } using (FileStream fileStream = new FileStream(copyFileAction.Destination, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { UnicodeEncoding uniEncoding = new UnicodeEncoding(); fileStream.Write(uniEncoding.GetBytes("ABC"), 0, 3); fileStream.Lock(0, 1); Assert.That(copyFileAction.Execute() == false); } }
static bool CheckFileCopyAction(CopyFileAction action, List <string> loadErrors) { // Files can only be copied into the game folder if (!ValidGameFilePath(action.DestinationPath)) { loadErrors.Add($"FileCopy - {nameof(action.DestinationPath)}: Provided path must be in the [GAME] folder"); return(false); } // Target file can be either in game or mod path if (!ValidFilePath(action.TargetFile)) { loadErrors.Add($"FileCopy - {nameof(action.TargetFile)}: Provided path must be in the [GAME] or [MOD] folder"); return(false); } return(!string.IsNullOrWhiteSpace(action.TargetFile) && !string.IsNullOrWhiteSpace(action.DestinationPath)); }
public void UserProfileNotificationTest() { CopyFileAction target = new CopyFileAction(); Assert.IsFalse(target.RefersToUserProfile, "The property 'RefersToUserProfile' is not properly initialized"); target.DestinationFolder = @"C:\Temp"; foreach (string folder in CommonData.userProfileRelatedFolders) { target.SourceFile = folder + @"\test.txt"; Assert.IsTrue(target.RefersToUserProfile, folder + " SourceFile should set 'RefersToUserProfile' to true."); } target.SourceFile = @"C:\Temp\Test.txt"; Assert.IsFalse(target.RefersToUserProfile); foreach (string folder in CommonData.userProfileRelatedFolders) { target.DestinationFolder = folder; Assert.IsTrue(target.RefersToUserProfile, folder + " as DestinationFolder should set 'RefersToUserProfile' to true."); } target.DestinationFolder = @"C:\Temp"; Assert.IsFalse(target.RefersToUserProfile); foreach (string folder in CommonData.otherFolders) { target.DestinationFolder = folder; Assert.IsFalse(target.RefersToUserProfile, folder + " as DestinationFolder should not set 'RefersToUserProfile' to true."); } foreach (string folder in CommonData.otherFolders) { target.SourceFile = folder; Assert.IsFalse(target.RefersToUserProfile, folder + " as SourceFile should not set 'RefersToUserProfile' to true."); } }
public void SourceFileToNullText() { CopyFileAction target = new CopyFileAction(); target.SourceFile = null; }
public void DestinationFolderToNullText() { CopyFileAction target = new CopyFileAction(); target.DestinationFolder = null; }
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); }
public void CheckActionNameIsCorrect() { var copyFileAction = new CopyFileAction(Path.Combine(_sourceDirectory, "FileToCopyAlreadyExists.txt"), Path.Combine(_destinationDirectory, "FileToCopyAlreadyExists.txt")); Assert.That(copyFileAction.ActionName == "Copy File", "Action Name was not Copy File"); }
public void ExecuteFailsIfDestinationAlreadyExists() { var copyFileAction = new CopyFileAction(Path.Combine(_sourceDirectory, "FileToCopyAlreadyExists.txt"), Path.Combine(_destinationDirectory, "FileToCopyAlreadyExists.txt")); Assert.That(copyFileAction.Execute() == false && copyFileAction.ErrorMessage.Contains("already exists")); }
public void ExecuteFailsIfSourceDoesNotExist() { var copyFileAction = new CopyFileAction(Path.Combine(_sourceDirectory, "FileToCopyMissing.txt"), Path.Combine(_destinationDirectory, "FileToCopyMissing.txt")); Assert.That(copyFileAction.Execute() == false && copyFileAction.ErrorMessage.Contains("does not exist")); }
public void ExecuteCopiesFile() { var copyFileAction = new CopyFileAction(Path.Combine(_sourceDirectory, "FileToCopy.txt"), Path.Combine(_destinationDirectory, "FileToCopy.txt")); Assert.That(copyFileAction.Execute(), string.Format("File didn't copy {0}", copyFileAction.ErrorMessage)); }