예제 #1
0
        public void UniversalDataCollectorDataModelUpdateCheck()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable2>();

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable2>());

            UniversalDataCollector.Register<SampleTable1>();
            UniversalDataCollector.Register<SampleTable2>();

            for (int i = 0; i < 20; i++)
            {
                var inserted_entry1 = new SampleTable1 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry1.Add();

                var inserted_entry2 = new SampleTable2 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry2.Add();
            }

            Assert.IsTrue(UniversalDataCollector.Select<SampleTable1>().Count == 20);
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 20);

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteMatching<SampleTable1>(new[] { new Selector("Column1", 80, Selector.Operator.LessThan) });

            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 20);
            var other_results = UniversalDataCollector.Select<SampleTable1>();
            Assert.IsTrue(other_results.Count == 12);

            var second_entry = other_results[1] as SampleTable1;

            Assert.IsTrue(other_results.First().Remove());

            Assert.IsTrue(UniversalDataCollector.Select<SampleTable1>().Count == 11);
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 20);

            second_entry.Column2 = "Does this work";
            Assert.IsTrue(second_entry.Update());

            Assert.IsTrue(UniversalDataCollector.Select<SampleTable1>().Count == 11);
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 20);

            var grabbed_entry = UniversalDataCollector.Select<SampleTable1>(new []{new Selector("Column1", 90)})[0] as SampleTable1;

            Assert.IsTrue(second_entry.Equals(grabbed_entry));

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteAll<SampleTable1>();
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable1>().Count == 0);

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteAll<SampleTable2>();
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 0);
        }
예제 #2
0
        public void TestingDataTableLoading()
        { 
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            for (int i = 0; i < 20; i++)
            {
                var inserted_entry = new SampleTable1 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry.Add();
            }

            DataTable dtblMain = new DataTable();
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).FillDataTable<SampleTable1>(ref dtblMain, new []{new Selector("Column1", 100, Selector.Operator.LessThan)});

            Assert.IsTrue(dtblMain.Rows.Count == 10);
        }
예제 #3
0
        public void LoadingItemsToDatabaseEntityViewer()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            for (int i = 0; i < 20; i++)
            {
                var inserted_entry = new SampleTable1 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry.Add();

                var fetched_entries = GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>(new[] { new Selector("Column1", inserted_entry.Column1) });
                Assert.IsTrue(fetched_entries.Length == 1);

                var fetched_entry = fetched_entries.First() as SampleTable1;
                Assert.IsNotNull(fetched_entry);
                var sample_text = fetched_entry.Column2 = "This is the modified value " + DateTime.Now.Ticks;
                Assert.IsTrue(fetched_entry.Update());

                fetched_entries = GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>(new[] { new Selector("Column1", inserted_entry.Column1) });
                Assert.IsTrue(fetched_entries.Length == 1);

                var newly_fetched_entry = fetched_entries.First() as SampleTable1;
                Assert.IsNotNull(newly_fetched_entry);
                Assert.AreEqual(newly_fetched_entry.Column1, inserted_entry.Column1);
                Assert.AreEqual(newly_fetched_entry.Column2, sample_text);
            }

            var form = DatabaseEntityViewer.ShowNonModalWindow<SampleTable1>(null);
            form.Close();

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteAll<SampleTable1>());

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>().Length == 0);
        }
예제 #4
0
        public void RegisteringEntityTypeOnUniversalDataCollector()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable2>();

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable2>());

            UniversalDataCollector.Register<SampleTable1>();
            UniversalDataCollector.Register<SampleTable2>();

            for (int i = 0; i < 20; i++)
            {
                var inserted_entry1 = new SampleTable1 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry1.Add();

                var inserted_entry2 = new SampleTable2 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry2.Add();
            }

            Assert.IsTrue(UniversalDataCollector.Select<SampleTable1>().Count == 20);
            Assert.IsTrue(UniversalDataCollector.Select<SampleTable2>().Count == 20);
        }
예제 #5
0
        public void ReferenceKeyViolationException_SampleTable1_2()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable2>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable2>());

            var inserted_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
            inserted_entry.Add();

            var inserted_sample_table2_entry = new SampleTable2 { Column1 = 10, Column2 = "The Next Set of Data", Column3 = inserted_entry.Column1 };
            inserted_sample_table2_entry.Add();

            Assert.IsTrue(Relationship.CheckReferences(inserted_entry));

            try
            {
                inserted_entry.Remove();
                Assert.Fail("No Error was Thrown !");
            }
            catch (DatabaseException ex)
            {
                if (ex.GetErrorType() != DatabaseException.ErrorType.ReferenceKeyViolation)
                {
                    Assert.Fail("The Correct Exception was Thrown, but not the Correct Error Type !");
                }
                else
                {
                    Assert.IsNotNull(ex.GetAdditionalData());
                }
            }
            catch (System.Exception)
            {
                Assert.Fail("Invalid Exception was Thrown !");
            }

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>(new[] { new Selector("Column1", inserted_entry.Column1) }).Length == 1);
        }
예제 #6
0
        public void LoadingItemToDbEntityForm()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            var inserted_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
            var frmSampleTable = DatabaseEntityForm.ShowWindow<frmSampleTable1>(inserted_entry);
            var retrieved_entry = frmSampleTable.GetUpdatedEntity();
            frmSampleTable.Close();

            Assert.IsTrue(inserted_entry.Equals(retrieved_entry));
        }
예제 #7
0
        public void ReferenceCheckValidation_SampleTable2()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable2>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable2>());

            var inserted_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
            inserted_entry.Add();

            var inserted_sample_table2_entry = new SampleTable2 { Column1 = 10, Column2 = "The Next Set of Data", Column3 = inserted_entry.Column1 };
            inserted_sample_table2_entry.Add();

            Assert.IsTrue(Relationship.CheckReferences(inserted_entry));

            inserted_sample_table2_entry.Remove();

            Assert.IsFalse(Relationship.CheckReferences(inserted_entry));
        }
예제 #8
0
        public void CheckEqualObjects()
        {
            var entry_1 = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
            var entry_2 = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };

            Assert.IsTrue(entry_1.Equals(entry_2));
        }
예제 #9
0
        public void CreateDuplicateInsert_SampleTable1()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            var inserted_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
            inserted_entry.Add();
            try
            {
                var clone_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
                clone_entry.Add();
                Assert.Fail("No Error was Thrown !");
            }
            catch (DatabaseException ex)
            {
                if (ex.GetErrorType() != DatabaseException.ErrorType.RecordAlreadyExists &&
                    ex.GetErrorType() != DatabaseException.ErrorType.AlreadyExistingUnqiueField)
                {
                    Assert.Fail("The Correct Exception was Thrown, but not the Correct Error Type !");
                }
            }
            catch (System.Exception)
            {
                Assert.Fail("Invalid Exception was Thrown !");
            }

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteAll<SampleTable1>());

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>().Length == 0);

            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DropTable<SampleTable1>();
            Assert.IsFalse(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());
        }
예제 #10
0
        public void CreateInsertAndDeleteMultiple2_SampleTable1()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            for (int i = 0; i < 20; i++)
            {
                var inserted_entry = new SampleTable1 { Column1 = i * 10, Column2 = "Sample Data" };
                inserted_entry.Add();

                var fetched_entries = GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>();
                Assert.IsTrue(fetched_entries.Length == i + 1);
            }

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).DeleteAll<SampleTable1>());

            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>().Length == 0);
        }
예제 #11
0
        public void CreateInsertAndDeleteMultiple1_SampleTable1()
        {
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable1>();
            GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).CreateTable<SampleTable2>();
            Assert.IsTrue(GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).TableExist<SampleTable1>());

            for (int i = 0; i < 100; i++)
            {
                var inserted_entry = new SampleTable1 { Column1 = 1, Column2 = "Sample Data" };
                inserted_entry.Add();

                var fetched_entries = GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>();
                Assert.IsTrue(fetched_entries.Length == 1);

                var fetched_entry = fetched_entries.First() as SampleTable1;

                Assert.IsTrue(fetched_entry != null);
                Assert.IsTrue(fetched_entry.Column1 == inserted_entry.Column1);
                Assert.IsTrue(fetched_entry.Column2 == inserted_entry.Column2);

                Assert.IsTrue(fetched_entry.Remove());

                fetched_entries = GenericDatabaseManager.GetDatabaseManager(DatabaseType.MySQL).Select<SampleTable1>();
                Assert.IsTrue(fetched_entries.Length == 0);
            }
        }