public void AddMissingColumn_Test_ColumnDidNotExistAndWeDetectedItCorrectly()
        {
            // Create a test database
            FAKE_SqlLiteDatabase db = CreateTestDatabase(String.Format("{0}", dbConstants.ID));

            db.InsertData(dbConstants.table_name, new string[3] {
                dbConstants.STATUS,
                dbConstants.XML,
                dbConstants.GUID
            }
                          , new object[3] {
                "boo status", "boo xml", "GUID_A"
            });
            _w.output(db.BackupDatabase());
            // add ColumnA to it
            bool result = db.TestAddMissingColumn(dbConstants.table_name, new string[1] {
                "boomer"
            },
                                                  new string[1] {
                "TEXT"
            });

            // check return value is true
            Assert.True(result);
            _w.output(db.BackupDatabase());
            // add ColumnA to it again. This time return value should be false (because we did not need to add the column)
            result = db.TestAddMissingColumn(dbConstants.table_name, new string[1] {
                "boomer"
            },
                                             new string[1] {
                "TEXT"
            });
            Console.WriteLine("Result #2 = " + result);
            Assert.False(result);
        }
        public void CreateExampleAndSystemLayouts()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            form.Show();
            //form.Visible=false; NOPE Form has to be visible now!!!

            DefaultLayouts.CreateExampleLayout(form, null);
            DefaultLayouts.CreateASystemLayout(form, null);
            FAKE_SqlLiteDatabase db    = new FAKE_SqlLiteDatabase(LayoutDetails.Instance.YOM_DATABASE);
            NoteDataXML_Table    table = (NoteDataXML_Table)LayoutDetails.Instance.TableLayout.FindNoteByGuid("systemqueries");

            Assert.NotNull(table);
            Assert.AreEqual("name", table.Columns[1].ColumnName);


            string result = db.BackupDatabase();

            Assert.Greater(result.Length, 29000);
            //Assert.AreEqual(29971, result.Length);
            db.Dispose();
            // creates the example and system layouts
            // to catch if any popups or other oddities introduced
            //Assert.True (false);
        }
        public void CreateExampleAndSystemLayouts()
        {
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            System.Windows.Forms .Form form = new System.Windows.Forms.Form();
            form.Show();
            //form.Visible=false; NOPE Form has to be visible now!!!

            DefaultLayouts.CreateExampleLayout(form,null);
            DefaultLayouts.CreateASystemLayout(form,null);
            FAKE_SqlLiteDatabase db = new FAKE_SqlLiteDatabase(LayoutDetails.Instance.YOM_DATABASE);
            NoteDataXML_Table table =  (NoteDataXML_Table) LayoutDetails.Instance.TableLayout.FindNoteByGuid("systemqueries");
            Assert.NotNull(table);
            Assert.AreEqual ("name", table.Columns[1].ColumnName);

            string result = db.BackupDatabase();
            Assert.Greater(result.Length,29000);
            //Assert.AreEqual(29971, result.Length);
            db.Dispose();
            // creates the example and system layouts
            // to catch if any popups or other oddities introduced
            //Assert.True (false);
        }
Example #4
0
        public void SpeedTest()
        {
            // this will be a benchmarking test that will create a complicated Layout
            // Then it will time and record the results of LOADING and SAVING that layout into a
            // table saved in my backup paths
            // will also output a DAAbackup file (text readable) format too
            _TestSingleTon.Instance._SetupForLayoutPanelTests();


            System.Windows.Forms.Form form = _TestSingleTon.Instance.FORM;             //new System.Windows.Forms.Form();



            FAKE_LayoutPanel panel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);

            form.Controls.Add(panel);

            // needed else DataGrid does not initialize

            form.Show();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form, null);


            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();

            panel.NewLayout(panelname, true, null);
            LayoutDetails.Instance.AddToList(typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output("herefirst");

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                for (int i = 0; i < 10; i++)
                {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                    panel.AddNote(note);
                    note.CreateParent(panel);
                }
            }
            _w.output("here");
            FAKE_NoteDataXML_Panel panelA = new FAKE_NoteDataXML_Panel();

            panelA.Caption = "PanelA";
            panel.AddNote(panelA);
            string stringoftypes = "";

            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML())
            {
                NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance(t);
                panelA.AddNote(note);
                stringoftypes = stringoftypes + " " + t.ToString();
            }
            panel.SaveLayout();
            string base_path = _TestSingleTon.PATH_TO_SpeedTestFiles;            //@"C:\Users\BrentK\Documents\Keeper\Files\yomspeedtests2013\";

            _w.output("here");
            NoteDataXML_RichText richy;

            for (int i = 0; i < 20; i++)
            {
                richy         = new NoteDataXML_RichText();
                richy.Caption = "richtext";
                panel.AddNote(richy);
                Assert.True(richy.GetIsRichTextBlank());
                richy.DoOverwriteWithRTFFile(System.IO.Path.Combine(base_path, "speedtest.rtf"));
                Assert.False(richy.GetIsRichTextBlank());
            }
            _w.output("First save");
            panel.SaveLayout();
            string table = "layoutpanelsaveload";
            // Now try and write this data out.
            SqlLiteDatabase timetracking = new SqlLiteDatabase(System.IO.Path.Combine(base_path, "speedtests.s3db"));

            timetracking.CreateTableIfDoesNotExist(table, new string [5] {
                "id", "datetime", "timetook", "types", "saveorload"
            },
                                                   new string[5] {
                "INTEGER", "TEXT", "FLOAT", "TEXT", "TEXT"
            }, "id");


            // * Now start the Load Test
            TimeSpan time;

            CoreUtilities.TimerCore.TimerOn = true;
            time = CoreUtilities.TimerCore.Time(() => {
                panel = new FAKE_LayoutPanel(CoreUtilities.Constants.BLANK, false);
                form.Controls.Add(panel);
                panel.LoadLayout(panelname, false, null);
            });
            _w.output("TIME " + time);



            timetracking.InsertData(table, new string[4] {
                "datetime", "timetook", "types", "saveorload"
            }, new object[4] {
                DateTime.Now.ToString(),
                time.TotalSeconds, stringoftypes, "load"
            });

            time = CoreUtilities.TimerCore.Time(() => {
                // We keep the PANEL from above! Don't recreate it.
                //panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK);
                panel.SaveLayout();
            });


            Console.WriteLine("TIME " + time);

            timetracking.InsertData(table, new string[4] {
                "datetime", "timetook", "types", "saveorload"
            }, new object[4] {
                DateTime.Now.ToString(),
                time.TotalSeconds, stringoftypes, "save"
            });

            string backup = timetracking.BackupDatabase();

            System.IO.TextWriter write = new System.IO.StreamWriter(System.IO.Path.Combine(base_path, "timeresults.txt"));
            write.WriteLine(backup);

            write.Close();

            FakeLayoutDatabase   layout = new FakeLayoutDatabase("testguid");
            FAKE_SqlLiteDatabase db     = new FAKE_SqlLiteDatabase(layout.GetDatabaseName());

            _w.output("Backup of stored database: " + db.BackupDatabase());

            timetracking.Dispose();
            db.Dispose();
        }
        public void CreateFakeDatabaseAndBackup()
        {
            SqlLiteDatabase db = CreateTestDatabase(String.Format("{0}", dbConstants.GUID));

            db.InsertData(dbConstants.table_name, new string[3] {
                dbConstants.STATUS, dbConstants.XML, dbConstants.GUID
            }, new object[3] {
                "boo status", "boo xml", "GUID_A"
            });
            db.InsertData(dbConstants.table_name, new string[3] {
                dbConstants.STATUS, dbConstants.XML, dbConstants.GUID
            }, new object[3] {
                "boo status2", "boo xml2", "GUID_A2"
            });
            db.Dispose();


            db = new FAKE_SqlLiteDatabase(test_database_name);


            try {
                db.DropTableIfExists(dbConstants.table_name + "_b");
            } catch (Exception ex) {
                _w.output(String.Format("Unable to drop table {0}", ex.ToString()));
            }

            db.CreateTableIfDoesNotExist(dbConstants.table_name + "_b", new string[4]
            {
                dbConstants.ID, dbConstants.GUID, dbConstants.XML,
                dbConstants.STATUS
            },
                                         new string[4] {
                "INTEGER",
                "TEXT UNIQUE",
                "LONGTEXT",
                "TEXT"
            }, dbConstants.GUID
                                         );


            db.InsertData(dbConstants.table_name + "_b", new string[3] {
                dbConstants.STATUS, dbConstants.XML, dbConstants.GUID
            }, new object[3] {
                "boo status", "boo xml", "GUID_B"
            });



            db.Dispose();
            db = new FAKE_SqlLiteDatabase(test_database_name);


            try {
                db.DropTableIfExists(dbConstants.table_name + "_c");
            } catch (Exception ex) {
                _w.output(String.Format("Unable to drop table {0}", ex.ToString()));
            }

            db.CreateTableIfDoesNotExist(dbConstants.table_name + "_c", new string[4]
            {
                dbConstants.ID, dbConstants.GUID, dbConstants.XML,
                dbConstants.STATUS
            },
                                         new string[4] {
                "INTEGER",
                "TEXT UNIQUE",
                "LONGTEXT",
                "TEXT"
            }, dbConstants.GUID
                                         );

            db.InsertData(dbConstants.table_name + "_c", new string[3] {
                dbConstants.STATUS, dbConstants.XML, dbConstants.GUID
            }, new object[3] {
                "boo status", "boo xml", "GUID_C"
            });

            // get rid of full text database too
            db.DropTableIfExists("fulltextsearch");

            //not sure how to set this test up. Force File Write? Then test if file exists?
            // or shoudl this return a Stream?
            string result = db.BackupDatabase();

            _w.output(result.Length);
            _w.output(result);

            db.DropTableIfExists(dbConstants.table_name + "_b");
            db.DropTableIfExists(dbConstants.table_name + "_c");
            db.Dispose();
            Assert.AreEqual(526, result.Length);
            //Assert.False (true);
        }
        public void SpeedTest()
        {
            // this will be a benchmarking test that will create a complicated Layout
            // Then it will time and record the results of LOADING and SAVING that layout into a
            // table saved in my backup paths
            // will also output a DAAbackup file (text readable) format too
            _TestSingleTon.Instance._SetupForLayoutPanelTests();

            System.Windows.Forms .Form form = _TestSingleTon.Instance.FORM;//new System.Windows.Forms.Form();

            FAKE_LayoutPanel panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK, false);

            form.Controls.Add (panel);

            // needed else DataGrid does not initialize

            form.Show ();
            //form.Visible = false;
            _w.output("boom");
            // March 2013 -- notelist relies on having this
            YOM2013.DefaultLayouts.CreateASystemLayout(form,null);

            //NOTE: For now remember that htis ADDS 1 Extra notes
            string panelname = System.Guid.NewGuid().ToString();
            panel.NewLayout (panelname,true, null);
            LayoutDetails.Instance.AddToList (typeof(FAKE_NoteDataXML_Panel), "testingpanel");
            _w.output ("herefirst");

            // ADD 1 of each type
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML()) {
                for (int i = 0; i < 10; i++) {
                    NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance (t);
                    panel.AddNote (note);
                    note.CreateParent(panel);
                }
            }
            _w.output("here");
            FAKE_NoteDataXML_Panel panelA = new FAKE_NoteDataXML_Panel ();
            panelA.Caption = "PanelA";
            panel.AddNote (panelA);
            string stringoftypes = "";
            foreach (Type t in LayoutDetails.Instance.ListOfTypesToStoreInXML()) {
                NoteDataInterface note = (NoteDataInterface)Activator.CreateInstance (t);
                panelA.AddNote (note);
                stringoftypes = stringoftypes + " " + t.ToString();
            }
            panel.SaveLayout();
            string base_path = _TestSingleTon.PATH_TO_SpeedTestFiles;//@"C:\Users\BrentK\Documents\Keeper\Files\yomspeedtests2013\";
            _w.output ("here");
            NoteDataXML_RichText richy;
            for (int i = 0; i < 20; i ++) {
                richy = new NoteDataXML_RichText ();
                richy.Caption = "richtext";
                panel.AddNote (richy);
                Assert.True (richy.GetIsRichTextBlank ());
                richy.DoOverwriteWithRTFFile (System.IO.Path.Combine (base_path,"speedtest.rtf"));
                Assert.False (richy.GetIsRichTextBlank ());
            }
            _w.output("First save");
            panel.SaveLayout();
            string table = "layoutpanelsaveload";
            // Now try and write this data out.
            SqlLiteDatabase timetracking = new SqlLiteDatabase(System.IO.Path.Combine (base_path,"speedtests.s3db"));
            timetracking.CreateTableIfDoesNotExist(table, new string [5] {"id", "datetime", "timetook", "types","saveorload"},
            new string[5] {"INTEGER", "TEXT", "FLOAT", "TEXT", "TEXT"}, "id");

            // * Now start the Load Test
            TimeSpan time;
            CoreUtilities.TimerCore.TimerOn = true;
            time = CoreUtilities.TimerCore.Time (() => {
            panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK, false);
                form.Controls.Add (panel);
                panel.LoadLayout(panelname, false,null);
            });
            _w.output("TIME " + time);

            timetracking.InsertData(table, new string[4] {"datetime", "timetook", "types","saveorload"},new object[4] {DateTime.Now.ToString (),
                time.TotalSeconds, stringoftypes,"load"});

            time = CoreUtilities.TimerCore.Time (() => {
                // We keep the PANEL from above! Don't recreate it.
                //panel = new FAKE_LayoutPanel (CoreUtilities.Constants.BLANK);
                panel.SaveLayout();
            });

            Console.WriteLine("TIME " + time);

            timetracking.InsertData(table, new string[4] {"datetime", "timetook", "types","saveorload"},new object[4] {DateTime.Now.ToString (),
                time.TotalSeconds, stringoftypes,"save"});

            string backup = timetracking.BackupDatabase();

            System.IO.TextWriter write = new System.IO.StreamWriter(System.IO.Path.Combine (base_path,"timeresults.txt"));
            write.WriteLine (backup);

            write.Close();

            FakeLayoutDatabase layout = new FakeLayoutDatabase("testguid");
            FAKE_SqlLiteDatabase db = new FAKE_SqlLiteDatabase(layout.GetDatabaseName ());
            _w.output("Backup of stored database: " + db.BackupDatabase());

            timetracking.Dispose();
            db.Dispose();
        }
        public void CreateFakeDatabaseAndBackup()
        {
            SqlLiteDatabase db =CreateTestDatabase(String.Format ("{0}", dbConstants.GUID));
            db.InsertData (dbConstants.table_name, new string[3] {	dbConstants.STATUS,dbConstants.XML,dbConstants.GUID
            }, new object[3] {"boo status", "boo xml", "GUID_A"});
            db.InsertData (dbConstants.table_name, new string[3] {	dbConstants.STATUS,dbConstants.XML,dbConstants.GUID
            }, new object[3] {"boo status2", "boo xml2", "GUID_A2"});
            db.Dispose();

            db = new FAKE_SqlLiteDatabase (test_database_name);

            try {

                db.DropTableIfExists(dbConstants.table_name+"_b");
            } catch (Exception ex) {
                _w.output (String.Format ("Unable to drop table {0}", ex.ToString()));
            }

            db.CreateTableIfDoesNotExist (dbConstants.table_name+"_b", new string[4]
                                          {dbConstants.ID, dbConstants.GUID, dbConstants.XML,
                dbConstants.STATUS},
            new string[4] {
                "INTEGER",
                "TEXT UNIQUE",
                "LONGTEXT",
                "TEXT"
            }, dbConstants.GUID
            );

            db.InsertData (dbConstants.table_name+"_b", new string[3] {	dbConstants.STATUS,dbConstants.XML,dbConstants.GUID
            }, new object[3] {"boo status", "boo xml", "GUID_B"});

            db.Dispose();
            db = new FAKE_SqlLiteDatabase (test_database_name);

            try {

                db.DropTableIfExists(dbConstants.table_name+"_c");
            } catch (Exception ex) {
                _w.output (String.Format ("Unable to drop table {0}", ex.ToString()));
            }

            db.CreateTableIfDoesNotExist (dbConstants.table_name+"_c", new string[4]
                                          {dbConstants.ID, dbConstants.GUID, dbConstants.XML,
                dbConstants.STATUS},
            new string[4] {
                "INTEGER",
                "TEXT UNIQUE",
                "LONGTEXT",
                "TEXT"
            }, dbConstants.GUID
            );

            db.InsertData (dbConstants.table_name+"_c", new string[3] {	dbConstants.STATUS,dbConstants.XML,dbConstants.GUID
            }, new object[3] {"boo status", "boo xml", "GUID_C"});

            // get rid of full text database too
            db.DropTableIfExists("fulltextsearch");

            //not sure how to set this test up. Force File Write? Then test if file exists?
            // or shoudl this return a Stream?
            string result = db.BackupDatabase();
            _w.output(result.Length);
            _w.output(result);

            db.DropTableIfExists(dbConstants.table_name+"_b");
            db.DropTableIfExists(dbConstants.table_name+"_c");
            db.Dispose();
            Assert.AreEqual(526, result.Length);
            //Assert.False (true);
        }