private void btnGenerateTests_Click(object sender, EventArgs e) { UpdateStatusStrip("Bulding test case components."); var testComponents = BuildTestComponents(); var testModuleConfig = BuildTestModuleConfig(); UpdateStatusStrip("Building test case fragments."); var builder = new TestCaseComponentBuilder(testComponents, testModuleConfig); var testCaseComponentGroups = builder.Build(); UpdateStatusStrip("Building test scenarios"); var scenarioBuilder = new ScenarioBuilder(testCaseComponentGroups, testModuleConfig); List <ScenarioDTO> scenarios = scenarioBuilder.Build(); UpdateStatusStrip("Building test project"); TestCaseScenario finalObject = new TestCaseScenario() { ModuleConfig = testModuleConfig, Scenarios = scenarios }; CodeSolutionBuilder solutionBuilder = new CodeSolutionBuilder(); SolutionGenerationConfig solConfig = new SolutionGenerationConfig() { IsGeneratedDistinctDLL = chkGenerateDistinctDLL.Checked, IsGeneratedDistinctSuiteXmlConfig = chkGenerateDistinctSuiteXmlConfig.Checked, IsAutoGenerateSolutionName = chkAutoGenerateSolutionName.Checked, //if this is false then we must specify SolutionNameExplicitly SolutionTargetPath = txtSolutionTargetPath.Text, //SolutionName //LastKnownSolutionFolderDirPath IsCompileAndGenerateLibrary = chkCompileAndGenerateLibrary.Checked, SolutionName = txtSolutionName.Text, IsAutoDeploy = chkAutoDeploy.Checked, AutoDeployPath = txtDeploymentPath.Text, }; tacMain.SelectedIndex = 3; using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { solutionBuilder.Generate(finalObject, solConfig, writer); writer.Flush(); txtCompilerWarnings.Text = Encoding.ASCII.GetString(stream.ToArray()); } } MessageBox.Show("Operation completed successfully.", "Save successful", MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateStatusStrip("Finished"); }
protected GlobalGeneratedFileNames Generate_Core(TestCaseScenario scenarioConfig, SolutionGenerationConfig solutionConfig) { this.SolutionGenConfig = solutionConfig; string suiteName = scenarioConfig.ModuleConfig.ModuleId + "_TestSuite"; //Step 1: Create Solution Folder this.Create_SolutionFolder_WithDateTimeStamp(suiteName); string assemblyName = scenarioConfig.ModuleConfig.AutoGeneratedProjectNamespace + (this.SolutionGenConfig.IsGeneratedDistinctSuiteXmlConfig ? ("_" + this._DateTimeStamp) : string.Empty); scenarioConfig.ModuleConfig.AssemblyName = assemblyName; //Step 2: create necessary folders : create top level folders : AutoGenTests & UserTests this.Create_RequiredFolders_InsideSolutionFolder(); List <string> scenarioMethodNames = new List <string>(); scenarioConfig.Scenarios.ForEach((s) => { scenarioMethodNames.Add(s.Name); }); //Step 3: create top level files: MasterRunner_AutoGenTests.cs, MasterRunner_UserTests.cs, ModuleXYZ_TestSuite.xml,TestConfig.cs GlobalGeneratedFileNames globalGeneratedFileNames = this.Create_RequiredFiles_InsideSolutionFolder(scenarioConfig.ModuleConfig.ModuleId, suiteName, scenarioMethodNames, scenarioConfig); //Step 4: create files inside AutoGenTests folder //TC._.cs this.Create_TestCaseMainFile_InsideAutoGenTests(scenarioConfig.ModuleConfig); //TC.Scenario.cs List <GeneratorScenarioFileObject> scenarioFileList = Create_All_TestCaseScenarioFile_InsideAutoGenTests(scenarioConfig); //TODO: substitue null with object //Step 5: copy old UserTests contents //TODO: based on time constraint //Step 6: Create only one project for now : project 1 GeneratorProjectXmlFile csprojXmlObj = this.Create_ProjectFile( scenarioConfig.ModuleConfig.ModuleId, scenarioFileList, globalGeneratedFileNames.TestSuiteXmlFile, assemblyName ); //Step 7: Create Assembly file name under properties using GeneratorProjectXmlFile Create_AssemblyInfoCsFile(csprojXmlObj); //Step 8: Create Solution File (yipee!!!) Create_SolutionFile(new List <GeneratorProjectXmlFile>() { csprojXmlObj }); return(globalGeneratedFileNames); }
public void Generate(TestCaseScenario scenarioConfig, SolutionGenerationConfig solutionConfig, StreamWriter sWrite = null) { if (!Directory.Exists(solutionConfig.SolutionTargetPath)) { Directory.CreateDirectory(solutionConfig.SolutionTargetPath); } GlobalGeneratedFileNames fileNameListing = Generate_Core(scenarioConfig, solutionConfig); sWrite.WriteLine("Code generation started"); if (this.SolutionGenConfig.IsCompileAndGenerateLibrary) { this._SolutionCompiledCodeFolderFullPath = Path.Combine(this.SolutionGenConfig.SolutionTargetPath, CONST_FOLDER_COMPILED_CODE_CONTAINER); //string targetCompiledFolderPath = Path.Combine(this.SolutionGenConfig.SolutionTargetPath, "CompiledCode"); string dllFileNameWithFullPath; bool isCOmpileSuccess = this.BuildRunLibrary(sWrite, this._SolutionCompiledCodeFolderFullPath, out dllFileNameWithFullPath); if (isCOmpileSuccess) { //copy TestSuiteXmlFile To TargetCompiledPath string xmlFileNameWithFullPath = this.CopyFile_ToTargetCompiledPath(fileNameListing.TestSuiteXmlFile, this._SolutionContentFolderFullPath, this._SolutionCompiledCodeFolderFullPath); //Copy AppConfigFile To TargetCompiledPath string appSettingFilePath = this.CopyFile_ToTargetCompiledPath(fileNameListing.ConfigFile_AppSettingConfigFile, this._SolutionContentFolderFullPath, this._SolutionCompiledCodeFolderFullPath); if (this.SolutionGenConfig.IsAutoDeploy) { string dllfileNameWithoutExtension = Path.GetFileNameWithoutExtension(dllFileNameWithFullPath); string src_dllLocationPath = Path.GetDirectoryName(dllFileNameWithFullPath); string dllFileName = dllfileNameWithoutExtension + ".dll"; string pdbFileName = dllfileNameWithoutExtension + ".pdb"; string xmlFileName = Path.GetFileName(xmlFileNameWithFullPath); string appSettingFileName = Path.GetFileName(appSettingFilePath); //Copy dll and pdb file if (File.Exists(Path.Combine(src_dllLocationPath, dllFileName))) { File.Copy(Path.Combine(src_dllLocationPath, dllFileName), Path.Combine(this.SolutionGenConfig.AutoDeployPath, dllFileName), true); } if (File.Exists(Path.Combine(src_dllLocationPath, pdbFileName))) { File.Copy(Path.Combine(src_dllLocationPath, pdbFileName), Path.Combine(this.SolutionGenConfig.AutoDeployPath, pdbFileName), true); } //copy xml file if (File.Exists(xmlFileNameWithFullPath)) { File.Copy(xmlFileNameWithFullPath, Path.Combine(this.SolutionGenConfig.AutoDeployPath, xmlFileName), true); } //copy app.Config file if (File.Exists(appSettingFilePath)) { File.Copy(appSettingFilePath, Path.Combine(this.SolutionGenConfig.AutoDeployPath, appSettingFileName), true); } } } } sWrite.WriteLine("Code generation completed"); }