public void Dispose()
            {
                var processName = Path.GetFileNameWithoutExtension(_toolPath);

                using (new ProcessKiller(processName)) // Make sure tool process is closed and file handles released
                {
                    // Get rid of our temp files
                    _movedDirectory.Dispose();
                }
            }
Exemple #2
0
 public void Dispose()
 {
     _movedDirectory.Dispose();
 }
        public void TestInstallFromZip()
        {
            // Using clause here overwrites failure exception when it fails
            var movedDir = new MovedDirectory(ToolDescriptionHelpers.GetToolsDirectory(), Program.StressTest);
            try
            {
                Settings.Default.ToolList.Clear();
                var testFilesDir = new TestFilesDir(TestContext, COMMAND_FILE);
                {
                    // Test bad input
                    const string badFileName = "BadFilePath";
                    Assert.IsFalse(File.Exists(badFileName));
                    const string command = "--tool-add-zip=" + badFileName;
                    string output = RunCommand(command);
                    Assert.IsTrue(output.Contains(Resources.CommandLine_ImportToolsFromZip_Error__the_file_specified_with_the___tool_add_zip_command_does_not_exist__Please_verify_the_file_location_and_try_again_));
                }
                {
                    string notZip = testFilesDir.GetTestPath("Broken_file.sky");
                    Assert.IsTrue(File.Exists(notZip));
                    string command = "--tool-add-zip=" + notZip;
                    string output = RunCommand(command);
                    Assert.IsTrue(output.Contains(Resources.CommandLine_ImportToolsFromZip_Error__the_file_specified_with_the___tool_add_zip_command_is_not_a__zip_file__Please_specify_a_valid__zip_file_));
                }
                {
                    var uniqueReportZip = testFilesDir.GetTestPath("UniqueReport.zip");
                    Assert.IsTrue(File.Exists(uniqueReportZip));
                    string command = "--tool-add-zip=" + uniqueReportZip;
                    string output = RunCommand(command);

                    Assert.IsTrue(Settings.Default.ToolList.Count == 1);
                    ToolDescription newTool = Settings.Default.ToolList.Last();
                    Assert.AreEqual("HelloWorld", newTool.Title);
                    Assert.IsTrue(newTool.OutputToImmediateWindow);
                    Assert.AreEqual("UniqueReport", newTool.ReportTitle);
                    string path = newTool.ToolDirPath;
                    Assert.IsTrue(File.Exists(Path.Combine(path, "HelloWorld.exe")));
                    Assert.IsTrue(output.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_,"HelloWorld")));
                    //Try to add the same tool again. Get conflicting report and tool with no overwrite specified.
                    string output1 = RunCommand(command);
                    Assert.IsTrue(output1.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwrite_Error__There_is_a_conflicting_tool + Resources.AddZipToolHelper_ShouldOverwrite__in_the_file__0_, "UniqueReport.zip")));
                    Assert.IsTrue(
                        output1.Contains(
                            Resources.AddZipToolHelper_ShouldOverwrite_Please_specify__overwrite__or__parallel__with_the___tool_zip_conflict_resolution_command_));
                    //Now run with overwrite specified.
                    string output2 = RunCommand(command, "--tool-zip-conflict-resolution=overwrite");
                    Assert.IsTrue(output2.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwrite_Overwriting_tool___0_,"HelloWorld")));
                    //Now install in parallel.
                    string output3 = RunCommand(command, "--tool-zip-conflict-resolution=parallel");
                    Assert.IsTrue(output3.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "HelloWorld1")));
                    ToolDescription newTool1 = Settings.Default.ToolList.Last();
                    Assert.AreEqual("HelloWorld1", newTool1.Title);
                    Assert.IsTrue(newTool1.OutputToImmediateWindow);
                    Assert.AreEqual("UniqueReport", newTool1.ReportTitle);
                    string path1 = newTool1.ToolDirPath;
                    Assert.IsTrue(File.Exists(Path.Combine(path1, "HelloWorld.exe")));
                    //Cleanup.
                    Settings.Default.ToolList.Clear();
                    DirectoryEx.SafeDelete(ToolDescriptionHelpers.GetToolsDirectory());
                    Settings.Default.PersistedViews.RemoveView(PersistedViews.ExternalToolsGroup.Id, "UniqueReport");
                    Settings.Default.PersistedViews.RemoveView(PersistedViews.ExternalToolsGroup.Id, "UniqueReport1");
                }
                {
                    //Test working with packages and ProgramPath Macro.
                    var testCommandLine = testFilesDir.GetTestPath("TestCommandLine.zip");
                    Assert.IsTrue(File.Exists(testCommandLine));
                    string command = "--tool-add-zip=" + testCommandLine;
                    string output = RunCommand(command);
                    StringAssert.Contains(output, Resources.AddZipToolHelper_InstallProgram_Error__Package_installation_not_handled_in_SkylineRunner___If_you_have_already_handled_package_installation_use_the___tool_ignore_required_packages_flag);
                    string output1 = RunCommand(command, "--tool-ignore-required-packages");
                    StringAssert.Contains(output1, string.Format(
                        Resources.AddZipToolHelper_FindProgramPath_A_tool_requires_Program__0__Version__1__and_it_is_not_specified_with_the___tool_program_macro_and___tool_program_path_commands__Tool_Installation_Canceled_,
                        "Bogus",
                        "2.15.2"));

                    string path = testFilesDir.GetTestPath("NumberWriter.exe");
                    string output2 = RunCommand(command, "--tool-ignore-required-packages",
                                                "--tool-program-macro=Bogus,2.15.2",
                                                "--tool-program-path=" + path);

                    StringAssert.Contains(output2, string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "TestCommandline"));
                    ToolDescription newTool = Settings.Default.ToolList.Last();
                    Assert.AreEqual("TestCommandline", newTool.Title);
                    Assert.AreEqual("$(ProgramPath(Bogus,2.15.2))", newTool.Command);
                    Assert.AreEqual("100 12", newTool.Arguments);
                    ProgramPathContainer ppc = new ProgramPathContainer("Bogus", "2.15.2");
                    Assert.IsTrue(Settings.Default.ToolFilePaths.ContainsKey(ppc));
                    Assert.AreEqual(path, Settings.Default.ToolFilePaths[ppc]);
                    Settings.Default.ToolFilePaths.Remove(ppc);
                    Settings.Default.ToolList.Clear();
                    DirectoryEx.SafeDelete(ToolDescriptionHelpers.GetToolsDirectory());
                }
                {
                    //Test working with annotations.
                    var testCommandLine = testFilesDir.GetTestPath("TestAnnotations.zip");
                    Assert.IsTrue(File.Exists(testCommandLine));
                    string command = "--tool-add-zip=" + testCommandLine;
                    string output = RunCommand(command);
                    Assert.IsTrue(output.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "AnnotationTest\\Tool1")));
                    Assert.IsTrue(output.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "AnnotationTest\\Tool2")));
                    Assert.IsTrue(output.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "AnnotationTest\\Tool3")));
                    Assert.IsTrue(output.Contains(string.Format(Resources.CommandLine_ImportToolsFromZip_Installed_tool__0_, "AnnotationTest\\Tool4")));
                }
                {
                    var conflictingAnnotations = testFilesDir.GetTestPath("ConflictAnnotations.zip");
                    Assert.IsTrue(File.Exists(conflictingAnnotations));
                    string command = "--tool-add-zip=" + conflictingAnnotations;
                    string output = RunCommand(command);
                    Assert.IsTrue(
                        output.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwriteAnnotations_There_are_annotations_with_conflicting_names__Please_use_the___tool_zip_overwrite_annotations_command_)));
                    output = RunCommand(command, "--tool-zip-overwrite-annotations=false");
                    Assert.IsTrue(output.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwriteAnnotations_There_are_conflicting_annotations__Keeping_existing_)));
                    Assert.IsTrue(
                        output.Contains(
                            string.Format(
                                Resources.AddZipToolHelper_ShouldOverwriteAnnotations_Warning__the_annotation__0__may_not_be_what_your_tool_requires_,
                                "SampleID")));

                    output = RunCommand(command, "--tool-zip-overwrite-annotations=true");
                    Assert.IsTrue(output.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwriteAnnotations_There_are_conflicting_annotations__Overwriting_)));
                    Assert.IsTrue(output.Contains(string.Format(Resources.AddZipToolHelper_ShouldOverwriteAnnotations_Warning__the_annotation__0__is_being_overwritten,"SampleID")));

                    Settings.Default.AnnotationDefList = new AnnotationDefList();
                    Settings.Default.ToolList.Clear();
                    DirectoryEx.SafeDelete(ToolDescriptionHelpers.GetToolsDirectory());
                }
            }
            finally
            {
                try { movedDir.Dispose(); }
            // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception) {}
            }
        }