Esempio n. 1
0
        public void OrderByTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ContactList l;

                    Contact.Mary.Name = "Aaa";  // to make it temporarily first
                    Contact.Ed.Name   = "ZZZZ"; // to make it temporarily last

                    l = Contact.GetList(tran, SoodaWhereClause.Unrestricted, SoodaOrderBy.Ascending("Name"));

                    foreach (Contact c in l)
                    {
                        Console.WriteLine("c: {0}", c.Name);
                    }

                    Assert.IsTrue(l.IndexOf(Contact.Mary) == 0);
                    Assert.IsTrue(l.IndexOf(Contact.Ed) == l.Count - 1);
                    for (int i = 0; i < l.Count - 1; ++i)
                    {
                        if (String.CompareOrdinal((string)l[i].Name, (string)l[i + 1].Name) > 0)
                        {
                            Assert.Fail("Invalid sort!");
                        }
                    }
                    tran.Commit();
                }
            }
        }
Esempio n. 2
0
 public void Count()
 {
     using (new SoodaTransaction())
     {
         GroupList groups = Group.GetList(true, SoodaOrderBy.Ascending("Id"));
         Assert.AreEqual(2, groups.Count);
         Assert.AreEqual("Sooda.UnitTests.BaseObjects.ContactList", groups[0].GetLabel(false));
         Assert.AreEqual("Sooda.UnitTests.BaseObjects.ContactList", groups[1].GetLabel(false));
     }
 }
Esempio n. 3
0
 public void Int()
 {
     using (new SoodaTransaction())
     {
         RoleList roles = Role.GetList(true, SoodaOrderBy.Ascending("Id"));
         Assert.AreEqual(3, roles.Count);
         Assert.AreEqual("1", roles[0].GetLabel(false));
         Assert.AreEqual("2", roles[1].GetLabel(false));
         Assert.AreEqual("3", roles[2].GetLabel(false));
     }
 }
Esempio n. 4
0
 public void Basic()
 {
     using (new SoodaTransaction())
     {
         ContactList contacts = Contact.GetList(true, SoodaOrderBy.Ascending("ContactId"));
         Assert.AreEqual(7, contacts.Count);
         Assert.AreEqual("Mary Manager", contacts[0].GetLabel(false));
         Assert.AreEqual("Ed Employee", contacts[1].GetLabel(false));
         Assert.AreEqual("Eva Employee", contacts[2].GetLabel(false));
         Assert.AreEqual("Catie Customer", contacts[3].GetLabel(false));
         Assert.AreEqual("Caroline Customer", contacts[4].GetLabel(false));
         Assert.AreEqual("Chris Customer", contacts[5].GetLabel(false));
         Assert.AreEqual("Chuck Customer", contacts[6].GetLabel(false));
     }
 }
Esempio n. 5
0
 public void ReferencedObject()
 {
     using (new SoodaTransaction())
     {
         VehicleList vehicles = Vehicle.GetList(true, SoodaOrderBy.Ascending("Id"));
         Assert.AreEqual(9, vehicles.Count);
         Assert.AreEqual(string.Empty, vehicles[0].GetLabel(false));
         Assert.AreEqual("Mary Manager", vehicles[1].GetLabel(false));
         Assert.AreEqual("Ed Employee", vehicles[2].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[3].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[4].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[5].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[6].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[7].GetLabel(false));
         Assert.AreEqual(string.Empty, vehicles[8].GetLabel(false));
     }
 }
Esempio n. 6
0
        public void OrderByTest3()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ContactList l;

                    l = Contact.GetList(tran, new SoodaWhereClause("Name like '%customer'"), SoodaOrderBy.Ascending("Name"));

                    foreach (Contact c in l)
                    {
                        Console.WriteLine("c: {0}", c.Name);
                    }

                    Assert.IsTrue(l.IndexOf(Contact.Mary) == -1);
                    Assert.IsTrue(l.IndexOf(Contact.Ed) == -1);
                    for (int i = 0; i < l.Count - 1; ++i)
                    {
                        if (String.CompareOrdinal((string)l[i].Name, (string)l[i + 1].Name) > 0)
                        {
                            Assert.Fail("Invalid sort!");
                        }
                    }
                    tran.Commit();
                }
            }
        }
Esempio n. 7
0
    static void Main()
    {
        using (SoodaTransaction transaction = new SoodaTransaction())
        {
            Category c = Category.Load(1);

            // display all beverage products
            foreach (Product p in c.ProductsInThisCategory)
            {
                Console.WriteLine("Product: {0} category: {1} price: {2}", p.Name, p.Category.Name, p.UnitPrice);
            }

            Console.WriteLine("The total number of beverages: {0}", c.ProductsInThisCategory.Count);

            Product p2 = Product.Load(1);

            // remove a particular product from the collection
            p2.ProductsInThisCategory.Remove(p2);

            // the new p2.Category == null (the product is no longer in the collection)
            Console.WriteLine("New category of product #1 is null: {0}", p2.Category == null);

            // iterate over first 3 products (in no particular order)
            foreach (Product p in c.ProductsInThisCategory.SelectFirst(3))
            {
                // do something
            }

            // note that the order is fixed after the collection is first accessed. subsequent accesses
            // can rely on the fact.

            // iterate over last 3 products (in no particular order)
            foreach (Product p in c.ProductsInThisCategory.SelectLast(3))
            {
                // do something
            }

            // iterate over the specified range of products (in no particular order)
            foreach (Product p in c.ProductsInThisCategory.SelectRange(3, 10))
            {
                // do something
            }

            // iterate over the products sorted by name
            foreach (Product p in c.ProductsInThisCategory.Sort(SoodaOrderBy.Ascending("Name").GetComparer()))
            {
                // do something
            }

            // get the snapshot of this collection. Updates to c.ProductsInThisCategory (direct or indirect)
            // will not affect the snapshot
            ProductList snapshot = c.ProductsInThisCategory.GetSnapshot();

            foreach (Product p in snapshot)
            {
                // do something
            }

            // another way to iterate the collection. Note that ProductList returns strongly-typed instances
            // of Product

            for (int i = 0; i < snapshot.Count; ++i)
            {
                Product p3 = snapshot[i];
            }
        }
    }