Exemplo n.º 1
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");
            }
        }