whereconditiontest.cs

来自「基于LINQ和.NET 3.5 的数据库源码」· CS 代码 · 共 102 行

CS
102
字号
using Lephone.Data;
using Lephone.Data.Builder.Clause;
using Lephone.Data.Common;
using Lephone.Data.Dialect;
using Lephone.Data.SqlEntry;
using NUnit.Framework;

namespace Lephone.UnitTest.Data.Inner
{
    [TestFixture]
    public class WhereConditionTest
    {
        [Test]
        public void Test1()
        {
            WhereCondition c = null;
            c = ((c & null) | null);
            Assert.IsTrue(c is EmptyCondition);
        }

        [Test]
        public void Test2()
        {
            WhereCondition c = null;
            c = ((c & null) | null);
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual("", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test3()
        {
            WhereCondition c = WhereCondition.EmptyCondition;
            c = ((c & null) | null);
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual("", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test4()
        {
            WhereCondition c = WhereCondition.EmptyCondition;
            c &= (CK.K["Id"] == 1 | CK.K["Age"] > 18);
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.IsFalse(c is EmptyCondition);
            Assert.AreEqual(" Where ([Id] = @Id_0) Or ([Age] > @Age_1)", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test5()
        {
            WhereCondition c = WhereCondition.EmptyCondition;
            c = c.And(CK.K["Id"].Eq(1)).Or(CK.K["Age"].Gt(18));
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual(" Where ([Id] = @Id_0) Or ([Age] > @Age_1)", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test6()
        {
            WhereCondition c = null;
            c &= (CK.K["Id"] == 1 | CK.K["Age"] > 18);
            c &= null;
            c |= null;
            c &= CK.K["Gender"] == true;
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual(" Where (([Id] = @Id_0) Or ([Age] > @Age_1)) And ([Gender] = @Gender_2)", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test7()
        {
            WhereCondition c = WhereCondition.EmptyCondition;
            c = c.And(CK.K["Id"].Eq(1)).Or(CK.K["Age"].Gt(18));
            c = c.And(null);
            c = c.Or(null);
            c = c.And(CK.K["Gender"].Eq(true));
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual(" Where (([Id] = @Id_0) Or ([Age] > @Age_1)) And ([Gender] = @Gender_2)", cc.ToSqlText(dpc, new Access()));
        }

        [Test]
        public void Test8()
        {
            WhereCondition c = WhereCondition.EmptyCondition;
            c = c.And(CK.K["Id"] == 1).Or(CK.K["Age"] > 18);
            c = c.And(null);
            c = c.Or(null);
            c = c.And(CK.K["Gender"].Eq(true));
            WhereClause cc = new WhereClause(c);
            DataParamterCollection dpc = new DataParamterCollection();
            Assert.AreEqual(" Where (([Id] = @Id_0) Or ([Age] > @Age_1)) And ([Gender] = @Gender_2)", cc.ToSqlText(dpc, new Access()));
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?