⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smarkdatatest.cs

📁 smark.data是基于C#开发的轻量级数据访问组件。 提供以下功能封: 1)提供了跨数据库类型操作能力 2)基于程线存储的数据访问上下文对象
💻 CS
📖 第 1 页 / 共 2 页
字号:
        }
        [TestMethod]
        public void op_Equality()
        {
            Expression exp = Order.employeeID == new int[] {1,3,5 };
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
            WriteSplit();
            exp = Order.employeeID == 3;
            items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
            WriteSplit();
            exp = Order.employeeID == null;
            items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);


        }
        [TestMethod]
        public void op_Inequality()
        {
            Expression exp = Order.employeeID != new int[] { 1, 3, 5 };
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
            WriteSplit();
            exp = Order.employeeID != 3;
            items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
            WriteSplit();
            exp = Order.employeeID != null;
            items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void op_GreaterThan()
        {
            Expression exp = Order.orderDate > "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void op_LessThan()
        {
            Expression exp = Order.orderDate < "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void op_GreaterThanOrEqual()
        {
            Expression exp = Order.orderDate >= "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void op_LessThanOrEqual()
        {
            Expression exp = Order.orderDate <= "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void Or()
        {
            Expression exp = Order.employeeID == 3 | Order.orderDate == "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void And()
        {
            Expression exp = Order.employeeID == 3 & Order.orderDate == "1996-1-1";
            IList<Order> items = Order.List(exp);
            WriteExpression(exp);
            WriteOrder(items);
        }
        [TestMethod]
        public void CountByEmployee()
        {
            Expression exp = Order.employeeID.At("o").In(Employee.employeeID, Employee.country == "usa");
            IList<OrdersByEmployee> items = OrdersByEmployee.List(exp);
            WriteExpression(exp);
            TestContext.WriteLine("Count\tEmployeeName");
            foreach (OrdersByEmployee item in items)
            {
                TestContext.WriteLine("{0}\t{1}", item.Orders, item.EmployeeName);
            }

            exp = Order.orderDate.Between("1995-5-1", "1995-6-1");
            items = OrdersByEmployee.List(exp);
            WriteExpression(exp);
            TestContext.WriteLine("Count\tEmployeeName");
            foreach (OrdersByEmployee item in items)
            {
                TestContext.WriteLine("{0}\t{1}", item.Orders, item.EmployeeName);
            }
        }
        [TestMethod]
        public void CountByCustomer()
        {
            Expression exp = Order.customerID.At("o") == new string[] { "ANATR", "ANTON", "BLONP" };
            IList<OrderByCustomer> items = OrderByCustomer.List(exp);
            WriteExpression(exp);
            TestContext.WriteLine("Count\tCompanyName");
            foreach (OrderByCustomer item in items)
            {
                TestContext.WriteLine("{0}\t{1}", item.Orders, item.CompanyName);
            }

            exp = Order.orderDate.Between("1995-5-1", "1995-6-1");
            items = OrderByCustomer.List(exp);
            WriteExpression(exp);
            TestContext.WriteLine("Count\tCompanyName");
            foreach (OrderByCustomer item in items)
            {
                TestContext.WriteLine("{0}\t{1}", item.Orders, item.CompanyName);
            }
        }
        [TestMethod]
        public void Commit()
        {
            Employee item;
            using (IConnectinContext cc = DBContext.Context)
            {
                cc.BeginTransaction();
                item = new Employee();
                item.FirstName = "tran1";
                item.LastName = "Commit";
                item.Save();
                item = new Employee();
                item.FirstName = "tran2";
                item.LastName = "Commit";
                item.Save();
                cc.Commit();
            }
        }
        [TestMethod]
        public void CommitError()
        {
            Employee item;
            using (IConnectinContext cc = DBContext.Context)
            {
                cc.BeginTransaction();
                item = new Employee();
                item.FirstName = "tran1";
                item.LastName = "CommitError";
                item.Save();
                item = new Employee();
                item.FirstName = "tran2";
                item.LastName = "CommitError";
                throw new Exception("Custom Error");
                item.Save();
                
                cc.Commit();
            }
        }
        [TestMethod]
        public void Rollback()
        {
            Employee item;
            using (IConnectinContext cc = DBContext.Context)
            {
                cc.BeginTransaction();
                item = new Employee();
                item.FirstName = "tran1";
                item.LastName = "Rollback";
                item.Save();
                item = new Employee();
                item.FirstName = "tran2";
                item.LastName = "Rollback";
                item.Save();
                cc.Rollback();
            }
        }
        [TestMethod]
        public void Like()
        {
            Expression exp = Customer.customerID.Like("a%");
            IList<Customer> items = Customer.List(exp);
            WriteExpression(exp);
            WriteCustomer(items);
            WriteSplit();
            exp = Customer.customerID.Like(new string[] {"a%","c%","d%" });
            
            items = Customer.List(exp);
            WriteExpression(exp);
            WriteCustomer(items);
            WriteSplit();
        }
        [TestMethod]
        public void Match()
        {
            Expression exp = Customer.customerID.Match("a");
            IList<Customer> items = Customer.List(exp);
            WriteExpression(exp);
            WriteCustomer(items);
            WriteSplit();
            exp = Customer.customerID.Match(new string[] { "a", "c", "d" });
            items = Customer.List(exp);
            WriteExpression(exp);
            WriteCustomer(items);
            WriteSplit();
        }
        private void WriteCustomer(IList<Customer> items)
        {
            foreach (Customer item in items)
            {
                TestContext.WriteLine("{0}\t{1}", item.CustomerID,item.CompanyName);
            }
        }
        private void WriteEmployee(IList<Employee> items)
        {
            foreach (Employee item in items)
            {
                TestContext.WriteLine("{0}\t{1}\t{2}", item.EmployeeID, item.FirstName, item.LastName);
            }
        }
        private void WriteExpression(Expression exp)
        {
            TestContext.WriteLine(exp.ToString());
            foreach (Command.Parameter item in exp.Parameters)
            {
                TestContext.WriteLine("\t{0}={1}", item.Name, item.Value);
            }
        }
        private void WriteOrder(IList<Order> orders)
        {
            WriteCount(orders.Count);
            foreach(Order item in orders)
            {
                WriteOrder(item);
            }
        }
        private void WriteSplit()

        {
            TestContext.WriteLine("-------------------------------------------------------------------------------");
        }
        private void WriteOrder(Order order)
        {
            TestContext.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}",order.OrderID,order.EmployeeID,order.CustomerID,order.OrderDate,order.RequiredDate);
        }
        private void WriteCount(int count)
        {
            TestContext.WriteLine("订单数量:{0}", count);
        }
    }
}

⌨️ 快捷键说明

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