コード例 #1
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)));
        }
コード例 #2
0
        public void TestReflect1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("UniquePluginId", "My very own plugin", "Simon", "http://google.com", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader())
                {
                    var description = loader.ReflectPlugin(stream, true);
                    description.Should().NotBeNull();
                    description.Id.Should().Be("UniquePluginId");
                    description.Name.Should().Be("My very own plugin");
                    description.Version.Should().Be(new Version(0, 0, 0), "because the plugin version should default to 0.0.0 when none has been specified");
                    description.Author.Should().Be("Simon");
                    description.Website.Should().Be(new Uri("http://google.com"));
                    description.Description.Should().Be("get of my lawn");
                }
            }
        }
コード例 #3
0
        public void TestLoad2()
        {
            var assemblyFileName = "Foo2.dll";

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

            var builder = new PluginBuilder("Simon", "Foo2", "Foo2", "Simon", "None of your business", "Get of my lawn");

            builder.ImplementInterface <IFileFormatPlugin>("Foo2.MyAwesomePlugin");
            builder.Save();
            var description = new PluginDescription
            {
                FilePath = assemblyFileName,
                PluginImplementations = new List <IPluginImplementationDescription>
                {
                    new PluginImplementationDescription("Foo2.MyAwesomePlugin", typeof(IFileFormatPlugin))
                }
            };

            using (var scanner = new PluginAssemblyLoader())
            {
                var plugin = scanner.Load <IFileFormatPlugin>(description, description.PluginImplementations[0]);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo2.MyAwesomePlugin");
            }
        }
コード例 #4
0
        public void TestLoadAllOfType1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "SomePlugin", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.SomePlugin.1.tvp"), stream);

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    var plugins = loader.LoadAllOfType <IFileFormatPlugin>()?.ToList();
                    plugins.Should().NotBeNull();
                    plugins.Should().HaveCount(1);
                    plugins[0].Should().NotBeNull();
                    plugins[0].GetType().FullName.Should().Be("Plugin.FileFormatPlugin");
                }
            }
        }
コード例 #5
0
        public void TestAddNativeImage1()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Simon", "Foo", "Plugin");
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);

                var fname = Path.Combine(_testData, "Native", "x86", "NativeImage.dll");
                packer.AddFile("NativeImage.dll", fname);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Should().NotBeNull();
                index.Assemblies.Should().NotBeNull();
                index.Assemblies.Should().HaveCount(1);

                index.NativeImages.Should().NotBeNull();
                index.NativeImages.Count.Should().Be(1);
                index.NativeImages[0].EntryName.Should().Be("NativeImage.dll");
                index.NativeImages[0].ImageName.Should().Be("NativeImage");
            }
        }
コード例 #6
0
        public void TestReflect1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "My very own plugin", "Simon", "http://google.com", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.UniquePluginId.2.0.tvp"), stream);

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    loader.Plugins.Should().HaveCount(1, "because one plugin should've been loaded");
                    var description = loader.Plugins.First();
                    description.Should().NotBeNull();
                    description.Id.Should().Be(new PluginId("Kittyfisto.UniquePluginId"));
                    description.Name.Should().Be("My very own plugin");
                    description.Version.Should().Be(new Version(0, 0, 0), "because the plugin version should default to 0.0.0 when none has been specified");
                    description.Author.Should().Be("Simon");
                    description.Website.Should().Be(new Uri("http://google.com"));
                    description.Description.Should().Be("get of my lawn");
                }
            }
        }
コード例 #7
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")
                );
        }
コード例 #8
0
        public void TestLoad1()
        {
            var assemblyFileName = "Foo1.dll";

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

            var builder = new PluginBuilder("Simon", "Foo1", "Foo1", "Simon", "None of your business", "Get of my lawn");

            builder.ImplementInterface <IFileFormatPlugin>("Foo1.MyAwesomePlugin");
            builder.Save();
            var description = new PluginDescription
            {
                FilePath = assemblyFileName,
                Plugins  = new Dictionary <Type, string>
                {
                    { typeof(IFileFormatPlugin), "Foo1.MyAwesomePlugin" }
                }
            };

            using (var scanner = new PluginAssemblyLoader())
            {
                var plugin = scanner.Load <IFileFormatPlugin>(description);
                plugin.Should().NotBeNull();
                plugin.GetType().FullName.Should().Be("Foo1.MyAwesomePlugin");
            }
        }
コード例 #9
0
        public void TestAddAssembly1()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Simon", "Foo", "Plugin");
                builder.AssemblyVersion              = "4.0.3.1";
                builder.AssemblyFileVersion          = "1.2.3.42";
                builder.AssemblyInformationalVersion = "4.0.0.0-beta";
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Should().NotBeNull();
                index.Name.Should().Be("Plugin");
                index.Assemblies.Should().NotBeNull();
                index.Assemblies.Should().HaveCount(1);
                index.Assemblies[0].EntryName.Should().Be("Plugin.dll");
                index.Assemblies[0].AssemblyName.Should().Be("Plugin");
                index.Assemblies[0].AssemblyVersion.Should().Be(new Version(4, 0, 3, 1));
                index.Assemblies[0].AssemblyFileVersion.Should().Be(new Version(1, 2, 3, 42));
                index.Assemblies[0].AssemblyInformationalVersion.Should().Be("4.0.0.0-beta");
                index.NativeImages.Should().NotBeNull();
                index.NativeImages.Should().HaveCount(0);

                var actualAssembly = reader.LoadAssembly("Plugin.dll");
                actualAssembly.Should().NotBeNull();
            }
        }
コード例 #10
0
        public void TestLoadAllOfTypeWithDescription()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "Simon", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                var path = Path.Combine(Constants.PluginPath, "Kittyfisto.Simon.1.0.tvp");
                _filesystem.WriteAllBytes(path, stream.ToArray());

                using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
                {
                    var pluginsWithDescription = loader.LoadAllOfTypeWithDescription <IFileFormatPlugin>();
                    pluginsWithDescription.Should().HaveCount(1, "because we've added one plugin which implements the IFileFormatPlugin interface");
                    var description = pluginsWithDescription[0].Description;
                    description.Should().NotBeNull();
                    description.Id.Should().Be(new PluginId("Kittyfisto.Simon"));
                    description.Author.Should().Be("get of my lawn");
                }
            }
        }
コード例 #11
0
        public void TestReflectTwoPluginImplementations()
        {
            var stream = new MemoryStream();

            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "MyAwesomePlugin");
                builder.ImplementInterface <IFileFormatPlugin>("A");
                builder.ImplementInterface <IFileFormatPlugin>("B");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
            _filesystem.Write(Path.Combine(Constants.PluginPath, "Kittyfisto.UniquePluginId.2.0.tvp"), stream);

            using (var loader = new PluginArchiveLoader(_filesystem, Constants.PluginPath))
            {
                loader.Plugins.Should().HaveCount(1, "because one plugin should've been loaded");
                var description = loader.Plugins.First();
                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");
            }
        }
コード例 #12
0
        public void TestLoadAllOfType1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "SomePlugin", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader(null))
                {
                    var description = loader.ReflectPlugin(stream, true);
                    var plugins     = loader.LoadAllOfType <IFileFormatPlugin>()?.ToList();
                    plugins.Should().NotBeNull();
                    plugins.Should().HaveCount(1);
                    plugins[0].Should().NotBeNull();
                    plugins[0].GetType().FullName.Should().Be("Plugin.FileFormatPlugin");
                }
            }
        }
コード例 #13
0
        protected static void CreatePlugin(string assemblyFileName,
                                           string author      = null,
                                           string website     = null,
                                           string description = null)
        {
            var pluginName = Path.GetFileNameWithoutExtension(assemblyFileName);
            var builder    = new PluginBuilder(pluginName, pluginName, author, website, description);

            builder.Save();
        }
コード例 #14
0
        private static void CreatePlugin(MemoryStream stream)
        {
            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder("Kittyfisto", "UniquePluginId", "My very own plugin", "Simon", "http://google.com",
                                                "get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
        }
コード例 #15
0
ファイル: PluginPackerTest.cs プロジェクト: radtek/Tailviewer
        public void TestPackPrivatePluginImplementation()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Kittyfisto", "MyPlugin", "My First Plugin");
                builder.PluginVersion = new Version(1, 4, 12034);
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin", TypeAttributes.NotPublic | TypeAttributes.Sealed);
                builder.Save();

                new Action(() => packer.AddPluginAssembly(builder.FileName))
                .Should()
                .Throw <PackException>()
                .WithMessage("Plugin implementations must publicly visible, but 'Plugin.FileFormatPlugin' is not!");
            }
        }
コード例 #16
0
        protected static void CreatePlugin(string assemblyFileName,
                                           string author      = null,
                                           string website     = null,
                                           string description = null)
        {
            var pluginName = Path.GetFileNameWithoutExtension(assemblyFileName);
            var idParts    = pluginName.Split('.');

            idParts.Should().HaveCount(2);
            var @namespace = idParts[0];
            var name       = idParts[1];

            var builder = new PluginBuilder(@namespace, name, pluginName, author, website, description);

            builder.Save();
        }
コード例 #17
0
        private static PluginId CreatePlugin(MemoryStream stream)
        {
            var @namespace = "Kittyfisto";
            var name       = "UniquePluginId";

            using (var packer = PluginPacker.Create(stream, true))
            {
                var builder = new PluginBuilder(@namespace, name, "My very own plugin", "Simon", "http://google.com",
                                                "get of my lawn");
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            stream.Position = 0;
            return(new PluginId($"{@namespace}.{name}"));
        }
コード例 #18
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");
        }
コード例 #19
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!");
        }
コード例 #20
0
        private void CreatePlugin(string @namespace, string name, Version version)
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, leaveOpen: true))
                {
                    var builder = new PluginBuilder(@namespace, name, "dawawdwdaaw")
                    {
                        PluginVersion = version
                    };
                    builder.ImplementInterface <IFileFormatPlugin>("dwwwddwawa");
                    builder.Save();
                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;
                var fileName = Path.Combine(Constants.PluginPath, string.Format("{0}.{1}.{2}.tvp", @namespace, name, version));
                _filesystem.Write(fileName, stream);
            }
        }
コード例 #21
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");
            }
        }
コード例 #22
0
        private string CreatePlugin(string @namespace, string name, Version version)
        {
            var fileName = Path.Combine(_pluginFolder, string.Format("{0}.{1}.{2}.dll", @namespace, name, version));

            using (var packer = PluginPacker.Create(fileName))
            {
                var builder = new PluginBuilder(@namespace, name, "dawawdwdaaw")
                {
                    PluginVersion = version
                };
                builder.ImplementInterface <IFileFormatPlugin>("dwwwddwawa");
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);
            }

            var dest = Path.Combine(_pluginFolder, Path.GetFileName(fileName));

            File.Move(fileName, dest);

            return(dest);
        }
コード例 #23
0
        public void TestAddAssembly5()
        {
            using (var packer = CreatePacker(_fname))
            {
                var builder = new PluginBuilder("Kittyfisto", "MyPlugin", "My First Plugin");
                builder.PluginVersion = new Version(1, 4, 12034);
                builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                builder.Save();

                packer.AddPluginAssembly(builder.FileName);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var index = reader.Index;
                index.Version.Should().NotBeNull();
                index.Id.Should().Be("Kittyfisto.MyPlugin");
                index.Name.Should().Be("My First Plugin");
                index.Version.Should().Be(new Version(1, 4, 12034));
            }
        }
コード例 #24
0
        public void TestLoadAssembly1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Simon", "Foo1", "TestLoadAssembly1", "Simon", "None of your business", "Get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Foo1.MyAwesomePlugin");
                    builder.Save();
                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var reader = PluginArchive.OpenRead(stream))
                {
                    var assembly = reader.LoadAssembly("Plugin.dll");
                    assembly.Should().NotBeNull();
                    reader.LoadAssembly("Plugin.dll").Should().BeSameAs(assembly, "because LoadAssembly should return the very same assembly every time");
                }
            }
        }
コード例 #25
0
        private void CreatePlugin <T>(string pluginFolder, PluginId actualId, Version actualVersion, PluginId fakeId, Version fakeVersion) where T : IPlugin
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var idx             = actualId.Value.LastIndexOf(".");
                    var actualNamespace = actualId.Value.Substring(0, idx);
                    var actualName      = actualId.Value.Substring(idx + 1);
                    var builder         = new PluginBuilder(actualNamespace, actualName, "none of your business", "get of my lawn", version: actualVersion);
                    builder.ImplementInterface <T>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }
                stream.Position = 0;

                var path = Path.Combine(pluginFolder, $"{fakeId.Value}.{fakeVersion}.tvp");
                _filesystem.CreateDirectory(pluginFolder);
                _filesystem.WriteAllBytes(path, stream.ToArray());
            }
        }
コード例 #26
0
        public void TestAddSameAssemblyTwice()
        {
            var directory = Directory.GetCurrentDirectory();
            var aFileName = "A.dll";
            var aFilePath = Path.Combine(directory, aFileName);
            var bFileName = "B.dll";
            var bFilePath = Path.Combine(directory, bFileName);

            using (var packer = CreatePacker(_fname))
            {
                var aBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("A"), AssemblyBuilderAccess.Save);
                var aModule  = aBuilder.DefineDynamicModule(aFileName);
                var aType    = aModule.DefineType("A_Dummy", TypeAttributes.Class | TypeAttributes.Public);
                aType.CreateType();
                aBuilder.Save(aFileName);

                var bBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("B"), AssemblyBuilderAccess.Save);
                var bModule  = bBuilder.DefineDynamicModule(bFileName);
                var bType    = bModule.DefineType("B_Dummy", TypeAttributes.Class | TypeAttributes.Public, Assembly.LoadFile(aFilePath).ExportedTypes.First());
                bType.CreateType();
                bBuilder.Save(bFileName);

                var builder = new PluginBuilder("Simon", "Foo", "Plugin");
                builder.AddDependency(aFilePath);
                builder.AddDependency(bFilePath);
                builder.Save();
                packer.AddPluginAssembly(builder.FileName);
            }

            using (var reader = PluginArchive.OpenRead(_fname))
            {
                var assemblies = reader.Index.Assemblies;
                assemblies.Should().ContainSingle(x => x.AssemblyName == "A");
                assemblies.Should().ContainSingle(x => x.AssemblyName == "B");
                assemblies.Should().ContainSingle(x => x.AssemblyName == "Plugin");
                assemblies.Should().HaveCount(3, "because we expect a total of 3 assemblies to have been saved");
            }
        }
コード例 #27
0
        public void TestLoad1()
        {
            using (var stream = new MemoryStream())
            {
                using (var packer = PluginPacker.Create(stream, true))
                {
                    var builder = new PluginBuilder("Kittyfisto", "Simon", "none of your business", "get of my lawn");
                    builder.ImplementInterface <IFileFormatPlugin>("Plugin.FileFormatPlugin");
                    builder.Save();

                    packer.AddPluginAssembly(builder.FileName);
                }

                stream.Position = 0;

                using (var loader = new PluginArchiveLoader(null))
                {
                    var description = loader.ReflectPlugin(stream, true);
                    var plugin      = loader.Load <IFileFormatPlugin>(description);
                    plugin.Should().NotBeNull();
                }
            }
        }