Ejemplo n.º 1
0
        public void TestReflectPlugin6()
        {
            var scanner = new PluginAssemblyLoader();

            new Action(() => scanner.ReflectPlugin("C:\adwwdwawad\asxas")).ShouldThrow <ArgumentException>(
                "because we used illegal characters in that path");
        }
Ejemplo n.º 2
0
        public void TestReflectPlugin2()
        {
            var plugin = "sql.dll";

            if (File.Exists(plugin))
            {
                File.Delete(plugin);
            }

            var builder = new PluginBuilder("Simon", "sql", "sql", "SMI", "none of your business", "go away");

            builder.ImplementInterface <IFileFormatPlugin>("sql.LogFilePlugin");
            builder.Save();

            var scanner     = new PluginAssemblyLoader();
            var description = scanner.ReflectPlugin(plugin);

            description.Author.Should().Be("SMI");
            description.Website.Should().Be(new Uri("none of your business", UriKind.RelativeOrAbsolute));
            description.Description.Should().Be("go away");
            description.PluginImplementations.Should().HaveCount(1);
            description.PluginImplementations.Should().Contain(x => x.InterfaceType == typeof(IFileFormatPlugin));
            var implementationDescription = description.PluginImplementations[0];

            implementationDescription.FullTypeName.Should().Be("sql.LogFilePlugin");
            implementationDescription
            .Version.Should().Be(PluginInterfaceVersionAttribute.GetInterfaceVersion(typeof(IFileFormatPlugin)));
        }
Ejemplo n.º 3
0
        public void TestReflectPlugin2()
        {
            var plugin = "sql.dll";

            if (File.Exists(plugin))
            {
                File.Delete(plugin);
            }

            var builder = new PluginBuilder("Simon", "sql", "sql", "SMI", "none of your business", "go away");

            builder.ImplementInterface <IFileFormatPlugin>("sql.LogFilePlugin");
            builder.Save();

            var scanner     = new PluginAssemblyLoader();
            var description = scanner.ReflectPlugin(plugin);

            description.Author.Should().Be("SMI");
            description.Website.Should().Be(new Uri("none of your business", UriKind.RelativeOrAbsolute));
            description.Description.Should().Be("go away");
            description.Plugins.Should().HaveCount(1);
            description.Plugins.Should().Contain(
                new KeyValuePair <Type, string>(typeof(IFileFormatPlugin), "sql.LogFilePlugin")
                );
        }
Ejemplo n.º 4
0
        public void TestReflectTwoPluginImplementations()
        {
            var builder = new PluginBuilder("Kittyfisto", "TestReflectTwoPluginImplementations", "TestReflectTwoPluginImplementations");

            builder.ImplementInterface <IFileFormatPlugin>("A");
            builder.ImplementInterface <IFileFormatPlugin>("B");
            builder.Save();

            var assemblyLoader = new PluginAssemblyLoader();
            var description    = assemblyLoader.ReflectPlugin(builder.FileName);

            description.PluginImplementations.Should().HaveCount(2, "because we've implemented the IFileFormatPlugin twice");
            description.PluginImplementations[0].InterfaceType.Should().Be <IFileFormatPlugin>();
            description.PluginImplementations[0].FullTypeName.Should().Be("A");

            description.PluginImplementations[1].InterfaceType.Should().Be <IFileFormatPlugin>();
            description.PluginImplementations[1].FullTypeName.Should().Be("B");
        }
Ejemplo n.º 5
0
        public void TestReflectPluginNonPublicSerializableType()
        {
            var pluginBuilder = new PluginBuilder("Kittyfisto", "Test", "TestReflectPluginNonPublicSerializableType");
            var type          = pluginBuilder.DefineType("SomeSerializableType", TypeAttributes.Class | TypeAttributes.NotPublic);

            type.AddInterfaceImplementation(typeof(ISerializableType));
            var attribute = pluginBuilder.BuildCustomAttribute(new DataContractAttribute());

            type.SetCustomAttribute(attribute);
            var ctorBuilder = type.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, new Type[0]);
            var gen         = ctorBuilder.GetILGenerator();

            gen.Emit(OpCodes.Ret);

            var serialize = type.DefineMethod(nameof(ISerializableType.Serialize), MethodAttributes.Public | MethodAttributes.Virtual,
                                              CallingConventions.HasThis,
                                              typeof(void),
                                              new [] { typeof(IWriter) });

            serialize.GetILGenerator().Emit(OpCodes.Ret);

            var deserialize = type.DefineMethod(nameof(ISerializableType.Deserialize), MethodAttributes.Public | MethodAttributes.Virtual,
                                                CallingConventions.HasThis,
                                                typeof(void),
                                                new [] { typeof(IReader) });

            deserialize.GetILGenerator().Emit(OpCodes.Ret);

            type.CreateType();
            pluginBuilder.Save();

            var scanner = new PluginAssemblyLoader();

            var appender = Appender.CaptureEvents("Tailviewer.Archiver.Plugins.PluginAssemblyLoader", Level.Error);

            scanner.ReflectPlugin(pluginBuilder.FileName);
            appender.Events.Should().HaveCount(1, "because the serializable type's parameterless constructor is not publicly visible and this should have provoked an error");
            var error = appender.Events.First();

            error.RenderedMessage.Should().Contain(type.FullName);
            error.RenderedMessage.Should().Contain("must be set to public!");
        }
Ejemplo n.º 6
0
        public void TestScanAndLoad()
        {
            using (var scanner = new PluginAssemblyLoader())
            {
                var assemblyFileName = "Foo3.dll";
                if (File.Exists(assemblyFileName))
                {
                    File.Delete(assemblyFileName);
                }

                var builder = new PluginBuilder("Simon", "Foo3", "Foo3", "Simon", "None of your business", "Get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Foo3.MyAwesomePlugin");
                builder.Save();

                var description = scanner.ReflectPlugin(assemblyFileName);
                var plugin      = scanner.Load <IFileFormatPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo3.MyAwesomePlugin");
            }
        }
Ejemplo n.º 7
0
        public void TestReflectPlugin1()
        {
            var plugin = "Kittyfisto.SomePlugin.dll";

            if (File.Exists(plugin))
            {
                File.Delete(plugin);
            }

            CreatePlugin(plugin, "John Snow", "https://got.com", "You know nothing, John Snow!");
            var scanner     = new PluginAssemblyLoader();
            var description = scanner.ReflectPlugin(plugin);

            description.Should().NotBeNull();
            description.FilePath.Should().Be(plugin);
            description.Author.Should().Be("John Snow");
            description.Website.Should().Be(new Uri("https://got.com", UriKind.RelativeOrAbsolute));
            description.Description.Should().Be("You know nothing, John Snow!");
            description.PluginImplementations.Should().NotBeNull();
            description.PluginImplementations.Should().BeEmpty("Because we didn't add any plugin implementations");
        }
Ejemplo n.º 8
0
        public void TestReflectPlugin5()
        {
            var scanner = new PluginAssemblyLoader();

            new Action(() => scanner.ReflectPlugin(@"C:\adwwdwawad\asxas")).ShouldThrow <FileNotFoundException>();
        }
Ejemplo n.º 9
0
        public void TestReflectPlugin4()
        {
            var scanner = new PluginAssemblyLoader();

            new Action(() => scanner.ReflectPlugin("DAAWDADAWWF")).ShouldThrow <FileNotFoundException>();
        }
Ejemplo n.º 10
0
        public void TestReflectPlugin3()
        {
            var scanner = new PluginAssemblyLoader();

            new Action(() => scanner.ReflectPlugin(null)).ShouldThrow <ArgumentNullException>();
        }