Beispiel #1
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);
        }
Beispiel #2
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));
            }
        }