/// <summary> /// Event handler for messages raised by the File Manager /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void fm_MessageRaised(object sender, MessageEventArgs e) { //Detect if the error message raised is an error or not if (e.MsgRaised.TypeMessage == MessageType.Error) { errorDetected = true; } Output.WriteMessage(e.MsgRaised); }
/// <summary> /// Constructor /// </summary> /// <param name="args">Arguments to inspect</param> public ProgramArguments(string[] args) { //Build the report template paths scenarioTemplateFileName = AppDomain.CurrentDomain.BaseDirectory + scenarioTemplateName; featureTemplateFileName = AppDomain.CurrentDomain.BaseDirectory + featureTemplateName; testReportTemplateFileName = AppDomain.CurrentDomain.BaseDirectory + testReportTemplateName; FileManager fm = new FileManager(); fm.MessageRaised += new EventHandler <MessageEventArgs>(fm_MessageRaised); if (args != null) { int i = 0; foreach (string argument in args) { switch (argument.ToUpperInvariant()) { case projectDirArgument: if (args.Length > i + 1) { projectFileName = fm.GetProjectFileName(args[i + 1]); } break; case testDirArgument: if (args.Length > i + 1) { //MSTest testReportFile = fm.GetMSTestFileName(args[i + 1]); //TODO: Include here other testing tools } break; case testCategoryArgument: testCategory = args[i + 1]; break; } //Detect if errors were detected to avoid to continue if (errorDetected) { break; } i++; } } //Confirms all arguments were populated and no errors were detected if ((string.IsNullOrEmpty(this.projectFileName) || string.IsNullOrEmpty(this.testReportFile)) && !errorDetected) { Output.WriteMessage(new Message(MessageType.Error, ResourceLabel.StringErrorInvalidArguments, null)); } }
/// <summary> /// Entry Point /// </summary> /// <param name="args">DocumentationFileName TestReportFileName</param> static void Main(string[] args) { try { //Display Starting Message Output.WriteStartingMessage(startingTime); ProgramArguments pArgs = new ProgramArguments(args); //Detect if all arguments were populated to continue if (string.IsNullOrEmpty(pArgs.ProjectFileName) || string.IsNullOrEmpty(pArgs.TestReportFile)) { Output.WriteEndingMessage(startingTime); return; } Project projectTested = new Project(); FileParser parser = new FileParser(); parser.MessageRaised += new EventHandler <MessageEventArgs>(parser_MessageRaised); //Parse the project file projectTested = parser.ParseProjectFile(projectTested, pArgs.ProjectFileName); if (projectTested.Error) { Output.WriteEndingMessage(startingTime); return; } //Parse the documentation file into objects on memory //TODO: Refactor two parameters to one projectTested = parser.ParseDocumentationFile(projectTested, projectTested.DocumentationFile); if (projectTested.Error) { Output.WriteEndingMessage(startingTime); return; } //Parse the MSTest file into object on memory projectTested = parser.ParseMSTestFile(projectTested, pArgs.TestReportFile, pArgs.TestCategory); if (projectTested.Error) { Output.WriteEndingMessage(startingTime); return; } //Generates the html report Report reportManager = new Report(projectTested); reportManager.MessageRaised += new EventHandler <MessageEventArgs>(parser_MessageRaised); string reportContent = reportManager.PrepareReportContent(pArgs.ScenarioTemplateFileName, pArgs.FeatureTemplateFileName, pArgs.TestReportTemplateFileName); if (projectTested.Error) { Output.WriteEndingMessage(startingTime); return; } string reportFileName = reportManager.SaveReportOnDisc(reportContent, pArgs.TestCategory); //Print all ok on screen if no errors or warnings were written if (!Output.ErrorWarningWasWritten) { Output.WriteMessage(new Message(MessageType.Information, ResourceLabel.StringInformationNoErrorOrSuggestion, null)); } //Print Report Name on screen Output.WriteMessage(new Message(MessageType.Information, ResourceLabel.StringInformationReportGeneratedSuccessfully, new string[] { reportFileName })); Output.WriteEndingMessage(startingTime); } catch (Exception ex) { //Write unhandled error out on console Output.WriteMessage(new Message(MessageType.Error, ex.Message)); Output.WriteEndingMessage(startingTime); } }
/// <summary> /// Event Handler responsible of write message on the console /// </summary> /// <param name="sender">Object who raise the event</param> /// <param name="e">Customer MessageEventArgs with the message to write</param> static void parser_MessageRaised(object sender, MessageEventArgs e) { //Write the message on console Output.WriteMessage(e.MsgRaised); }