/** * Event handler for clicking the Create button for a unit test. This will * create an entry in the database for the specified information. */ protected void onclick_create_unit_test(object sender, EventArgs e) { try { // Create a new unit test definition. UnitTestDefinition test = new UnitTestDefinition(); test.Name = this.unit_test_name_.Text; test.Description = this.unit_test_description_.Text; test.LogFormats.AddRange(this.lf_manager_.SelectedItems); test.Relations.AddRange(this.lf_manager_.SelectedRelations); test.Grouping.AddRange(this.grouping_.Variables); test.EvalFunction = this.unit_test_eval_.Text; test.AggrFunction = this.aggr_function_.Text; if (this.database_.State == ConnectionState.Closed) { this.database_.Open(); } // Create the unit test in the database. this.database_.CreateNewUnitTest(test); this.master_.Console.Add(MessageSeverity.Info, "Successfully created unit test"); this.reset_unit_test_form(); } catch (Exception ex) { this.master_.Console.Add(MessageSeverity.Error, ex.Message); this.master_.Console.Add(MessageSeverity.Error, "Failed to create new unit test"); } finally { if (this.database_.State == ConnectionState.Open) { this.database_.Close(); } } }
private UnitTestResult Execute(UnitTestDefinition testDefinition) { UnitTestResult result = new() { Status = UnitTestResultStatus.Success }; try { using (var calc = new Calculation(_definition)) { foreach (var input in testDefinition.Input) { calc.Set(input with { }); } foreach (var expectedOutput in testDefinition.ExpectedOutput) { var actual = calc.Get(expectedOutput.Name); if (!expectedOutput.Equals(actual)) { result.Status = UnitTestResultStatus.Failed; result.FailedExpectations.Add(new FailedExpectation() { Actual = actual, Expected = expectedOutput }); } } } } catch (Exception ex) { result.Status = UnitTestResultStatus.Error; result.ErrorMessage = ex.ToString(); } return(result); } }