Пример #1
0
        public void NullableFields()
        {
            Order order = Order.New();

            order.Customer      = Customer.New();
            order.Customer.Name = "blabla";

            order.Save();

            int orderId = order.OrderID;

            order = Order.Read(orderId);

            Assert.IsNull(order.SalesPersonID);

            order.SalesPerson      = SalesPerson.New();
            order.SalesPerson.Name = "Salesperson";

            order.Save();

            order = Order.Read(orderId);

            Assert.IsNotNull(order.SalesPersonID);

            order.SalesPersonID = null;

            order.Save();

            order = Order.Read(orderId);

            Assert.IsNull(order.SalesPersonID);
        }
Пример #2
0
        public void ManyToOne()
        {
            SetupTestData();

            Customer    customer    = new CSList <Customer>()[0];
            SalesPerson salesPerson = SalesPerson.New();

            salesPerson.Name = "Test";
            salesPerson.Save();

            Order order = Order.New();

            order.SalesPerson = null;
            order.Customer    = customer;

            order.Save();

            int id = order.OrderID;

            order = Order.Read(id);

            Assert.AreEqual(order.Customer, customer);

            order.SalesPerson = salesPerson;
            order.Save();

            order = Order.Read(id);

            Assert.AreEqual(salesPerson, order.SalesPerson);

            order.SalesPerson = null;
            order.Save();

            order = Order.Read(id);

            Assert.IsNull(order.SalesPerson);
            Assert.IsNull(order.SalesPersonID);
        }
Пример #3
0
        public void ComplexFilters()
        {
            PaymentMethod[] methods = new PaymentMethod[] { PaymentMethod.New(), PaymentMethod.New(), PaymentMethod.New(), PaymentMethod.New(), PaymentMethod.New() };

            methods[0].Name = "Bank";                   methods[0].MonthlyCost = 5;
            methods[1].Name = "Credit Card";    methods[1].MonthlyCost = 50;
            methods[2].Name = "PayPal";                 methods[2].MonthlyCost = 10;
            methods[3].Name = "Cash";                   methods[3].MonthlyCost = 20;
            methods[4].Name = "Bancontact";             methods[4].MonthlyCost = 100;


            foreach (PaymentMethod method in methods)
            {
                method.Save();
            }

            Order order = Order.New();

            order.Customer      = Customer.New();
            order.Customer.Name = "test";
            order.Customer.PaymentMethods.Add(methods[2]);
            order.Customer.PaymentMethods.Add(methods[4]);

            order.OrderItems.Add(OrderItem.New("test", 5, 200.0));
            order.OrderItems.Add(OrderItem.New("test", 3, 45.0));

            order.Save();

            order = Order.New();

            order.Customer      = Customer.New();
            order.Customer.Name = "blabla";

            order.OrderItems.Add(OrderItem.New("test", 15, 100.0));
            order.OrderItems.Add(OrderItem.New("test2", 6, 35.0));

            order.SalesPerson      = SalesPerson.New();
            order.SalesPerson.Name = "SalesPerson1";

            order.Save();


            Assert.AreEqual(1, new OrderCollection("count(OrderItems where Price > 100) = 1").Count);

            Assert.AreEqual(2, new CSList <OrderItem>("Order.Customer.Name = 'blabla'").Count);
            Assert.AreEqual(2, new CSList <OrderItem>("len(Order.Customer.Name) = 6").Count);
            Assert.AreEqual(2, new CSList <OrderItem>("len(Order.Customer.Name) = @len", new { len = 6 }).Count);
            //Assert.AreEqual(2, new CSList<OrderItem>("left(Order.Customer.Name,3) = 'bla'").Count);
//			Assert.AreEqual(1, new CSList<Order>("countdistinct(OrderItems.Description) = 1").Count);
//			Assert.AreEqual(1, new CSList<Order>("countdistinct(OrderItems.Description) = 2").Count);
            Assert.AreEqual(1, new OrderCollection("max(OrderItems.Price) = 200").Count);
            Assert.AreEqual(1, new OrderCollection("sum(OrderItems.Price) = 245").Count);
            Assert.AreEqual(2, new CSList <Order>("count(OrderItems) = 2").Count);
            Assert.AreEqual(2, new CSList <Order>("has(OrderItems)").Count);
            Assert.AreEqual(1, Customer.List("len(Name)=4").Count);
            //Assert.AreEqual(1, new CSList<Customer>("count(PaymentMethods)>0").Count);
            Assert.AreEqual(1, new CSList <Customer>("sum(PaymentMethods.MonthlyCost)=110").Count);
            Assert.AreEqual(1, new CSList <Customer>("sum(PaymentMethods.MonthlyCost where Name='PayPal')=10").Count);
//			Assert.AreEqual(1, new CSList<Customer>("count(PaymentMethods where PaymentMethodID = @MethodID) > 0", "@MethodID", methods[2].PaymentMethodID).Count);
//			Assert.AreEqual(1, new CSList<Customer>("count(PaymentMethods where Name = @MethodName) > 0", "@MethodName", methods[2].Name).Count);
            Assert.AreEqual(1, new CSList <Customer>("has(PaymentMethods)").Count);


            //Assert.AreEqual(200.0, (double)Customer.GetScalar("Orders.OrderItems.Price", CSAggregate.Max));
        }
Пример #4
0
        public void ManyToMany()
        {
            for (int i = 0; i < numIterations; i++)
            {
                DeleteData();

                Customer cust1 = Customer.New();
                Customer cust2 = Customer.New();
                Customer cust3 = Customer.New();

                cust1.Name = "Cust1";
                cust2.Name = "Cust2";
                cust3.Name = "Cust3";

                SalesPerson sp1 = SalesPerson.New();
                SalesPerson sp2 = SalesPerson.New();

                sp1.Name            = "SP1";
                sp1.SalesPersonType = SalesPersonType.External;

                sp2.Name            = "SP2";
                sp2.SalesPersonType = SalesPersonType.Internal;

                cust1.Save();
                cust2.Save();
                cust3.Save();
                sp1.Save();
                sp2.Save();

                sp1 = SalesPerson.Read(sp1.ID);

                Assert.AreEqual(SalesPersonType.External, sp1.SalesPersonType);

                Order order;

                order             = Order.New();
                order.SalesPerson = sp1;
                order.Customer    = cust1;
                order.Save();

                order             = Order.New();
                order.SalesPerson = sp2;
                order.Customer    = cust1;
                order.Save();

                order             = Order.New();
                order.SalesPerson = sp2;
                order.Customer    = cust2;
                order.Save();

                order             = Order.New();
                order.SalesPerson = sp1;
                order.Customer    = cust3;
                order.Save();

                cust1 = Customer.Read(cust1.CustomerID);
                cust2 = Customer.Read(cust2.CustomerID);
                cust3 = Customer.Read(cust3.CustomerID);

                Assert.AreEqual(2, cust1.SalesPeople.Count);
                Assert.AreEqual(1, cust2.SalesPeople.Count);
                Assert.AreEqual(1, cust3.SalesPeople.Count);

                Assert.AreEqual(2, cust1.SalesPeople.GetScalar("*", CSAggregate.Count));
                Assert.AreEqual(1, cust2.SalesPeople.GetScalar("*", CSAggregate.Count));
                Assert.AreEqual(1, cust3.SalesPeople.GetScalar("*", CSAggregate.Count));

                cust1 = Customer.Read(cust1.CustomerID);
                cust2 = Customer.Read(cust2.CustomerID);
                cust3 = Customer.Read(cust3.CustomerID);

                Assert.AreEqual(2, cust1.SalesPeople.Count);
                Assert.AreEqual(1, cust2.SalesPeople.Count);
                Assert.AreEqual(1, cust3.SalesPeople.Count);

                Assert.AreEqual(2, cust1.SalesPeople.GetScalar("*", CSAggregate.Count));
                Assert.AreEqual(1, cust2.SalesPeople.GetScalar("*", CSAggregate.Count));
                Assert.AreEqual(1, cust3.SalesPeople.GetScalar("*", CSAggregate.Count));
            }
        }