private string[] GetSource(string[] filePaths, UnitTestFrameworkEnum framework) { var source = new List<string>(); for (var i = 0; i < filePaths.Length; i++) { if (filePaths[i] == null) continue; _parser.Input = File.ReadAllText(filePaths[i]); source.Add(_parser.Parse(framework)); } source.Add(NVelocityCodeGenerationExtensions.GetNVelocityTemplate(TemplateEnum.StructureMapInitialization)); return source.ToArray(); }
public bdUnitPreviewWindow(string filePath, UnitTestFrameworkEnum framework, Parser parser) { InitializeComponent(); _parser = parser; _parser = parser; Id = Guid.NewGuid(); Loaded += bdPreviewWindow_Loaded; var range = new TextRange(InputEditor.Document.ContentStart, InputEditor.Document.ContentEnd); var text = File.ReadAllText(filePath); range.Text = text; CurrentFramework = framework; IsSaved = true; Load(); UpdatePreview(); }
public string CompileDll(string[] filePaths, UnitTestFrameworkEnum currentFramework) { CodeDomProvider compiler = new CSharpCodeProvider(new Dictionary<string, string> { {"CompilerVersion", "v3.5"} }); var parameters = new CompilerParameters { GenerateInMemory = false, GenerateExecutable = false, IncludeDebugInformation = true, OutputAssembly = string.Format("bdUnit_{0}.dll", currentFramework), ReferencedAssemblies = {"System.dll", "System.Core.dll"} }; foreach (var reference in References) { parameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + string.Format("\\{0}.dll", reference)); } try { var source = GetSource(filePaths, currentFramework); var results = compiler.CompileAssemblyFromSource(parameters, source); if (results.Errors.HasErrors) { var errorText = new StringBuilder(); var count = results.Errors.Count; for (var i = 0; i < count; i++) { errorText.AppendLine("Compilation Error: " + results.Errors[i].ErrorText); } return errorText.ToString(); } return "Successfully Generated Dll"; } catch (Exception ex) { return "One or more documents could not be parsed. Please check and try again. Exception: " + ex.Message; } }
public string Parse(UnitTestFrameworkEnum framework) { var tests = Parse(); if (tests != null) { switch (framework) { case UnitTestFrameworkEnum.NUnit: var nUnit = new NUnitCodeGenerator(); return nUnit.GenerateTestFixture(tests, TestFileName); case UnitTestFrameworkEnum.XUnit: var xUnit = new XUnitCodeGenerator(); return xUnit.GenerateTestFixture(tests, TestFileName); case UnitTestFrameworkEnum.MbUnit: var mbUnit = new MbUnitCodeGenerator(); return mbUnit.GenerateTestFixture(tests, TestFileName); } } return string.Empty; }