public void executes_postman_generatetask() { // Arrange var mock = new Mock<IBuildEngine>(); var codeBase = new Uri(Assembly.GetExecutingAssembly().CodeBase); var assemblyFilePath = codeBase.LocalPath; var task = new GenerateTask { AssemblyFilePath = assemblyFilePath, OutputDirectory = @".\", BuildEngine = mock.Object }; File.Delete(task.OutputFilePath); // Act var actual = task.Execute(); // Assert actual.Should().BeTrue(); File.Exists(task.OutputFilePath).Should().BeTrue(); AssertOutputFile(task.OutputFilePath); }
private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < numberOfProcessors; i++) { processors[i].MillisecondRemove(); } generateTask = new GenerateTask(); if (GENERAL_PROBABILITY > 0) { generateTask.probability = GENERAL_PROBABILITY; } if (GENERAL_COMPLEXITY > 0) { generateTask.taskComplexity = GENERAL_COMPLEXITY; } var processorsInUse = generateTask.GetProcessors(availableProcessors.Count, availableProcessors); var minInd = processorsInUse[0]; double load = (double)Int32.MaxValue; double tmp = 0; GetMinLoadedProcessor(ref minInd, ref load, ref tmp, processorsInUse); var currentProcessor = minInd; Pair <bool, double> pair = generateTask.CanAppear(); for (int i = 0; i < processorsInUse.Count; i++) { processorsInUse[i]++; } if (pair.First) { TOTAL_TASKS++; processors[currentProcessor].AddTask(generateTask.taskComplexity); // if (processorsInUse.Count > 1) // processorsInUse.RemoveAt(processorsInUse.Count - 1); ListViewItem listView = new ListViewItem( new string[] { string.Join(" ", processorsInUse), generateTask.taskComplexity.ToString(), processors[currentProcessor].queue.ToString() } ); // shitty construction listViews.ToArray()[currentProcessor].Items.Add(listView); } ListViewItem lstRes = new ListViewItem( new string[] { (pair.Second / 100.0).ToString(), pair.First.ToString(), string.Join(" ", processorsInUse), generateTask.taskComplexity.ToString(), processors[currentProcessor].queue.ToString() } ); listView6.Items.Add(lstRes); }
public ApiResult Generate(string module, string view) { var genrateTask = new GenerateTask(null); genrateTask.Generate(module, view); //genrateTask.GenerateAll(); return(new ApiResult()); }
private async void Form1_Load(object sender, EventArgs e) { GENERAL_PROBABILITY = -1; GENERAL_COMPLEXITY = -1; generateTask = new GenerateTask(); processors = new List <Processor>(); for (int i = 0; i < numberOfProcessors; i++) { processors.Add(new Processor()); await Task.Delay(10); } }
public async void RunMainTask_NoProvider() { var config = new Dictionary <string, string>(); var task = new GenerateTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _dataModelService.Object, _pluginManager.Object, _logger.Object); task.SetConfig(config, "working"); task.Provider = "NotExistCodeGeneratorProvider"; var result = await task.RunMainTask(new Dictionary <string, string>()); Assert.False(result.IsSuccess); Assert.Equal("Code generator provider \"NotExistCodeGeneratorProvider\" could not be found.", result.ErrorMessage); }
public async void RunMainTask_AdditionalConfigSecured() { _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object> { { "outputLocation", "c:\\test" } }); _pluginManager.Setup(p => p.GetPlugins(It.IsAny <string>())).Returns(new List <PluginItem> { new PluginItem("FakeCodeGeneratorProvider", "path/to/FakeCodeGeneratorProvider.dll", new string[] { "GitHub" }) }); _externalServiceService.Setup(p => p.GetExternalServiceByName(It.IsAny <string>())).ReturnsAsync((string name) => new ExternalServiceDto { Name = name, Config = new Dictionary <string, string> { { "AuthToken", "123" } } }); var config = new Dictionary <string, string> { { "GitHubExternalService", "github-test" } }; var task = new GenerateTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _dataModelService.Object, _pluginManager.Object, _logger.Object); task.SetConfig(config, "working"); task.Provider = "FakeCodeGeneratorProvider"; task.AdditionalConfigs = new Dictionary <string, string> { { "ConnectionString", "Server=localhost;Database=TestProject;User ID=sa;Password=samprod;" } }; var result = await task.RunMainTask(new Dictionary <string, string>()); Assert.True(result.IsSuccess); Assert.Equal("c:\\test", result.ReturnValue); Assert.Equal("The generated code is located at c:\\test", result.TaskRemarks); Assert.Equal(2, task.AdditionalConfigs.Count); Assert.Equal(2, task.SecuredAdditionalConfigs.Count); Assert.Equal("***", task.SecuredAdditionalConfigs["AuthToken"]); Assert.Equal("***", task.SecuredAdditionalConfigs["ConnectionString"]); Assert.Equal("123", task.AdditionalConfigs["AuthToken"]); Assert.Equal("Server=localhost;Database=TestProject;User ID=sa;Password=samprod;", task.AdditionalConfigs["ConnectionString"]); }
public async void RunMainTask_Failed() { _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object> { { "errorMessage", "error-message" } }); var config = new Dictionary <string, string>(); var task = new GenerateTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _dataModelService.Object, _pluginManager.Object, _logger.Object); task.SetConfig(config, "working"); task.Provider = "FakeCodeGeneratorProvider"; var result = await task.RunMainTask(new Dictionary <string, string>()); Assert.False(result.IsSuccess); Assert.Equal("error-message", result.ErrorMessage); }
public async void RunMainTask_Success() { _pluginManager.Setup(p => p.InvokeTaskProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync((string pluginDll, string pluginArgs, string secretPluginArgs) => new Dictionary <string, object> { { "outputLocation", "c:\\test" } }); var config = new Dictionary <string, string>(); var task = new GenerateTask(_projectService.Object, _externalServiceService.Object, _externalServiceTypeService.Object, _providerService.Object, _dataModelService.Object, _pluginManager.Object, _logger.Object); task.SetConfig(config, "working"); task.Provider = "FakeCodeGeneratorProvider"; var result = await task.RunMainTask(new Dictionary <string, string>()); Assert.True(result.IsSuccess); Assert.Equal("c:\\test", result.ReturnValue); Assert.Equal("The generated code is located at c:\\test", result.TaskRemarks); }
private async void buttonStart_Click(object sender, EventArgs e) { availableProcessors = new List <int>(); listViews = new Memory <ListView>(new ListView[] { listView1, listView2, listView3, listView4, listView5 }); textBoxes = new Memory <TextBox>(new TextBox[] { textBoxProcessor1, textBoxProcessor2, textBoxProcessor3, textBoxProcessor4, textBoxProcessor5 }); generateTask = new GenerateTask(); processors = new List <Processor>(); for (int i = 0; i < numberOfProcessors; i++) { processors.Add(new Processor()); await Task.Delay(10); } #region Processor's perfomance manual try { processors[0].perfomance = Convert.ToInt32(textBoxProcessor1.Text); } catch (Exception ex) { //throw ex; } try { processors[1].perfomance = Convert.ToInt32(textBoxProcessor2.Text); } catch (Exception ex) { //throw ex; } try { processors[2].perfomance = Convert.ToInt32(textBoxProcessor3.Text); } catch (Exception ex) { //throw ex; } try { processors[3].perfomance = Convert.ToInt32(textBoxProcessor4.Text); } catch (Exception ex) { //throw ex; } try { processors[4].perfomance = Convert.ToInt32(textBoxProcessor5.Text); } catch (Exception ex) { //throw ex; } TextBox[] array = textBoxes.ToArray(); for (int i = 0; i < array.Length; i++) { TextBox item = (TextBox)array[i]; item.Text = processors[i].perfomance.ToString(); } #endregion #region Initial Settings try { generateTask.probability = Convert.ToInt32(Convert.ToDouble(textBoxProbability.Text) * 100); GENERAL_PROBABILITY = generateTask.probability; } catch (Exception ex) { // throw; } try { generateTask.taskComplexity = Convert.ToInt32(textBoxComplexity.Text); GENERAL_COMPLEXITY = generateTask.taskComplexity; } catch (Exception ex) { // throw; } #endregion double maxPerfomance = processors.Max(b => b.perfomance); PLANNER_PROCESSOR_INDEX = processors.FindIndex(b => b.perfomance == maxPerfomance); listViews.ToArray()[PLANNER_PROCESSOR_INDEX].Items.Add("Planner"); // Remove processor; // processors.RemoveAt(PLANNER_PROCESSOR_INDEX); InitializeAvailableProcessors(); timer1.Start(); timer1000.Start(); }
private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < numberOfProcessors; i++) { processors[i].MillisecondRemove(); } generateTask = new GenerateTask(); if (GENERAL_PROBABILITY > 0) { generateTask.probability = GENERAL_PROBABILITY; } if (GENERAL_COMPLEXITY > 0) { generateTask.taskComplexity = GENERAL_COMPLEXITY; } var currentProcessor = 0; var processorsInUse = new List <int>(); bool isPlanner = true; // Planner - 4 ms if (processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner != 0) { processorsInUse = generateTask.GetProcessors(availableProcessors.Count, availableProcessors); var minInd = processorsInUse[0]; double load = (double)Int32.MaxValue; double tmp = 0; GetMinLoadedProcessor(ref minInd, ref load, ref tmp, processorsInUse); currentProcessor = minInd; processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner--; if (processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner == 0) { listViews.ToArray()[PLANNER_PROCESSOR_INDEX].Items.Add("working"); } } else if (processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor != 0) { isPlanner = false; processorsInUse = generateTask.GetProcessors(numberOfProcessors); currentProcessor = processorsInUse[0] - 1; for (int i = 0; i < processorsInUse.Count; i++) { processorsInUse[i]--; } processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor--; if (processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor == 0) { listViews.ToArray()[PLANNER_PROCESSOR_INDEX].Items.Add("planner"); processors[PLANNER_PROCESSOR_INDEX].timeToBePlanner = 4; processors[PLANNER_PROCESSOR_INDEX].timeToBeProcessor = 20; } } // Queue - 20 ms Pair <bool, double> pair = generateTask.CanAppear(); for (int i = 0; i < processorsInUse.Count; i++) { processorsInUse[i]++; } if (pair.First) { TOTAL_TASKS++; processors[currentProcessor].AddTask(generateTask.taskComplexity); if (processorsInUse.Count > 1 && !isPlanner) { processorsInUse.RemoveAt(processorsInUse.Count - 1); } ListViewItem listView = new ListViewItem( new string[] { string.Join(" ", processorsInUse), generateTask.taskComplexity.ToString(), processors[currentProcessor].queue.ToString() } ); // shitty construction listViews.ToArray()[currentProcessor].Items.Add(listView); } ListViewItem lstRes = new ListViewItem( new string[] { (pair.Second / 100.0).ToString(), pair.First.ToString(), string.Join(" ", processorsInUse), generateTask.taskComplexity.ToString(), processors[currentProcessor].queue.ToString() } ); listView6.Items.Add(lstRes); }
public void throws_filenotfoundexception_when_no_assembly_file_found() { // Arrange var mock = new Mock<IBuildEngine>(); GenerateTask task = new GenerateTask { AssemblyFilePath = "c:\badpath\file.dll", OutputDirectory = @".\", BuildEngine = mock.Object }; // Act/Assert Assert.That(() => task.Execute(), Throws.TypeOf<FileNotFoundException>()); }
public void throws_filenotfoundexception_when_no_xml_doc_file_found() { // Arrange var codeBase = new Uri(Assembly.GetExecutingAssembly().CodeBase); var assemblyFilePath = codeBase.LocalPath; var mock = new Mock<IBuildEngine>(); GenerateTask task = new GenerateTask { AssemblyFilePath = assemblyFilePath, OutputDirectory = @".\", BuildEngine = mock.Object }; var xmlFile = task.AssemblyFilePath.Replace(Resources.DllFileExtension, Resources.XmlFileExtension); var tmpFile = @"tmp.xml"; File.Move(xmlFile, tmpFile); // Act/Assert Assert.That(() => task.Execute(), Throws.TypeOf<FileNotFoundException>()); File.Move(tmpFile, xmlFile); }
public void throws_argumentnullexception_when_assemblyfilepath_unspecified() { // Arrange var mock = new Mock<IBuildEngine>(); GenerateTask task = new GenerateTask { BuildEngine = mock.Object }; // Act/Assert Assert.That(() => task.Execute(), Throws.TypeOf<ArgumentNullException>()); }