private void GenerateCSharpFile(string projectName, string outputDirectory, bool xmlDocFood, bool generetaNUnit, FormatStyleEnum formatIndex, string formatFile, bool sortUsing, int templateIndex) { // To DO // For each file // http://msdn.microsoft.com/en-us/library/ee844259.aspx //TemplateStandard page = new TemplateStandard(xmlDocFood, sortUsing); //String pageContent = page.TransformText(); //System.IO.File.WriteAllText("outputPage.cs", pageContent); // Format this new C# source file CSharpFormattingOptions format; switch (formatIndex) { case FormatStyleEnum.Empty: // Nothing to do! // format = FormattingOptionsFactory.CreateEmpty(); break; case FormatStyleEnum.Mono: format = FormattingOptionsFactory.CreateMono(); break; case FormatStyleEnum.KR_style: format = FormattingOptionsFactory.CreateKRStyle(); break; case FormatStyleEnum.Allman_Visual_Studio: format = FormattingOptionsFactory.CreateAllman(); break; case FormatStyleEnum.Whitesmiths: format = FormattingOptionsFactory.CreateWhitesmiths(); break; case FormatStyleEnum.GNU: format = FormattingOptionsFactory.CreateGNU(); break; case FormatStyleEnum.Custom: format = (CSharpFormattingOptions)CSharpFormattingOptionsUI.Load(formatFile); break; default: // unknow value! // TO DO : Throw an error break; } // Genereta NUnit test class if (generetaNUnit == true) { // Generate the project NStub.CSharp.CSharpProjectGenerator gen = new NStub.CSharp.CSharpProjectGenerator(String.Format("{0}_unitary_tests", projectName), outputDirectory); // gen.ReferencedAssemblies gen.GenerateProjectFile(); /* * // Generate the test case file * foreach(string origFile in ) * { * CSharpCodeGenerator unitFile = new CSharpCodeGenerator(origFile, origFile); * unitFile.GenerateCode(); * } */ } }
private void WorkerDoWork(object sender, DoWorkEventArgs e) { try { var parObj = (object[])e.Argument; var parameters = (GeneratorRunnerData)parObj[0]; var codeGeneratorSetup = (ICodeGeneratorSetup)parObj[1]; var prjName = Path.GetFileNameWithoutExtension(parameters.InputAssemblyPath) + ".Tests"; var prj = new CSharpProjectGenerator(this.buildSystem, prjName, parameters.OutputFolder); // var builderFactory = NStub.CSharp.ObjectGeneration.TestBuilderFactory.Default; var testProjectBuilder = new CSharpTestProjectBuilder( this.buildSystem, this.buildData, prj, (pbuildSystem, pbuildData, configuration, codeNamespace) => { // var testBuilders = new TestBuilderFactory(); var codeGenerator = (ICodeGenerator)Activator.CreateInstance( parameters.GeneratorType, new object[] { pbuildSystem, codeNamespace, null, configuration }); // codeNamespace.Dump(3); if (codeGenerator is BaseCSharpCodeGenerator) { ((BaseCSharpCodeGenerator)codeGenerator).BuildProperties = pbuildData as BuildDataDictionary; } return codeGenerator; }, this.Log); testProjectBuilder.CustomGeneratorParameters = codeGeneratorSetup; testProjectBuilder.GenerateTests(parameters); } catch (Exception ex) { this.Log(ex.ToString()); } }