private void butNewDb_Click(object sender, EventArgs e) { textResults.Text = ""; Application.DoEvents(); Cursor = Cursors.WaitCursor; if (!_isOracle) { string serverAddr = textAddr.Text; string serverPort = textPort.Text; if (serverAddr == "") { serverAddr = "localhost"; } if (serverPort == "") { serverPort = "3306"; } if (!UnitTestsCore.DatabaseTools.SetDbConnection("", serverAddr, serverPort, textUserName.Text, textPassword.Text, _isOracle)) { OpenDental.MessageBox.Show("Could not connect"); return; } } DatabaseTools.FreshFromDump(textAddr.Text, textPort.Text, textUserName.Text, textPassword.Text, _isOracle); textResults.Text += "Fresh database loaded from sql dump."; Cursor = Cursors.Default; }
public void GetCompletedCases() { DataTable compcasesFor14; DataTable patsFor14; patsFor14 = KPICompletedCases.GetCompletedCasesPats( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05")); Assert.AreEqual(0, patsFor14.Rows.Count); var seedData2 = File.ReadAllText(@"..\..\Resources\kpi14completedcasesPT2.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData2); var startDate = new DateTime(2016, 3, 20); var endDate = new DateTime(2017, 4, 5); String patQuery = @" SELECT DISTINCT p.PatNum, p.LName, p.FName, p.MiddleI, p.HmPhone, p.WkPhone, p.WirelessPhone, p.Email FROM unittest.procedurelog pl JOIN unittest.appointment a ON pl.PlannedAptNum = a.AptNum JOIN unittest.procedurecode pc ON pc.CodeNum = pl.CodeNum JOIN unittest.patient p ON p.PatNum = pl.PatNum WHERE a.AptStatus = 6 AND pl.ProcStatus = 2 AND (pl.ProcDate BETWEEN '2016-03-21' AND '2018-03-21' ) "; // var patsFor14a = KPICompletedCases.GetCompletedCasesPats(startDate, endDate); var patsFor14a = StretchKPICustomForm.GetPatients(startDate, endDate, patQuery); Assert.IsNotNull(patsFor14a); Assert.AreEqual(1, patsFor14a.Rows.Count); var compcasesFor14a = KPICompletedCases.GetCompletedCasesPerPat(startDate, endDate, "1401"); Assert.AreEqual(1, compcasesFor14a.Rows.Count); var seedData3 = File.ReadAllText(@"..\..\Resources\kpi14completedcasesPT3.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData3); var patsFor14b = StretchKPICustomForm.GetPatients(startDate, endDate, patQuery); Assert.IsNotNull(patsFor14b); Assert.AreEqual(2, patsFor14b.Rows.Count); var compcasesFor14b = KPICompletedCases.GetCompletedCasesPerPat(startDate, endDate, "1402"); Assert.AreEqual(3, compcasesFor14b.Rows.Count); compcasesFor14b = KPICompletedCases.GetCompletedCasesPerPat(startDate, endDate, "1403"); Assert.AreEqual(3, compcasesFor14b.Rows.Count); }
public void Initialize() { //Create test DB DatabaseTools.SetDbConnection("", "localhost", "3306", "root", "", false); DatabaseTools.FreshFromDump("localhost", "3306", "root", "", false); //Inject data var seedData = File.ReadAllText(@"..\..\Resources\backlogrecall.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData); }
//Step 1: Start in SchemaCrudProposedTest. It is a series of proposed test methods (although not true crud). // Manually build some functional C# code that will make changes to the db when called. //Step 2: In FormUnitTests, check the radiobutton for "Test proposed crud". Click the Schema button. // It then calls each of the methods in the proposed crud, making sure that they don't crash and that each method makes valid calls to db. // There can still be errors if the crud queries don't crash, but still fail to perform the expected action. // So the ending schema should be checked for expected indexes, triggers, etc. // When the unit test Core Types button is clicked, some schema problems can be caught by failures at that point. //Step 3: In the CrudGenerator project, run with the Schema box checked in order to generate SchemaCrudTest. // SchemaCrudTest will not actually be used. It is simply to test the code generation ability. //Step 4: In FormUnitTests, check the radiobutton for "Compare proposed to generated". Click the Schema button. // It will compare SchemaCrudProposedTest to the generated SchemaCrudTest, and then notify the user whether they match or not. // If they don't match, alter CrudGenerator in order to produce the exact code needed. //Step 5: (Jordan only) Improve CrudGenerator to generate similar code on demand. This happens in three different situations: // a. Code is generated for the unit testing above. // b. Code is generated when a missing table or column is detected. // c. Code is also generated from the CrudGenerator interface to be copied and pasted into the ConvertDatabases class. // This can be done through the UI, or for more complex situations, by setting up some C# in CrudGenerator. public static string TestProposedCrud(bool isOracle) { string retVal = ""; DatabaseTools.SetDbConnection("unittest", isOracle); SchemaCrudProposedTest.AddTableTempcore(); SchemaCrudProposedTest.AddColumnEndClob(); SchemaCrudProposedTest.AddColumnEndInt(); SchemaCrudProposedTest.AddColumnEndTimeStamp(); SchemaCrudProposedTest.AddIndex(); SchemaCrudProposedTest.DropColumn(); retVal += "Proposed Crud passed test.\r\n"; return(retVal); }
private void butNewDb_Click(object sender, EventArgs e) { textResults.Text = ""; Application.DoEvents(); Cursor = Cursors.WaitCursor; if (!isOracle) { if (!DatabaseTools.SetDbConnection("", isOracle)) { MessageBox.Show("Could not connect"); return; } } DatabaseTools.FreshFromDump(isOracle); textResults.Text += "Fresh database loaded from sql dump."; Cursor = Cursors.Default; }
private void butHL7_Click(object sender, EventArgs e) { textResults.Text = ""; Application.DoEvents(); Cursor = Cursors.WaitCursor; if (!DatabaseTools.SetDbConnection("unittest", false)) //if database doesn't exist { DatabaseTools.SetDbConnection("", false); textResults.Text += DatabaseTools.FreshFromDump(false); //this also sets database to be unittest. } foreach (HL7TestInterfaceEnum hl7TestInterfaceEnum in Enum.GetValues(typeof(HL7TestInterfaceEnum))) { textResults.Text += DatabaseTools.ClearDb(); textResults.Text += "Testing " + hl7TestInterfaceEnum.ToString() + " interface.\r\n"; textResults.Text += HL7Tests.HL7TestAll(hl7TestInterfaceEnum); textResults.Text += "\r\n\r\n"; } textResults.Text += "Done\r\n"; Cursor = Cursors.Default; }
public static void Initialize(TestContext context) { ODInitialize.IsRunningInUnitTest = true; //Causes FormFriendlyException to throw rather than displaying a MessageBox. ODInitialize.Initialize(); if (!UnitTestsCore.DatabaseTools.SetDbConnection(UnitTestDbName, "localhost", "3306", "root", "", false)) //Put this in a config file in the future. { UnitTestsCore.DatabaseTools.SetDbConnection("", "localhost", "3306", "root", "", false); DatabaseTools.FreshFromDump("localhost", "3306", "root", "", false); //this also sets database to be unittest. } else { //Clear the database before running the unittests (instead of after) for two reasons //1- if the cleanup is done using [TestCleanup], the cleanup will not be run if the user cancels in the middle of a test while debugging //2- if a test fails, we may want to look at the data in the db to see why it failed. UnitTestsCore.DatabaseTools.ClearDb(); } if (!ODBuild.IsDebug()) { throw new Exception("Active solution configuration must be set to Debug for running unit tests."); } CreateAndSetUnitTestUser(); RevertMiddleTierSettingsIfNeeded(); //Set initial connection }
public static void Initialize(TestContext context) { if (!UnitTestsCore.DatabaseTools.SetDbConnection("unittest", "localhost", "3306", "root", "", false)) //Put this in a config file in the future. { UnitTestsCore.DatabaseTools.SetDbConnection("", "localhost", "3306", "root", "", false); DatabaseTools.FreshFromDump("localhost", "3306", "root", "", false); //this also sets database to be unittest. } else { //Clear the database before running the unittests (instead of after) for two reasons //1- if the cleanup is done using [TestCleanup], the cleanup will not be run if the user cancels in the middle of a test while debugging //2- if a test fails, we may want to look at the data in the db to see why it failed. UnitTestsCore.DatabaseTools.ClearDb(); } #if !DEBUG throw new Exception("You're running tests in release. BAD!!!"); #endif CreateUnitTestUser(); //Get the Admin user, should always exist Security.CurUser = Userods.GetUserByName(UnitTestUserName, false); Security.PasswordTyped = UnitTestPassword; //For middle tier unit tests. //Uncomment the next line in order to run every single unit test method like it is using the middle tier. //RunTestsAgainstMiddleTier(); }
private void butRun_Click(object sender, EventArgs e) { textResults.Text = ""; Application.DoEvents(); Cursor = Cursors.WaitCursor; if (!DatabaseTools.SetDbConnection("unittest", false)) //if database doesn't exist { DatabaseTools.SetDbConnection("", false); textResults.Text += DatabaseTools.FreshFromDump(false); //this also sets database to be unittest. } else { textResults.Text += DatabaseTools.ClearDb(); } try{ textResults.Text += BenefitT.BenefitComputeRenewDate(); } catch (Exception ex) { textResults.Text += ex.Message; //failed } try { textResults.Text += ToothT.FormatRanges(); } catch (Exception ex) { textResults.Text += ex.Message; //failed } int specificTest = 0; try { Application.DoEvents(); specificTest = PIn.Int(textSpecificTest.Text); //typically zero textResults.Text += AllTests.TestOneTwo(specificTest); } catch (Exception ex) { textResults.Text += "1&2: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestThree(specificTest); } catch (Exception ex) { textResults.Text += "3: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestFour(specificTest); } catch (Exception ex) { textResults.Text += "4: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestFive(specificTest); } catch (Exception ex) { textResults.Text += "5: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestSix(specificTest); } catch (Exception ex) { textResults.Text += "6: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestSeven(specificTest); } catch (Exception ex) { textResults.Text += "7: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestEight(specificTest); } catch (Exception ex) { textResults.Text += "8: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestNine(specificTest); } catch (Exception ex) { textResults.Text += "9: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestTen(specificTest); } catch (Exception ex) { textResults.Text += "10: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestEleven(specificTest); } catch (Exception ex) { textResults.Text += "11: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwelve(specificTest); } catch (Exception ex) { textResults.Text += "12: Failed. " + ex.Message + "\r\n"; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirteen(specificTest); } catch (Exception ex) { textResults.Text += "13: Failed. " + ex.Message + "\r\n"; } //try {//There is a phantom TestFourteen that has been commented out. It is similary to TestOne. // Application.DoEvents(); // textResults.Text+=AllTests.TestFourteen(specificTest); //} //catch(Exception ex) { // textResults.Text+="14: Failed. "+ex.Message+"\r\n"; //} try { Application.DoEvents(); textResults.Text += AllTests.TestFourteen(specificTest); } catch (Exception ex) { textResults.Text += "14: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestFifteen(specificTest); } catch (Exception ex) { textResults.Text += "15: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestSixteen(specificTest); } catch (Exception ex) { textResults.Text += "16: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestSeventeen(specificTest); } catch (Exception ex) { textResults.Text += "17: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestEighteen(specificTest); } catch (Exception ex) { textResults.Text += "18: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestNineteen(specificTest); } catch (Exception ex) { textResults.Text += "19: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwenty(specificTest); } catch (Exception ex) { textResults.Text += "20: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyOne(specificTest); } catch (Exception ex) { textResults.Text += "21: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyTwo(specificTest); } catch (Exception ex) { textResults.Text += "22: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyThree(specificTest); } catch (Exception ex) { textResults.Text += "23: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyFour(specificTest); } catch (Exception ex) { textResults.Text += "24: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyFive(specificTest); } catch (Exception ex) { textResults.Text += "25: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentySix(specificTest); } catch (Exception ex) { textResults.Text += "26: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentySeven(specificTest); } catch (Exception ex) { textResults.Text += "27: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyEight(specificTest); } catch (Exception ex) { textResults.Text += "28: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestTwentyNine(specificTest); } catch (Exception ex) { textResults.Text += "29: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirty(specificTest); } catch (Exception ex) { textResults.Text += "30: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirtyOne(specificTest); } catch (Exception ex) { textResults.Text += "31: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirtyTwo(specificTest); } catch (Exception ex) { textResults.Text += "32: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirtyThree(specificTest); } catch (Exception ex) { textResults.Text += "33: Failed. " + ex.Message; } try { Application.DoEvents(); textResults.Text += AllTests.TestThirtyFour(specificTest); } catch (Exception ex) { textResults.Text += "34: Failed. " + ex.Message; } textResults.Text += "Done"; Cursor = Cursors.Default; }
public void GetPendingTreatments() { DataTable plannedAppsFor13; DataTable patsFor13; patsFor13 = StretchKPICustomForm.GetPatients( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), KPIPendingTreatments.getPatQuery()); Assert.AreEqual(0, patsFor13.Rows.Count); // TEST FOR 2 TREATMENTS FOR 1 PAT, 1 PLANNEDAPPT; ONE TREATMENT HAS CODE 01202 var seedData2 = File.ReadAllText(@"..\..\Resources\kpi13pendingtreatmentsPT2.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData2); patsFor13 = StretchKPICustomForm.GetPatients( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), KPIPendingTreatments.getPatQuery()); plannedAppsFor13 = KPIPendingTreatments.GetPendingTreatmentProcsPerPat( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), patsFor13.Rows[0]["PatNum"].ToString()); Assert.AreEqual(1, patsFor13.Rows.Count); Assert.AreEqual(1, plannedAppsFor13.Rows.Count); // TEST FOR 6 MORE TREATMENTS FOR 3PATS, 2 MORE PLANNEDAPPTS var seedData3 = File.ReadAllText(@"..\..\Resources\kpi13pendingtreatmentsPT3.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData3); patsFor13 = StretchKPICustomForm.GetPatients( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), KPIPendingTreatments.getPatQuery()); Assert.AreEqual(3, patsFor13.Rows.Count); plannedAppsFor13 = KPIPendingTreatments.GetPendingTreatmentProcsPerPat( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), "1302"); Assert.AreEqual(3, plannedAppsFor13.Rows.Count); plannedAppsFor13 = KPIPendingTreatments.GetPendingTreatmentProcsPerPat( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), "1303"); Assert.AreEqual(3, plannedAppsFor13.Rows.Count); // TEST FOR 3 LESS TREATMENTS FOR 3PATS, 1 MORE SCHEDULEDAPPT var seedData4 = File.ReadAllText(@"..\..\Resources\kpi13pendingtreatmentsPT4.txt"); DatabaseTools.ExecuteSqlScript("localhost", "3306", "root", "", seedData4); patsFor13 = StretchKPICustomForm.GetPatients( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), KPIPendingTreatments.getPatQuery()); Assert.AreEqual(2, patsFor13.Rows.Count); plannedAppsFor13 = KPIPendingTreatments.GetPendingTreatmentProcsPerPat( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), "1302"); Assert.AreEqual(0, plannedAppsFor13.Rows.Count); plannedAppsFor13 = KPIPendingTreatments.GetPendingTreatmentProcsPerPat( Convert.ToDateTime("2016-03-20"), Convert.ToDateTime("2017-04-05"), "1303"); Assert.AreEqual(3, plannedAppsFor13.Rows.Count); }
/// <summary></summary> public static string CreateTempTable(bool isOracle) { string retVal = ""; DatabaseTools.SetDbConnection("unittest", isOracle); string command; if (DataConnection.DBtype == DatabaseType.MySql) { command = "DROP TABLE IF EXISTS tempcore"; DataCore.NonQ(command); command = @"CREATE TABLE tempcore ( TempCoreNum bigint NOT NULL, TimeOfDayTest time NOT NULL DEFAULT '00:00:00', TimeStampTest timestamp, DateTest date NOT NULL DEFAULT '0001-01-01', DateTimeTest datetime NOT NULL DEFAULT '0001-01-01 00:00:00', TimeSpanTest time NOT NULL DEFAULT '00:00:00', CurrencyTest double NOT NULL, BoolTest tinyint NOT NULL, TextTinyTest varchar(255) NOT NULL, TextSmallTest text NOT NULL, TextMediumTest text NOT NULL, TextLargeTest mediumtext NOT NULL, VarCharTest varchar(255) NOT NULL ) DEFAULT CHARSET=utf8" ; DataCore.NonQ(command); } else //oracle { command = "BEGIN EXECUTE IMMEDIATE 'DROP TABLE tempcore'; EXCEPTION WHEN OTHERS THEN NULL; END;"; DataCore.NonQ(command); command = @"CREATE TABLE tempcore ( TempCoreNum number(20), TimeOfDayTest date DEFAULT TO_DATE('0001-01-01','YYYY-MM-DD'), TimeStampTest timestamp DEFAULT TO_DATE('0001-01-01','YYYY-MM-DD'), DateTest date DEFAULT TO_DATE('0001-01-01','YYYY-MM-DD'), DateTimeTest date DEFAULT TO_DATE('0001-01-01','YYYY-MM-DD'), TimeSpanTest varchar2(255), CurrencyTest number(38,8), BoolTest number(3), TextTinyTest varchar2(255), TextSmallTest varchar2(4000), TextMediumTest clob, TextLargeTest clob, VarCharTest varchar2(255) )" ; DataCore.NonQ(command); } if (DataConnection.DBtype == DatabaseType.MySql) { command = "DROP TABLE IF EXISTS tempgroupconcat"; DataCore.NonQ(command); command = @"CREATE TABLE tempgroupconcat ( Names varchar(255) ) DEFAULT CHARSET=utf8" ; DataCore.NonQ(command); } else //oracle { command = "BEGIN EXECUTE IMMEDIATE 'DROP TABLE tempgroupconcat'; EXCEPTION WHEN OTHERS THEN NULL; END;"; DataCore.NonQ(command); command = @"CREATE TABLE tempgroupconcat ( Names varchar2(255) )" ; DataCore.NonQ(command); } retVal += "Temp tables created.\r\n"; //retVal+="Temp tables cannot yet be created.\r\n"; return(retVal); }