Exemplo n.º 1
0
        public static void FilterOrExpression()
        {
            Database      database = new SQLiteDatabase(".\\", MethodBase.GetCurrentMethod().Name);
            ConsoleLogger logger   = PrepareDatabaseAndGetLogger(database);

            TestTable one = new TestTable();

            one.Name = "banana";
            one.Save(database);

            TestTable two = new TestTable();

            two.Name = "blah";
            two.Save(database);

            DaoExpressionFilter v          = new DaoExpressionFilter(logger);
            QueryFilter         testFilter = v.Where <TestTable>((t) => t.Name == one.Name).Or <TestTable>((t) => t.Name == two.Name);

            TestTableCollection check = TestTable.Where(c => c.Name == "banana" || c.Name == "blah", database);

            Expect.IsNotNull(check);

            TestTableCollection evalCheck = TestTable.Where(testFilter, database);

            Expect.IsNotNull(evalCheck);

            Expect.AreEqual(2, evalCheck.Count);
            Out(v.TraceLog, ConsoleColor.Cyan);
        }
Exemplo n.º 2
0
        public void OrTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;
            string one        = 4.RandomLetters();
            string two        = 4.RandomLetters();

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                TestTable first  = DataTools.CreateTestTable("{0}_{1}"._Format(one, 4.RandomLetters()), db);
                TestTable second = DataTools.CreateTestTable("{0}_{1}"._Format(two, 4.RandomLetters()), db);
                TestTable third  = DataTools.CreateTestTable(8.RandomLetters(), db);

                TestTableCollection results = TestTable.Where(c => c.Name.StartsWith(one).Or(c.Name.StartsWith(two)), db);
                Expect.AreEqual(2, results.Count);
                List <TestTable> list = results.ToList();
                Expect.IsTrue(list.Contains(first));
                Expect.IsTrue(list.Contains(second));
                Expect.IsFalse(list.Contains(third));

                results = TestTable.Where(c => c.Name.StartsWith(one) || c.Name.StartsWith(two), db);
                Expect.AreEqual(2, results.Count);
                list = results.ToList();
                Expect.IsTrue(list.Contains(first));
                Expect.IsTrue(list.Contains(second));
                Expect.IsFalse(list.Contains(third));
            });
        }
Exemplo n.º 3
0
        public void EndsWithTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;
            string endsWith   = 7.RandomLetters();

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                3.Times(i =>
                {
                    DataTools.CreateTestTable("{0}{1}"._Format(4.RandomLetters(), endsWith), db);
                });

                5.Times(i =>
                {
                    DataTools.CreateTestTable(11.RandomLetters(), db);
                });

                TestTableCollection endsWithResults = TestTable.Where(c => c.Name.EndsWith(endsWith), db);
                Expect.AreEqual(3, endsWithResults.Count);

                TestTableCollection doesntEndWithResults = TestTable.Where(c => c.Name.DoesntEndWith(endsWith), db);
                Expect.IsTrue(doesntEndWithResults.Count > 0);
                doesntEndWithResults.Each(endsWithResults.ToList(), (ewr, tt) =>
                {
                    Expect.IsFalse(ewr.Contains(tt));
                });
            });
        }
Exemplo n.º 4
0
        public void ContainsTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;
            string contains   = 7.RandomLetters();

            _testDatabases.Each(db =>
            {
                OutLineFormat("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                3.Times(i =>
                {
                    DataTools.CreateTestTable("{0}{1}{2}"._Format(4.RandomLetters(), contains, 4.RandomLetters()), db);
                });

                5.Times(i =>
                {
                    DataTools.CreateTestTable(11.RandomLetters(), db);
                });

                TestTableCollection containsResults = TestTable.Where(c => c.Name.Contains(contains), db);
                Expect.AreEqual(3, containsResults.Count);

                TestTableCollection doesntContainResults = TestTable.Where(c => c.Name.DoesntContain(contains), db);
                Expect.IsTrue(doesntContainResults.Count > 0);
                doesntContainResults.Each(containsResults.ToList(), (cr, tt) =>
                {
                    Expect.IsFalse(cr.Contains(tt));
                });
            });
        }
Exemplo n.º 5
0
        public static void DaoExpressionFilterTest()
        {
            SQLiteBitMonitor.MonitorBitness();
            Database      database = new SQLiteDatabase(".\\", MethodBase.GetCurrentMethod().Name);
            ConsoleLogger logger   = PrepareDatabaseAndGetLogger(database);

            TestTable testInstance = new TestTable();

            testInstance.Name = "banana";
            testInstance.Save(database);

            DaoExpressionFilter v          = new DaoExpressionFilter(logger);
            QueryFilter         testFilter = v.Where <TestTable>((t) => t.Name == testInstance.Name);

            TestTable check = TestTable.Where(Filter.Column("Name") == "banana", database).FirstOrDefault();

            Expect.IsNotNull(check);

            TestTable evalCheck = TestTable.Where(testFilter, database).FirstOrDefault();

            Expect.IsNotNull(evalCheck);

            Expect.AreEqual(check.Id, evalCheck.Id);
            Out(v.TraceLog, ConsoleColor.Cyan);
        }
Exemplo n.º 6
0
        public void PagedQueryTest()
        {
            (_testDatabases.Count > 0).IsTrue();
            string name = MethodBase.GetCurrentMethod().Name;

            _testDatabases.Each(db =>
            {
                TestTableCollection testTables = CreateTestTableEntries(name, db);
                testTables = TestTable.Where(c => c.Name.StartsWith(name), db);
                Expect.AreEqual(8, testTables.Count, "There should have been 8 records but there were {0}"._Format(testTables.Count));
                PagedQuery <TestTableColumns, TestTable> q = new PagedQuery <TestTableColumns, TestTable>(new TestTableColumns().Id, testTables.Query, db);
                q.LoadMeta();
                Expect.IsGreaterThan(q.PageCount, 0, "Page count should have been greater than 0");
                Message.PrintLine("Page count was {0} for {1}", ConsoleColor.Cyan, q.PageCount, db.GetType().Name);
                CheckExpectations(q);
            });
        }
Exemplo n.º 7
0
        public void InQueryTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                List <TestTable> tables = new List <TestTable>();
                8.Times(i =>
                {
                    tables.Add(DataTools.CreateTestTable(4.RandomLetters(), db));
                });

                Expect.AreEqual(8, tables.Count);
                List <ulong> ids = new List <ulong>(tables.Select(t => t.Id.Value).ToArray());
                TestTableCollection retrieved = TestTable.Where(c => c.Id.In(ids.ToArray()), db);
                Expect.AreEqual(tables.Count, retrieved.Count);
            });
        }
Exemplo n.º 8
0
        public void AndTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName            = MethodBase.GetCurrentMethod()?.Name;
            string nameStartsWith        = 4.RandomLetters();
            string descriptionStartsWith = 4.RandomLetters();

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                TestTable one   = DataTools.CreateTestTable("{0}_{1}"._Format(nameStartsWith, 4.RandomLetters()), "{0}_{1}"._Format(descriptionStartsWith, 4.RandomLetters()), db);
                TestTable two   = DataTools.CreateTestTable("{0}_{1}"._Format(nameStartsWith, 4.RandomLetters()), "{0}_{1}"._Format(descriptionStartsWith, 4.RandomLetters()), db);
                TestTable three = DataTools.CreateTestTable(nameStartsWith, db);

                TestTableCollection results  = TestTable.Where(c => c.Name.StartsWith(nameStartsWith).And(c.Description.StartsWith(descriptionStartsWith)), db);
                TestTableCollection results2 = TestTable.Where(c => c.Name.StartsWith(nameStartsWith) && c.Description.StartsWith(descriptionStartsWith), db);
                Expect.AreEqual(2, results.Count);
                Expect.AreEqual(2, results2.Count);
            });
        }