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_BuildsChainOfResponsibility()
        {
            const string PluginAssemblyPath = "Plugin.dll";

            ConverterFactory factory = new ToolFormatConverter().CreateConverterFactory(PluginAssemblyPath);

            factory.Should().BeOfType <PluginConverterFactory>();
            var pluginFactory = factory as PluginConverterFactory;

            pluginFactory.pluginAssemblyPath.Should().Be(PluginAssemblyPath);

            factory = factory.Next;
            factory.Should().BeOfType <BuiltInConverterFactory>();

            factory = factory.Next;
            factory.Should().BeNull();
        }
Ejemplo n.º 3
0
        public void ToolFormatConverter_BuildsChainOfResponsibility()
        {
            const string PluginAssemblyPath = "Plugin.dll";

            ConverterFactory factory = ToolFormatConverter.CreateConverterFactory(PluginAssemblyPath);

            Assert.IsInstanceOfType(factory, typeof(PluginConverterFactory));
            var pluginFactory = factory as PluginConverterFactory;

            Assert.AreEqual(PluginAssemblyPath, pluginFactory.pluginAssemblyPath);

            factory = factory.Next;
            Assert.IsInstanceOfType(factory, typeof(BuiltInConverterFactory));

            factory = factory.Next;
            Assert.IsNull(factory);
        }