public void ToolFormatConverter_FailsIfPluginAssemblyCannotBeLoaded()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "TestTool";
                string       PluginAssemblyPath = GetCurrentAssemblyPath();

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                // Unlike all the other tests, which default-construct the converter, this test
                // provides the converter with a delegate which simulates the failure to load the
                // plugin assembly.
                const string             Message = "Something went dreadfully wrong.";
                AssemblyLoadFileDelegate assemblyLoadFileDelegate = path => throw new BadImageFormatException(Message);

                var converter = new ToolFormatConverter(assemblyLoadFileDelegate);

                Action action = () => converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    OptionallyEmittedData.None,
                    PluginAssemblyPath);

                // The attempt to convert the file should throw the same exception.
                action.Should().Throw <BadImageFormatException>().WithMessage(Message);
            }
        }
        public void ToolFormatConverter_TruncatesOutputFileInOverwriteMode()
        {
            // Using CPPCheck because its empty file format is the simplest
            string emptyCppCheckLog = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<results version=""2"">
    <cppcheck version=""1.66""/>
    <errors />
</results>";

            using (var tempDir = new TempDirectory())
            {
                var inputFileName          = tempDir.Write("input.xml", emptyCppCheckLog);
                var expectedOutputFileName = tempDir.Combine("output_expected.xml");
                _converter.ConvertToStandardFormat(ToolFormat.CppCheck, inputFileName, expectedOutputFileName);

                string expectedOutput       = File.ReadAllText(expectedOutputFileName, Encoding.UTF8);
                var    actualOutputFileName = tempDir.Write("output_actual.xml", new string('a', expectedOutput.Length + 4096));
                _converter.ConvertToStandardFormat(ToolFormat.CppCheck, inputFileName, actualOutputFileName, LoggingOptions.OverwriteExistingOutputFile);
                string actualOutput = File.ReadAllText(actualOutputFileName, Encoding.UTF8);
                Assert.AreEqual(expectedOutput, actualOutput);
            }
        }
        public void ToolFormatConverter_FindsConverterInPluginAssembly()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "TestTool";
                string       pluginAssemblyPath = GetCurrentAssemblyPath();

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    pluginAssemblyPath);

                action.ShouldNotThrow();
            }
        }
        public void ToolFormatConverter_FailsIfConverterTypeDoesNotHaveDefaultConstructor()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "NoDefaultConstructorTool";
                string       pluginAssemblyPath = GetCurrentAssemblyPath();

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    pluginAssemblyPath);

                action.ShouldThrow <ArgumentException>()
                .Where(ex => ex.Message.Contains(ToolName));
            }
        }
        public void ToolFormatConverter_FailsIfPluginAssemblyDoesNotExist()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "TestTool";
                const string PluginAssemblyPath = "NoSuchAssembly.dll";

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    PluginAssemblyPath);

                action.ShouldThrow <ArgumentException>()
                .Where(ex => ex.Message.Contains(PluginAssemblyPath));
            }
        }
Exemplo n.º 6
0
        public void ToolFormatConverter_FailsIfConverterTypeDoesNotHaveCorrectBaseClass()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "IncorrectlyDerivedTool";
                string       pluginAssemblyPath = GetCurrentAssemblyPath();

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LogFilePersistenceOptions.None,
                    OptionallyEmittedData.None,
                    pluginAssemblyPath);

                action.Should().Throw <ArgumentException>()
                .Where(ex => ex.Message.Contains(ToolName));
            }
        }
        public void ToolFormatConverter_FindsBuiltInConverterEvenIfPluginIsSpecified()
        {
            using (var tempDir = new TempDirectory())
            {
                string pluginAssemblyPath = GetCurrentAssemblyPath();

                // A minimal valid AndroidStudio output file.
                string inputFilePath = tempDir.Write(
                    "input.txt",
                    @"<?xml version=""1.0"" encoding=""UTF-8""?><problems></problems>");

                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolFormat.AndroidStudio,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    pluginAssemblyPath);

                action.ShouldNotThrow();
            }
        }
        public void ToolFormatConverter_FailsIfConverterTypeIsAmbiguousInPluginAssembly()
        {
            using (var tempDir = new TempDirectory())
            {
                const string ToolName           = "AmbiguousTool";
                string       pluginAssemblyPath = GetCurrentAssemblyPath();

                string inputFilePath  = tempDir.Write("input.txt", string.Empty);
                string outputFilePath = tempDir.Combine("output.txt");

                Action action = () => _converter.ConvertToStandardFormat(
                    ToolName,
                    inputFilePath,
                    outputFilePath,
                    LoggingOptions.None,
                    OptionallyEmittedData.None,
                    pluginAssemblyPath);

                action.Should().Throw <ArgumentException>()
                .Where(ex =>
                       ex.Message.Contains(pluginAssemblyPath) &&
                       ex.Message.Contains(ToolName));
            }
        }