示例#1
0
        public void CompositeKey()
        {
            Customer customer = Customer.New();

            customer.Name = "Blabla";
            customer.Save();

            int customerID = customer.CustomerID;

            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();
            }

            CustomerPaymentMethodLink link = CustomerPaymentMethodLink.New();

            link.CustomerID      = customerID;
            link.PaymentMethodID = methods[0].PaymentMethodID;
            link.Save();

            link = CustomerPaymentMethodLink.Read(customerID, methods[0].PaymentMethodID);

            Assert.IsNotNull(link);
            Assert.AreEqual(customerID, link.CustomerID);
            Assert.AreEqual(methods[0].PaymentMethodID, link.PaymentMethodID);
        }
示例#2
0
        public void PureManyToMany()
        {
            DeleteData();

            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();
            }

            for (int i = 0; i < 10; i++)
            {
                Customer customer = Customer.New();

                customer.Name = "customer" + (i + 1);

                Random rnd      = new Random();
                int    nMethods = 0;

                for (int j = 0; j < 5 || nMethods < 1; j++)
                {
                    if ((rnd.Next() % 2) == 0)
                    {
                        Assert.IsNotNull(PaymentMethod.Read(methods[j % 5].PaymentMethodID));

                        customer.PaymentMethods.Add(methods[j % 5]);
                        nMethods++;
                    }
                }

                customer.Save();

                int customerID = customer.CustomerID;

                customer = Customer.Read(customerID);

                Assert.AreEqual(nMethods, customer.PaymentMethods.Count);

                customer.PaymentMethods.Remove(customer.PaymentMethods[0]);

                customer.Save();

                Assert.AreEqual(nMethods - 1, customer.PaymentMethods.Count);

                customer = Customer.Read(customerID);

                Assert.AreEqual(nMethods - 1, customer.PaymentMethods.Count);
            }
        }
示例#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));
        }