示例#1
0
        public void SimpleWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    int ch0 = tran.Statistics.CollectionCacheHits;
                    int cm0 = tran.Statistics.CollectionCacheMisses;

                    ContactList cl = Contact.GetList(ContactField.Active == true, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl.Count);

                    // we've had a miss
                    int ch1 = tran.Statistics.CollectionCacheHits;
                    int cm1 = tran.Statistics.CollectionCacheMisses;
                    Assert.AreEqual(ch0, ch1);
                    // Assert.AreNotEqual(cm0, cm1);

                    ContactList cl2 = Contact.GetList(ContactField.Active == true, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl2.Count);

                    // we've had a hit
                    int ch2 = tran.Statistics.CollectionCacheHits;
                    int cm2 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch1, ch2);
                    Assert.AreEqual(cm1, cm2);
                }
            }
        }
示例#2
0
        public void GetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact mary = Contact.Load(1);
                    //mary.Name = "Ala ma kota";

                    Contact ed = Contact.Load(2);
                    ed.PrimaryGroup = null;

                    ContactList list = Contact.GetList(tran, new SoodaWhereClause("PrimaryGroup.Manager.Name = 'Mary Manager'"), SoodaSnapshotOptions.Default);
                    Console.WriteLine("Len: {0}", list.Count);

                    SoodaObjectMultiFieldComparer comparer = new SoodaObjectMultiFieldComparer();

                    comparer.AddField(new string[] { "PrimaryGroup", "Name" }, SortOrder.Ascending);
                    comparer.AddField("LastSalary", SortOrder.Ascending);
                    comparer.AddField("Name", SortOrder.Descending);

                    foreach (Contact c in list.Sort(comparer).Filter(new SoodaObjectFilter(predicate1)))
                    {
                        Console.WriteLine("Member: {0} - {2} - {1}", c.Evaluate("PrimaryGroup.Name"), c.Name, c.LastSalary);
                    }
                    tran.Commit();
                }
            }
        }
示例#3
0
        public void Test5()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache hit
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);
                }
            }
        }
示例#4
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();
                }
            }
        }
示例#5
0
        public void EventsTest()
        {
            using (TestSqlDataSource ds = new TestSqlDataSource("default"))
            {
                ds.Open();
                int roleID;

                using (SoodaTransaction t = new SoodaTransaction())
                {
                    t.RegisterDataSource(ds);
                    Role r = new Role();
                    r.Name = "aaa";
                    Console.WriteLine("Precommitting...");
                    t.SaveObjectChanges();
                    Console.WriteLine("Comitting.");
                    t.Commit();
                    roleID = r.Id;
                    Assert.AreEqual(0, r.BeforeObjectInsertEventCounter);
                    Assert.AreEqual(2, r.AfterObjectInsertEventCounter);
                    Assert.AreEqual(-1, r.BeforeObjectUpdateEventCounter);
                    Assert.AreEqual(-1, r.AfterObjectUpdateEventCounter);

                    Assert.AreEqual(1, r.Second.BeforeObjectInsertEventCounter);
                    Assert.AreEqual(3, r.Second.AfterObjectInsertEventCounter);
                    Assert.AreEqual(-1, r.Second.BeforeObjectUpdateEventCounter);
                    Assert.AreEqual(-1, r.Second.AfterObjectUpdateEventCounter);
                }
            }
        }
示例#6
0
        public void InvalidateTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    ContactList cl = Contact.GetList(ContactField.Name == "Mary Manager", SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(1, cl.Count);

                    cl[0].Name = "modified";
                    tran.Commit();
                }

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

                    ContactList cl = Contact.GetList(ContactField.Name == "Mary Manager", SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(0, cl.Count);
                }
            }
        }
示例#7
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();
                }
            }
        }
示例#8
0
        public void SimpleWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    int ch0 = tran.Statistics.CollectionCacheHits;
                    int cm0 = tran.Statistics.CollectionCacheMisses;

                    ContactList cl = Contact.GetList(ContactField.Active == true, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl.Count);

                    // we've had a miss
                    int ch1 = tran.Statistics.CollectionCacheHits;
                    int cm1 = tran.Statistics.CollectionCacheMisses;
                    Assert.AreEqual(ch0, ch1);
                    // Assert.AreNotEqual(cm0, cm1);

                    ContactList cl2 = Contact.GetList(ContactField.Active == true, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl2.Count);

                    // we've had a hit
                    int ch2 = tran.Statistics.CollectionCacheHits;
                    int cm2 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch1, ch2);
                    Assert.AreEqual(cm1, cm2);
                }
            }
        }
示例#9
0
        public void InvalidateTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    ContactList cl = Contact.GetList(ContactField.Name == "Mary Manager", SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(1, cl.Count);

                    cl[0].Name = "modified";
                    tran.Commit();
                }

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

                    ContactList cl = Contact.GetList(ContactField.Name == "Mary Manager", SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(0, cl.Count);
                }
            }
        }
示例#10
0
        public void MultiTableDelete()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ExtendedBike.Load(10).MarkForDelete();
                    tran.Commit();
                }

                try
                {
                    using (SoodaTransaction tran = new SoodaTransaction())
                    {
                        tran.RegisterDataSource(testDataSource);
                        ExtendedBike b = ExtendedBike.Load(10);
                    }
                    Assert.Fail("Object not deleted!");
                }
                catch (SoodaObjectNotFoundException)
                {
                    Assert.IsTrue(true);
                }
            }
        }
示例#11
0
        public void MultiTableDelete()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ExtendedBike.Load(10).MarkForDelete();
                    tran.Commit();
                }

                try
                {
                    using (SoodaTransaction tran = new SoodaTransaction())
                    {
                        tran.RegisterDataSource(testDataSource);
                        ExtendedBike b = ExtendedBike.Load(10);
                    }
                    Assert.Fail("Object not deleted!");
                }
                catch (SoodaObjectNotFoundException)
                {
                    Assert.IsTrue(true);
                }
            }
        }
示例#12
0
        public void EventsTest()
        {
            using (TestSqlDataSource ds = new TestSqlDataSource("default"))
            {
                ds.Open();
                int roleID;

                using (SoodaTransaction t = new SoodaTransaction())
                {
                    t.RegisterDataSource(ds);
                    Role r = new Role();
                    r.Name = "aaa";
                    Console.WriteLine("Precommitting...");
                    t.SaveObjectChanges();
                    Console.WriteLine("Comitting.");
                    t.Commit();
                    roleID = r.Id;
                    Assert.AreEqual(0, r.BeforeObjectInsertEventCounter);
                    Assert.AreEqual(2, r.AfterObjectInsertEventCounter);
                    Assert.AreEqual(-1, r.BeforeObjectUpdateEventCounter);
                    Assert.AreEqual(-1, r.AfterObjectUpdateEventCounter);

                    Assert.AreEqual(1, r.Second.BeforeObjectInsertEventCounter);
                    Assert.AreEqual(3, r.Second.AfterObjectInsertEventCounter);
                    Assert.AreEqual(-1, r.Second.BeforeObjectUpdateEventCounter);
                    Assert.AreEqual(-1, r.Second.AfterObjectUpdateEventCounter);
                }
            }
        }
示例#13
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();
                }
            }
        }
        public void CollectionNtoNTest()
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Assert.IsTrue(!Contact.Mary.Roles.Contains(Role.Customer));

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("00 serialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer));
                    Contact.Mary.Roles.Remove(Role.Customer);
                    Assert.IsTrue(!Contact.Mary.Roles.Contains(Role.Customer));
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer));

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("Before serialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                }
                Console.WriteLine("serialized: {0}", serialized);

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                    if (serialized == serialized2)
                    {
                        Console.WriteLine("Serialization is stable");
                    }
                    else
                    {
                        Console.WriteLine("Serialized again as\n{0}", serialized2);
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("After deserialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer), "Deserialization preserves N-N relation membersips");
                    tran.Commit();
                }
            }
        }
示例#15
0
        public void Test2()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    // create new uncommitted object
                    Contact nc = new Contact();

                    Console.WriteLine("Precommitting...");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId));

                    // we get one record
                    Assert.AreEqual(1, cl.Count, "#1");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl2 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(0, cl2.Count, "#2");

                    nc.Type = ContactType.Customer;

                    // force precommit
                    ContactList cl3 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(1, cl3.Count, "#3");

                    nc.Type = ContactType.Employee;

                    ContactList cl4 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(0, cl4.Count, "#4");

                    // tran.Commit();
                }
            }
        }
示例#16
0
        public void SimpleTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Console.WriteLine(MultiKey.Load(1, 1).Value);
                    Console.WriteLine(MultiKey.Load(1, 1).Value);
                }
            }
        }
示例#17
0
        public void GetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    foreach (MultiKey mk in MultiKey.GetList(SoodaWhereClause.Unrestricted))
                    {
                        Console.WriteLine("mk: {0},{1} = {2}", mk.Contact, mk.Group, mk.Value);
                    }
                }
            }
        }
示例#18
0
        public void MultiTableGetListTestWithWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    foreach (MultiKey mk in MultiKey.GetList(new SoodaWhereClause("Contact = {0}", 1)))
                    {
                        Console.WriteLine("mk: {0},{1} = {2},{3},{4}", mk.Contact, mk.Group, mk.Value, mk.Value2, mk.Value3);
                    }
                }
            }
        }
示例#19
0
        public void GetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    foreach (MultiKey mk in MultiKey.GetList(SoodaWhereClause.Unrestricted))
                    {
                        Console.WriteLine("mk: {0},{1} = {2}", mk.Contact, mk.Group, mk.Value);
                    }
                }
            }
        }
示例#20
0
        public void AllDataTypesMinTest()
        {
            string ser;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    AllDataTypes adt = new AllDataTypes();

                    // the range for decimal doesn't match the range in SQL

                    adt.DateVal    = DateTime.Now;
                    adt.IntVal     = Int32.MinValue;
                    adt.Int64Val   = Int64.MinValue;
                    adt.DecimalVal = -1000000.12345m;
                    adt.DoubleVal  = Double.MinValue;
                    adt.FloatVal   = Single.MinValue;
                    adt.StringVal  = "test 12345";
                    adt.BoolVal    = true;

                    adt.NnDateVal    = DateTime.Now;
                    adt.NnIntVal     = Int32.MinValue;
                    adt.NnInt64Val   = Int64.MinValue;
                    adt.NnDecimalVal = -1000000.12345m;
                    adt.NnDoubleVal  = Double.MinValue;
                    adt.NnFloatVal   = Single.MinValue;
                    adt.NnStringVal  = "test 12345";
                    adt.NnBoolVal    = true;

                    ser = tran.Serialize();

                    Console.WriteLine("ser: {0}", ser);

                    tran.Deserialize(ser);
                    Assert.AreEqual(ser, tran.Serialize());
                    Console.WriteLine("Serialization is stable...");
                    tran.Commit();
                }
            }
        }
示例#21
0
        public void DecimalTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Assert.AreEqual(123.1234567890m, (decimal)Contact.Mary.LastSalary);
                    Assert.AreEqual(234.0000000000m, (decimal)Contact.Ed.LastSalary);
                    Assert.AreEqual(345.0000000000m, (decimal)Contact.Eva.LastSalary);

                    Console.WriteLine("Type: {0}", Contact.Eva.Type);
                    Contact.Eva.LastSalary = (Decimal)Contact.Mary.LastSalary * 2;
                    tran.Commit();
                }
            }
        }
示例#22
0
        public void BugTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact c = new Contact();
                    c.Name = "a";
                    c.Type = ContactType.Customer;
                    GroupList list = Group.GetList(SoodaWhereClause.Unrestricted);
                    c.Name = "B";
                    tran.Commit();
                }
            }
        }
        public void MiniTest()
        {
            string serialized;
            int    id;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact c1;
                    c1         = new Contact();
                    c1.Name    = "Nancy Newcomer";
                    c1.Active  = true;
                    c1.Type    = ContactType.Employee;
                    id         = c1.ContactId;
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                }
            }
            Console.WriteLine("serialized: {0}", serialized);

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Console.WriteLine("*** Deserializing");
                    tran.Deserialize(serialized);
                    Console.WriteLine("*** Deserialized.");

                    Console.WriteLine("*** type: {0}", Contact.GetRef(id).Type);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);

                    Assert.AreEqual(serialized, serialized2);
                    // Console.WriteLine("s: {0}", serialized);
                }
            }
        }
示例#24
0
        public void BugTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact c = new Contact();
                    c.Name = "a";
                    c.Type = ContactType.Customer;
                    GroupList list = Group.GetList(SoodaWhereClause.Unrestricted);
                    c.Name = "B";
                    tran.Commit();
                }
            }
        }
示例#25
0
        public void Test6()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                // make sure it's in cache
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    // add role
                    Contact.Eva.Roles.Add(Role.Customer);

                    // force precommit
                    tran.SaveObjectChanges();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache miss
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheMisses);
                    tran.Commit();
                }
                // make sure it's NOT in cache
                Assert.IsNull(myCache.LoadCollection("ContactToRole where Role = 1"));
            }
        }
示例#26
0
        public void AllDataTypesMaxTest()
        {
            string ser;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    AllDataTypes adt = new AllDataTypes();

                    adt.DateVal = DateTime.Now;
                    adt.IntVal = Int32.MaxValue;
                    adt.Int64Val = Int64.MaxValue;
                    adt.DecimalVal = 1000000.12345m;
                    adt.DoubleVal = Double.MaxValue;
                    adt.FloatVal = Single.MaxValue;
                    adt.StringVal = "test 12345";
                    adt.BoolVal = true;

                    adt.NnDateVal = DateTime.Now;
                    adt.NnIntVal = Int32.MaxValue;
                    adt.NnInt64Val = Int64.MaxValue;
                    adt.NnDecimalVal = 1000000.12345m;
                    adt.NnDoubleVal = Double.MaxValue;
                    adt.NnFloatVal = Single.MaxValue;
                    adt.NnStringVal = "test 12345";
                    adt.NnBoolVal = true;

                    ser = tran.Serialize();

                    Console.WriteLine("ser: {0}", ser);

                    tran.Deserialize(ser);
                    Assert.AreEqual(ser, tran.Serialize());
                    Console.WriteLine("Serialization is stable...");
                    tran.Commit();
                }
            }
        }
示例#27
0
        public void InsertTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk = new MultiKey();
                    mk.Contact = 99;
                    mk.Group = 123;
                    mk.Value = 44;
                    mk.Value2 = 55;
                    mk.Value3 = 66;
                    Console.WriteLine(tran.Serialize());
                    tran.Commit();
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk2 = MultiKey.Load(99, 123);
                    Assert.AreEqual(44, mk2.Value);
                    Assert.AreEqual(55, mk2.Value2);
                    Assert.AreEqual(66, mk2.Value3);
                    mk2.Value2 = 99;
                    tran.Commit();
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk2 = MultiKey.Load(99, 123);
                    Assert.AreEqual(44, mk2.Value);
                    Assert.AreEqual(99, mk2.Value2);
                    Assert.AreEqual(66, mk2.Value3);
                    tran.Commit();
                }
            }
        }
示例#28
0
        public void Test1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    // create new uncommitted object
                    Contact nc = new Contact();

                    Console.WriteLine("Precommitting...");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    // update name

                    Console.WriteLine("Precommitting again...");
                    nc.Name = "name1";

                    // force precommit again
                    cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    Console.WriteLine("Precommitting again (2)...");

                    nc.Type = ContactType.Customer;
                    // force precommit again
                    cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    // this should do nothing

                    Console.WriteLine("Comitting...");
                    tran.Commit();
                }
            }
        }
示例#29
0
        public void InsertTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk = new MultiKey();
                    mk.Contact = 99;
                    mk.Group   = 123;
                    mk.Value   = 44;
                    mk.Value2  = 55;
                    mk.Value3  = 66;
                    Console.WriteLine(tran.Serialize());
                    tran.Commit();
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk2 = MultiKey.Load(99, 123);
                    Assert.AreEqual(44, mk2.Value);
                    Assert.AreEqual(55, mk2.Value2);
                    Assert.AreEqual(66, mk2.Value3);
                    mk2.Value2 = 99;
                    tran.Commit();
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    MultiKey mk2 = MultiKey.Load(99, 123);
                    Assert.AreEqual(44, mk2.Value);
                    Assert.AreEqual(99, mk2.Value2);
                    Assert.AreEqual(66, mk2.Value3);
                    tran.Commit();
                }
            }
        }
示例#30
0
        public void Test1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    // create new uncommitted object
                    Contact nc = new Contact();

                    Console.WriteLine("Precommitting...");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    // update name

                    Console.WriteLine("Precommitting again...");
                    nc.Name = "name1";

                    // force precommit again
                    cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    Console.WriteLine("Precommitting again (2)...");

                    nc.Type = ContactType.Customer;
                    // force precommit again
                    cl = Contact.GetList(SoodaWhereClause.Unrestricted);

                    // this should do nothing

                    Console.WriteLine("Comitting...");
                    tran.Commit();
                }
            }
        }
        public void CollectionNtoNSharedTest()
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Role.Customer.Members.Contains(Contact.Mary));
                    Contact.Mary.Roles.Remove(Role.Customer);
                    Assert.IsTrue(!Role.Customer.Members.Contains(Contact.Mary));

                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                }
                Console.WriteLine("serialized: {0}", serialized);

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                    if (serialized == serialized2)
                    {
                        Console.WriteLine("Serialization is stable");
                    }
                    else
                    {
                        Console.WriteLine("Serialized again as\n{0}", serialized2);
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");

                    tran.Commit();
                }
            }
        }
示例#32
0
        //[Test]
        public void AllDataTypesNotNullDefaults()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    AllDataTypes adt = new AllDataTypes();

                    Assert.AreEqual(adt.NnDateVal, DateTime.MinValue);
                    Assert.AreEqual(adt.NnIntVal, (int)0);
                    Assert.AreEqual(adt.NnInt64Val, (long)0);
                    Assert.AreEqual(adt.NnDecimalVal, (decimal)0);
                    Assert.AreEqual(adt.NnDoubleVal, (double)0);
                    Assert.AreEqual(adt.NnFloatVal, (float)0);
                    Assert.AreEqual(adt.NnStringVal, String.Empty);
                    Assert.AreEqual(adt.NnBoolVal, false);
                }
            }
        }
        public void CollectionNtoNSharedTest()
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Role.Customer.Members.Contains(Contact.Mary));
                    Contact.Mary.Roles.Remove(Role.Customer);
                    Assert.IsTrue(!Role.Customer.Members.Contains(Contact.Mary));

                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                }
                Console.WriteLine("serialized: {0}", serialized);

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                    if (serialized == serialized2)
                    {
                        Console.WriteLine("Serialization is stable");
                    }
                    else
                    {
                        Console.WriteLine("Serialized again as\n{0}", serialized2);
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");

                    tran.Commit();
                }
            }
        }
示例#34
0
        public void TriggerBug1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact c = new Contact();
                    c.Name = "a";
                    c.Type = ContactType.Customer;

                    Contact.GetList(true);
                    Contact.GetList(true);
                    Contact.GetList(true);
                    Contact.GetList(true);
                    tran.Commit();
                    Console.WriteLine("a: {0}", c.AfterInsertCalled);
                }
            }
        }
示例#35
0
        public void TriggerBug1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact c = new Contact();
                    c.Name = "a";
                    c.Type = ContactType.Customer;

                    Contact.GetList(true);
                    Contact.GetList(true);
                    Contact.GetList(true);
                    Contact.GetList(true);
                    tran.Commit();
                    Console.WriteLine("a: {0}", c.AfterInsertCalled);
                }
            }
        }
        public void Test10()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string      ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1  = Vehicle.GetList(true);

                    string   ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2  = Bike.GetList(true);

                    string   ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3  = Bike.GetList(false);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // ck2 is not evicted because vehicle[1] is not a bike
                    // ck3 is not evicted because it contains zero objects

                    Assert.IsNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
        public void Test10()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1 = Vehicle.GetList(true);

                    string ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2 = Bike.GetList(true);

                    string ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3 = Bike.GetList(false);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // ck2 is not evicted because vehicle[1] is not a bike
                    // ck3 is not evicted because it contains zero objects

                    Assert.IsNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
        public void Test11()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache         = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string      ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1  = Vehicle.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string   ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2  = Bike.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string   ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3  = Bike.GetList(false, SoodaSnapshotOptions.KeysOnly);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // nothing is evicted from collection cache because we requested KeysOnly

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
示例#39
0
        public void Test1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();

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

                    Console.WriteLine(Contact.Mary.Name);
                    Console.WriteLine(Contact.Mary.Type.Description);

                    foreach (Contact c in Contact.Mary.PrimaryGroup.Members)
                    {
                        Console.WriteLine(c.Name);
                    }
                    tran.Commit();
                }

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

                    foreach (Contact c in Contact.Mary.PrimaryGroup.Members)
                    {
                        Console.WriteLine(c.Name);
                    }

                    Console.WriteLine(Contact.Mary.Name);
                    Console.WriteLine(Contact.Mary.Type.Description);
                    tran.Commit();
                }
            }
        }
示例#40
0
        public void Test1()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();

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

                    Console.WriteLine(Contact.Mary.Name);
                    Console.WriteLine(Contact.Mary.Type.Description);

                    foreach (Contact c in Contact.Mary.PrimaryGroup.Members)
                    {
                        Console.WriteLine(c.Name);
                    }
                    tran.Commit();
                }

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

                    foreach (Contact c in Contact.Mary.PrimaryGroup.Members)
                    {
                        Console.WriteLine(c.Name);
                    }

                    Console.WriteLine(Contact.Mary.Name);
                    Console.WriteLine(Contact.Mary.Type.Description);
                    tran.Commit();
                }
            }
        }
示例#41
0
        public void DoGetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ContactTypeList ctl = ContactType.GetList(tran, SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Default);
                    foreach (ContactType ct in ctl)
                    {
                        Console.Out.WriteLine("ContactType[{0}]", ct.GetPrimaryKeyValue());
                    }

                    RoleList rl = Role.GetList(tran, SoodaWhereClause.Unrestricted);
                    foreach (Role r in rl)
                    {
                        Console.Out.WriteLine("Role[{0}]", r.GetPrimaryKeyValue());
                    }
                    tran.Commit();
                }
            }
        }
示例#42
0
        public void DoGetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ContactTypeList ctl = ContactType.GetList(tran, SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Default);
                    foreach (ContactType ct in ctl)
                    {
                        Console.Out.WriteLine("ContactType[{0}]", ct.GetPrimaryKeyValue());
                    }

                    RoleList rl = Role.GetList(tran, SoodaWhereClause.Unrestricted);
                    foreach (Role r in rl)
                    {
                        Console.Out.WriteLine("Role[{0}]", r.GetPrimaryKeyValue());
                    }
                    tran.Commit();
                }
            }
        }
示例#43
0
        public void UnrestrictedWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    int ch0 = tran.Statistics.CollectionCacheHits;
                    int cm0 = tran.Statistics.CollectionCacheMisses;

                    ContactList cl = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl.Count);

                    // we've had a miss
                    int ch1 = tran.Statistics.CollectionCacheHits;
                    int cm1 = tran.Statistics.CollectionCacheMisses;
                    Assert.AreEqual(ch0, ch1);
                    // Assert.AreNotEqual(cm0, cm1);

                    ContactList cl2 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl2.Count);

                    // we've had a hit
                    int ch2 = tran.Statistics.CollectionCacheHits;
                    int cm2 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch1, ch2);
                    Assert.AreEqual(cm1, cm2);

                    ContactList cl3 = Contact.GetList(SoodaWhereClause.Unrestricted, 3, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(3, cl3.Count);

                    // Dump("after top no sort", cl3);

                    // we've had a hit
                    int ch3 = tran.Statistics.CollectionCacheHits;
                    int cm3 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch2, ch3);
                    Assert.AreEqual(cm1, cm3);

                    ContactList cl4 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaOrderBy.Descending("Name"), SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl4.Count);

                    Assert.AreSame(cl4[0], Contact.Mary);
                    // Dump("after sort, no top", cl4);

                    // we've had a hit
                    int ch4 = tran.Statistics.CollectionCacheHits;
                    int cm4 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch3, ch4);
                    Assert.AreEqual(cm1, cm4);

                    ContactList cl5 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaOrderBy.Descending("LastSalary"), 4, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(4, cl5.Count);

                    Assert.AreSame(cl5[0], Contact.Eva);
                    // Dump("after sort by salary, with top", cl5);

                    // we've had a hit
                    int ch5 = tran.Statistics.CollectionCacheHits;
                    int cm5 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch4, ch5);
                    Assert.AreEqual(cm1, cm5);
                }
            }
        }
示例#44
0
        public void UnrestrictedWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    int ch0 = tran.Statistics.CollectionCacheHits;
                    int cm0 = tran.Statistics.CollectionCacheMisses;

                    ContactList cl = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl.Count);

                    // we've had a miss
                    int ch1 = tran.Statistics.CollectionCacheHits;
                    int cm1 = tran.Statistics.CollectionCacheMisses;
                    Assert.AreEqual(ch0, ch1);
                    // Assert.AreNotEqual(cm0, cm1);

                    ContactList cl2 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl2.Count);

                    // we've had a hit
                    int ch2 = tran.Statistics.CollectionCacheHits;
                    int cm2 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch1, ch2);
                    Assert.AreEqual(cm1, cm2);

                    ContactList cl3 = Contact.GetList(SoodaWhereClause.Unrestricted, 3, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(3, cl3.Count);

                    // Dump("after top no sort", cl3);

                    // we've had a hit
                    int ch3 = tran.Statistics.CollectionCacheHits;
                    int cm3 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch2, ch3);
                    Assert.AreEqual(cm1, cm3);

                    ContactList cl4 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaOrderBy.Descending("Name"), SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(7, cl4.Count);

                    Assert.AreSame(cl4[0], Contact.Mary);
                    // Dump("after sort, no top", cl4);

                    // we've had a hit
                    int ch4 = tran.Statistics.CollectionCacheHits;
                    int cm4 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch3, ch4);
                    Assert.AreEqual(cm1, cm4);

                    ContactList cl5 = Contact.GetList(SoodaWhereClause.Unrestricted, SoodaOrderBy.Descending("LastSalary"), 4, SoodaSnapshotOptions.Cache);
                    Assert.AreEqual(4, cl5.Count);

                    Assert.AreSame(cl5[0], Contact.Eva);
                    // Dump("after sort by salary, with top", cl5);

                    // we've had a hit
                    int ch5 = tran.Statistics.CollectionCacheHits;
                    int cm5 = tran.Statistics.CollectionCacheMisses;
                    // Assert.AreNotEqual(ch4, ch5);
                    Assert.AreEqual(cm1, cm5);
                }
            }
        }
示例#45
0
        public void GetListTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Contact mary = Contact.Load(1);
                    //mary.Name = "Ala ma kota";

                    Contact ed = Contact.Load(2);
                    ed.PrimaryGroup = null;

                    ContactList list = Contact.GetList(tran, new SoodaWhereClause("PrimaryGroup.Manager.Name = 'Mary Manager'"), SoodaSnapshotOptions.Default);
                    Console.WriteLine("Len: {0}", list.Count);

                    SoodaObjectMultiFieldComparer comparer = new SoodaObjectMultiFieldComparer();

                    comparer.AddField(new string[] { "PrimaryGroup", "Name" }, SortOrder.Ascending);
                    comparer.AddField("LastSalary", SortOrder.Ascending);
                    comparer.AddField("Name", SortOrder.Descending);

                    foreach (Contact c in list.Sort(comparer).Filter(new SoodaObjectFilter(predicate1)))
                    {
                        Console.WriteLine("Member: {0} - {2} - {1}", c.Evaluate("PrimaryGroup.Name"), c.Name, c.LastSalary);
                    }
                    tran.Commit();
                }
            }
        }
示例#46
0
        public void LongTest()
        {
            // run multiple Sooda transactions in a single SQL transaction
            // this is achieved by a hacked SqlDataSource which ignores
            // Close(), Commit() requests

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                int ebKey;
                int bikeKey;
                int gvKey;

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

                    Vehicle v = new Bike();
                    Assert.AreEqual(v.Type, 2);
                    ((Bike)v).TwoWheels = 1;

                    ExtendedBike eb = new ExtendedBike();
                    Assert.AreEqual(eb.Type, 7);
                    eb.TwoWheels        = 1;
                    eb.ExtendedBikeInfo = "some info here";
                    ebKey   = eb.Id;
                    bikeKey = v.Id;

                    Contact.Mary.Bikes.Add((Bike)v);
                    Contact.Mary.Bikes.Add(eb);

                    Contact.Mary.Vehicles.Add(v);
                    Contact.Mary.Vehicles.Add(eb);

                    v     = new Bike();
                    gvKey = v.Id;
                    Contact.Mary.Vehicles.Add(v);

                    tran.Commit();
                }

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

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(Vehicle.GetRef(gvKey)));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v2));

                    Contact.Mary.Vehicles.Remove(v1);
                    Contact.Mary.Vehicles.Remove(v2);

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    Contact.Mary.Bikes.Remove((Bike)v1);

                    try
                    {
                        Vehicle v3 = ExtendedBike.GetRef(bikeKey);
                        Assert.Fail("Vehicle v3 = ExtendedBike.GetRef(bikeKey); should fail here.");
                    }
                    catch (SoodaObjectNotFoundException)
                    {
                        Console.WriteLine("Got exception as expected");
                    }

                    tran.Commit();
                }
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(!Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    tran.Commit();
                }
            }
        }
示例#47
0
        public void Test6()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                // make sure it's in cache
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    // add role
                    Contact.Eva.Roles.Add(Role.Customer);

                    // force precommit
                    tran.SaveObjectChanges();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache miss
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheMisses);
                    tran.Commit();
                }
                // make sure it's NOT in cache
                Assert.IsNull(myCache.LoadCollection("ContactToRole where Role = 1"));
            }
        }
示例#48
0
        public void SimpleTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Console.WriteLine(MultiKey.Load(1, 1).Value);
                    Console.WriteLine(MultiKey.Load(1, 1).Value);
                }
            }
        }
示例#49
0
        public void DecimalTest()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Assert.AreEqual(123.1234567890m, (decimal)Contact.Mary.LastSalary);
                    Assert.AreEqual(234.0000000000m, (decimal)Contact.Ed.LastSalary);
                    Assert.AreEqual(345.0000000000m, (decimal)Contact.Eva.LastSalary);

                    Console.WriteLine("Type: {0}", Contact.Eva.Type);
                    Contact.Eva.LastSalary = (Decimal)Contact.Mary.LastSalary * 2;
                    tran.Commit();
                }
            }
        }
示例#50
0
        public void LongTest()
        {
            // run multiple Sooda transactions in a single SQL transaction
            // this is achieved by a hacked SqlDataSource which ignores
            // Close(), Commit() requests

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                int ebKey;
                int bikeKey;
                int gvKey;

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

                    Vehicle v = new Bike();
                    Assert.AreEqual(v.Type, 2);
                    ((Bike)v).TwoWheels = 1;

                    ExtendedBike eb = new ExtendedBike();
                    Assert.AreEqual(eb.Type, 7);
                    eb.TwoWheels = 1;
                    eb.ExtendedBikeInfo = "some info here";
                    ebKey = eb.Id;
                    bikeKey = v.Id;

                    Contact.Mary.Bikes.Add((Bike)v);
                    Contact.Mary.Bikes.Add(eb);

                    Contact.Mary.Vehicles.Add(v);
                    Contact.Mary.Vehicles.Add(eb);

                    v = new Bike();
                    gvKey = v.Id;
                    Contact.Mary.Vehicles.Add(v);

                    tran.Commit();
                }

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

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(Vehicle.GetRef(gvKey)));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v2));

                    Contact.Mary.Vehicles.Remove(v1);
                    Contact.Mary.Vehicles.Remove(v2);

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    Contact.Mary.Bikes.Remove((Bike)v1);

                    try
                    {
                        Vehicle v3 = ExtendedBike.GetRef(bikeKey);
                        Assert.Fail("Vehicle v3 = ExtendedBike.GetRef(bikeKey); should fail here.");
                    }
                    catch (SoodaObjectNotFoundException)
                    {
                        Console.WriteLine("Got exception as expected");
                    }

                    tran.Commit();
                }
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(!Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    tran.Commit();
                }
            }
        }
        public void Collection1toNTest(bool quiet)
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact c1;
                    Group   g = Group.Load(10);

                    Assert.AreEqual((string)g.Manager.Name, "Mary Manager");
                    Assert.AreEqual(g.Members.Count, 4);
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(53)));
                    Console.WriteLine("oldgroup: {0}", Contact.GetRef(53).PrimaryGroup);
                    g.Members.Remove(Contact.GetRef(53));
                    Console.WriteLine("newgroup: {0}", Contact.GetRef(53).PrimaryGroup);
                    Assert.AreEqual(g.Members.Count, 3);
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));

                    g.Members.Add(c1 = new Contact());
                    c1.Name          = "Nancy Newcomer";
                    c1.Active        = true;
                    c1.Type          = ContactType.Employee;
                    Assert.AreEqual(g.Members.Count, 4);

                    //Console.WriteLine(ContactType.Employee.GetPrimaryKeyValue());
                    //Console.WriteLine(ContactType.Employee.Code);
                    //Console.WriteLine(ContactType.Employee.Description);

                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    int times = 0;
                    foreach (Contact c in g.Members)
                    {
                        if (!quiet)
                        {
                            Console.WriteLine("Got {0} [{1}]", c.Name, c.ContactId);
                        }
                        times++;
                        Assert.IsTrue(
                            c == Contact.GetRef(51) ||
                            c == Contact.GetRef(1) ||
                            c == c1 ||
                            c == Contact.GetRef(2));
                    }
                    ;
                    Assert.AreEqual(times, 4, "foreach() loop gets called 4 times");
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    Assert.IsTrue(g.Members.Contains(c1));
                    Assert.AreEqual(g.Members.Count, 4);

                    foreach (Contact c in g.Members)
                    {
                        if (!quiet)
                        {
                            Console.WriteLine("before serialization, member: {0}", c.Name);
                        }
                    }
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                    //serialized = tran.Serialize();
                    if (!quiet)
                    {
                        Console.WriteLine("Serialized as\n{0}", serialized);
                    }
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);

                    Console.WriteLine(ContactType.Employee.Description);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                    //string serialized2 = tran.Serialize();
                    if (serialized == serialized2)
                    {
                        if (!quiet)
                        {
                            Console.WriteLine("Serialization is stable\n{0}", serialized);
                        }
                    }
                    else
                    {
                        if (!quiet)
                        {
                            Console.WriteLine("Serialized again as\n{0}", serialized2);
                        }
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");


                    Group g = Group.Load(10);

                    foreach (Contact c in g.Members)
                    {
                        //if (!quiet)
                        Console.WriteLine("after deserialization, member: {0}", c.Name);
                    }
                    Assert.AreEqual("Mary Manager", g.Manager.Name);
                    Assert.AreEqual(4, g.Members.Count);
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));

                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    int times = 0;
                    foreach (Contact c in g.Members)
                    {
                        times++;
                        Assert.IsTrue(
                            c == Contact.GetRef(51) ||
                            c == Contact.GetRef(1) ||
                            (string)c.Name == "Nancy Newcomer" ||
                            c == Contact.GetRef(2));
                    }
                    ;
                    Assert.AreEqual(times, 4, "foreach() loop gets called 4 times");
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    Assert.AreEqual(g.Members.Count, 4);
                    tran.Commit();
                }
            }
        }
示例#52
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();
                }
            }
        }
        public void Test11()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    string ck1 = SoodaCache.GetCollectionKey("Vehicle", new SoodaWhereClause(true));
                    VehicleList c1 = Vehicle.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string ck2 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(true));
                    BikeList c2 = Bike.GetList(true, SoodaSnapshotOptions.KeysOnly);

                    string ck3 = SoodaCache.GetCollectionKey("Bike", new SoodaWhereClause(false));
                    BikeList c3 = Bike.GetList(false, SoodaSnapshotOptions.KeysOnly);

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));

                    myCache.Evict("Vehicle", 1);

                    // nothing is evicted from collection cache because we requested KeysOnly

                    Assert.IsNotNull(myCache.LoadCollection(ck1));
                    Assert.IsNotNull(myCache.LoadCollection(ck2));
                    Assert.IsNotNull(myCache.LoadCollection(ck3));
                }
            }
        }
        public void CollectionNtoNTest()
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Assert.IsTrue(!Contact.Mary.Roles.Contains(Role.Customer));

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("00 serialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer));
                    Contact.Mary.Roles.Remove(Role.Customer);
                    Assert.IsTrue(!Contact.Mary.Roles.Contains(Role.Customer));
                    Contact.Mary.Roles.Add(Role.Customer);
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer));

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("Before serialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                }
                Console.WriteLine("serialized: {0}", serialized);

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects);
                    if (serialized == serialized2)
                    {
                        Console.WriteLine("Serialization is stable");
                    }
                    else
                    {
                        Console.WriteLine("Serialized again as\n{0}", serialized2);
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");

                    foreach (SoodaObject r in Contact.Mary.Roles)
                    {
                        Console.WriteLine("After deserialization mary has role: {0}", r.GetObjectKeyString());
                    }
                    Assert.IsTrue(Contact.Mary.Roles.Contains(Role.Customer), "Deserialization preserves N-N relation membersips");
                    tran.Commit();
                }
            }
        }
示例#55
0
        public void Test2()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();
                SoodaCache.DefaultCache.Clear();;

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

                    // create new uncommitted object
                    Contact nc = new Contact();

                    Console.WriteLine("Precommitting...");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId));

                    // we get one record
                    Assert.AreEqual(1, cl.Count, "#1");

                    // force precommit
                    // the 'type' field precommits as 'Customer'
                    ContactList cl2 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(0, cl2.Count, "#2");

                    nc.Type = ContactType.Customer;

                    // force precommit
                    ContactList cl3 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(1, cl3.Count, "#3");

                    nc.Type = ContactType.Employee;

                    ContactList cl4 = Contact.GetList(new SoodaWhereClause("Type={0} and ContactId={1}", "Customer", nc.ContactId), SoodaSnapshotOptions.VerifyAfterLoad);

                    // we use SoodaSnapshotOptions.Verify to check in-memory
                    // values after the load
                    Assert.AreEqual(0, cl4.Count, "#4");

                    // tran.Commit();
                }
            }
        }
        public void MiniTest()
        {
            string serialized;
            int id;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact c1;
                    c1 = new Contact();
                    c1.Name = "Nancy Newcomer";
                    c1.Active = true;
                    c1.Type = ContactType.Employee;
                    id = c1.ContactId;
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                }
            }
            Console.WriteLine("serialized: {0}", serialized);

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

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

                    Console.WriteLine("*** Deserializing");
                    tran.Deserialize(serialized);
                    Console.WriteLine("*** Deserialized.");

                    Console.WriteLine("*** type: {0}", Contact.GetRef(id).Type);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);

                    Assert.AreEqual(serialized, serialized2);
                    // Console.WriteLine("s: {0}", serialized);
                }
            }
        }
示例#57
0
        public void Test5()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                SoodaInProcessCache myCache = new SoodaInProcessCache();
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    ContactList cl = Role.Employee.Members.GetSnapshot();
                }
                Assert.IsNotNull(myCache.LoadCollection("ContactToRole where Role = 1"));
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Cache = myCache;
                    tran.CachingPolicy = new SoodaCacheAllPolicy();

                    Assert.AreEqual(0, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);

                    // make sure w have a cache hit
                    ContactList cl = Role.Employee.Members.GetSnapshot();
                    Assert.AreEqual(1, tran.Statistics.CollectionCacheHits);
                    Assert.AreEqual(0, tran.Statistics.CollectionCacheMisses);
                }
            }
        }
示例#58
0
        //[Test]
        public void AllDataTypesNotNullDefaults()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    AllDataTypes adt = new AllDataTypes();

                    Assert.AreEqual(adt.NnDateVal, DateTime.MinValue);
                    Assert.AreEqual(adt.NnIntVal, (int)0);
                    Assert.AreEqual(adt.NnInt64Val, (long)0);
                    Assert.AreEqual(adt.NnDecimalVal, (decimal)0);
                    Assert.AreEqual(adt.NnDoubleVal, (double)0);
                    Assert.AreEqual(adt.NnFloatVal, (float)0);
                    Assert.AreEqual(adt.NnStringVal, String.Empty);
                    Assert.AreEqual(adt.NnBoolVal, false);
                }
            }
        }
示例#59
0
        public void Collection1toNTest(bool quiet)
        {
            string serialized;

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    Contact c1;
                    Group g = Group.Load(10);

                    Assert.AreEqual((string)g.Manager.Name, "Mary Manager");
                    Assert.AreEqual(g.Members.Count, 4);
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(53)));
                    g.Members.Remove(Contact.GetRef(53));
                    Assert.AreEqual(g.Members.Count, 3);
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));

                    g.Members.Add(c1 = new Contact());
                    c1.Name = "Nancy Newcomer";
                    c1.Active = true;
                    Assert.AreEqual(g.Members.Count, 4);
                    c1.Type = ContactType.Employee;

                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    int times = 0;
                    foreach (Contact c in g.Members)
                    {
                        if (!quiet)
                            Console.WriteLine("Got {0} [{1}]", c.Name, c.ContactId);
                        times++;
                        Assert.IsTrue(
                            c == Contact.GetRef(51) ||
                            c == Contact.GetRef(1) ||
                            c == c1 ||
                            c == Contact.GetRef(2));
                    };
                    Assert.AreEqual(times, 4, "foreach() loop gets called 4 times");
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    Assert.IsTrue(g.Members.Contains(c1));
                    Assert.AreEqual(g.Members.Count, 4);

                    foreach (Contact c in g.Members)
                    {
                        if (!quiet)
                            Console.WriteLine("before serialization, member: {0}", c.Name);
                    }
                    serialized = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                    //serialized = tran.Serialize();
                    if (!quiet)
                        Console.WriteLine("Serialized as\n{0}", serialized);
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    tran.Deserialize(serialized);
                    string serialized2 = tran.Serialize(SoodaSerializeOptions.IncludeNonDirtyFields | SoodaSerializeOptions.IncludeNonDirtyObjects | SoodaSerializeOptions.Canonical);
                    //string serialized2 = tran.Serialize();
                    if (serialized == serialized2)
                    {
                        if (!quiet)
                            Console.WriteLine("Serialization is stable");
                    }
                    else
                    {
                        if (!quiet)
                            Console.WriteLine("Serialized again as\n{0}", serialized2);
                    }
                    Assert.AreEqual(serialized, serialized2, "Serialization preserves state");

                    Group g = Group.Load(10);

                    foreach (Contact c in g.Members)
                    {
                        //if (!quiet)
                        Console.WriteLine("after deserialization, member: {0}", c.Name);
                    }
                    Assert.AreEqual("Mary Manager", g.Manager.Name);
                    Assert.AreEqual(4, g.Members.Count);
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));

                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    int times = 0;
                    foreach (Contact c in g.Members)
                    {
                        times++;
                        Assert.IsTrue(
                            c == Contact.GetRef(51) ||
                            c == Contact.GetRef(1) ||
                            (string)c.Name == "Nancy Newcomer" ||
                            c == Contact.GetRef(2));
                    };
                    Assert.AreEqual(times, 4, "foreach() loop gets called 4 times");
                    Assert.IsTrue(!g.Members.Contains(Contact.GetRef(53)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(51)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(1)));
                    Assert.IsTrue(g.Members.Contains(Contact.GetRef(2)));
                    Assert.AreEqual(g.Members.Count, 4);
                    tran.Commit();
                }
            }
        }
示例#60
0
        public void MultiTableGetListTestWithWhere()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    foreach (MultiKey mk in MultiKey.GetList(new SoodaWhereClause("Contact = {0}", 1)))
                    {
                        Console.WriteLine("mk: {0},{1} = {2},{3},{4}", mk.Contact, mk.Group, mk.Value, mk.Value2, mk.Value3);
                    }
                }
            }
        }