Beispiel #1
0
        public void SimpleCompile()
        {
            Directory.CreateDirectory(CachePath);
            var compiler = new CSharpCompiler <CodeSource>(new CSharpCompilerOptions(forceRecompile: true,
                                                                                     universalAssemblies: new[] { "Exor.Core.Tests.ContentBase.dll" }, cachePath: Path.Combine(CachePath, "SimpleCompile")));

            var contentA = new CodeSource("A", Version.Parse("1.0.0"),
                                          Directory.GetFiles(Path.Combine(AssetDirectory, "ContentA")).Where(f => Path.GetExtension(f) == ".cs"));

            List <ExorCompilerResults <CodeSource> > results;

            if (!compiler.TryCompileSources(new[] { contentA }, out results))
            {
                Assert.Fail("Compile of ContentA failed.");
            }

            var loader = new ExtensionLoader(_logger, results.Select(r => r.Assembly), TypeRecords);

            var obj = loader.Load <SimpleTestBase>("A");

            Assert.IsTrue(obj.GetType().FullName.Contains("SimpleTestA"));
        }
Beispiel #2
0
        public void DependentCompile()
        {
            Directory.CreateDirectory(CachePath);
            var compiler = new CSharpCompiler <CodeSource>(new CSharpCompilerOptions(forceRecompile: true,
                                                                                     universalAssemblies: new[] { "Exor.Core.Tests.ContentBase.dll" }, cachePath: Path.Combine(CachePath, "DependentCompile")));

            var contentA = new CodeSource("A", Version.Parse("1.0.0"),
                                          Directory.GetFiles(Path.Combine(AssetDirectory, "ContentA")).Where(f => Path.GetExtension(f) == ".cs"));
            var contentB = new CodeSource("B", Version.Parse("1.0.0"),
                                          Directory.GetFiles(Path.Combine(AssetDirectory, "ContentB")).Where(f => Path.GetExtension(f) == ".cs"));
            var contentC = new CodeSource("C", Version.Parse("1.0.0"),
                                          Directory.GetFiles(Path.Combine(AssetDirectory, "ContentC")).Where(f => Path.GetExtension(f) == ".cs"),
                                          new[]
            {
                new Dependency("A", "==", Version.Parse("1.0.0")),
            }
                                          );

            var selected   = new[] { contentC, contentB };
            var additional = new[] { contentA };

            List <ExorCompilerResults <CodeSource> > results;

            if (!compiler.TryCompileSources(selected, additional, out results))
            {
                Assert.Fail("Compile failed.");
            }

            var resultsMap = results.ToDictionary(r => r.Source.UniqueName);
            var loadOrder  = selected.Select(c => resultsMap[c.UniqueName].Assembly);

            var loader = new ExtensionLoader(_logger, loadOrder, TypeRecords);

            var obj = loader.DeepLoad <SimpleTestBase>("A").ToList();

            Assert.IsTrue(obj[0].GetType().FullName.Contains("SimpleTestC"));
            Assert.IsTrue(obj[0].GetType().GetTypeInfo().BaseType.FullName.Contains("SimpleTestA"));
            Assert.IsTrue(obj[1].GetType().FullName.Contains("SimpleTestB"));
        }