public void ShouldLoadCorrectlyANonConsistentFile() { var toParse = ResourceContentLoader.LoadText("ShouldLoadCorrectlyANonConsistentFile.input", Assembly.GetExecutingAssembly()); var expected = ResourceContentLoader.LoadText("ShouldLoadCorrectlyANonConsistentFile.csx", Assembly.GetExecutingAssembly()); var pp = new SharpParser(); var result = pp.Parse(toParse, "ClassName", "NameSpaceName"); Assert.AreEqual(TestUtils.Clean(expected), TestUtils.Clean(result)); }
public void CompileSimpleTemplate() { const string dllName = "CompileClassTemplate"; const string resultDllName = "CompileResultingTemplate"; var path = TestUtils.GetExecutionPath(); var source = ResourceContentLoader.LoadText("ClassTemplate.cs", Assembly.GetExecutingAssembly()); var pp = new SharpParser(); var sharpClass = pp.ParseClass(source, "TestParserClass", "SharpTemplate.Test.Resources.Parsers"); var loadedAssembly = BuildParserClass(dllName, path, sharpClass); AddFile(loadedAssembly); var content = File.ReadAllBytes(loadedAssembly); var compileSimpleObjectAsm = Assembly.Load(content); var instance = (ISharpResult)Activator.CreateInstance(compileSimpleObjectAsm.FullName, "SharpTemplate.Test.Resources.Parsers.TestParserClass").Unwrap(); Assert.IsNotNull(instance); var model = new ParseCompileModel("ResultingClass", "MethodToInvoke", 10); instance.Execute(model); var writtenModel = instance.Content; var resultingAssembly = BuildGenericClass(resultDllName, path, "TestNamespace", "ResultingClass",writtenModel); content = File.ReadAllBytes(resultingAssembly); compileSimpleObjectAsm = Assembly.Load(content); var instanceFinal = Activator.CreateInstance(compileSimpleObjectAsm.FullName, "TestNamespace.ResultingClass").Unwrap(); var method = instanceFinal.GetType().GetMethod("MethodToInvoke"); Assert.IsNotNull(method); var result = method.Invoke(instanceFinal, new object[] { }) as List<string>; Assert.IsNotNull(result); Assert.AreEqual(10, result.Count); }