Exemplo n.º 1
0
        public void Bug1()
        {
            string ser1, ser2;

            using (SoodaTransaction tran = new SoodaTransaction())
            {
                Group g1 = new Group();
                Group g2 = new Group();
                Contact c1 = new Contact();
                Contact c2 = new Contact();
                Contact c3 = new Contact();
                g1.Members.Add(c1);
                g1.Members.Add(c2);
                g1.Members.Add(c3);
                g1.Manager = c1;
                g2.Manager = c2;

                ser1 = tran.Serialize(SoodaSerializeOptions.Canonical);
            }
            using (SoodaTransaction tran = new SoodaTransaction())
            {
                tran.Deserialize(ser1);

                ser2 = tran.Serialize(SoodaSerializeOptions.Canonical);
                Console.WriteLine("ser1 {0}", ser1);
                Console.WriteLine("ser2 {0}", ser2);
                Assert.AreEqual(ser1, ser2, "Serialization is stable");
            }
        }
Exemplo n.º 2
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();
                }
            }
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
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();
                }
            }
        }
Exemplo n.º 5
0
        public void SharedCollection1ToNTest()
        {
            using (SoodaTransaction tran = new SoodaTransaction())
            {
                Group g1 = Group.GetRef(10);

                Contact newManager = new Contact();
                newManager.Type = ContactType.Manager;

                Assert.AreEqual(g1.Managers.Count, 1);
                Assert.IsTrue(g1.Members.Contains(Contact.Mary));
                Assert.IsTrue(g1.Managers.Contains(Contact.Mary));
                g1.Managers.Remove(Contact.Mary);
                Assert.AreEqual(g1.Managers.Count, 0);
                Assert.IsTrue(!g1.Members.Contains(Contact.Mary));
                Assert.IsTrue(!g1.Managers.Contains(Contact.Mary));
                g1.Managers.Add(Contact.Mary);
                Assert.AreEqual(g1.Managers.Count, 1);
                Assert.IsTrue(g1.Members.Contains(Contact.Mary));
                Assert.IsTrue(g1.Managers.Contains(Contact.Mary));
                g1.Members.Add(newManager);
                Assert.AreEqual(g1.Managers.Count, 2);
            }
        }
Exemplo n.º 6
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();
                }
            }
        }
Exemplo n.º 7
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 static Expression<Func<Contact, ContactType, bool>> TypeIsExpression(Contact dummyC, ContactType dummyT)
 {
     return (c, t) => c.Type == t;
 }
 public static bool TypeIs(Contact c, ContactType t)
 {
     return c.Type == t;
 }
Exemplo n.º 10
0
 public void ThreadProc()
 {
     using (SoodaTransaction t = new SoodaTransaction())
     {
         for (int i = 0; i < 100; ++i)
         {
             Contact c = new Contact();
             lock (GeneratedKeys)
             {
                 GeneratedKeys.Add(c.GetPrimaryKeyValue());
             }
         }
     }
 }
Exemplo n.º 11
0
        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);
                }
            }
        }
Exemplo n.º 12
0
        public void ToSoodaObjectListArray()
        {
            ContactList cl = new ContactList(new Contact[0].ToSoodaObjectList());
            Assert.AreEqual(0, cl.Count);

            using (new SoodaTransaction())
            {
                Contact[] a = new Contact[] { Contact.Mary, Contact.Ed };
                cl = new ContactList(a.ToSoodaObjectList());
                Assert.AreEqual(2, cl.Count);
                CollectionAssert.AreEqual(new Contact[] { Contact.Mary, Contact.Ed }, cl);

                // array should have been copied
                a[1] = Contact.Mary;
                CollectionAssert.AreEqual(new Contact[] { Contact.Mary, Contact.Ed }, cl);

                // should not affect the array
                cl.Add(Contact.Eva);
                CollectionAssert.AreEqual(new Contact[] { Contact.Mary, Contact.Ed, Contact.Eva }, cl);
                CollectionAssert.AreEqual(new Contact[] { Contact.Mary, Contact.Mary }, a);
            }
        }
Exemplo n.º 13
0
        public void Test5()
        {
            using (SoodaTransaction tran = new SoodaTransaction())
            {
                Contact c = new Contact();
                c.Type = ContactType.Customer;
                c.PrimaryGroup = Group.GetRef(10);

                ContactList cl = Contact.GetList(tran, new SoodaWhereClause("PrimaryGroup.Manager.Name = {0}", "Mary Manager"), SoodaOrderBy.Unsorted);
                Assert.AreEqual(5, cl.Count);
            }
        }
Exemplo n.º 14
0
        public void Test6()
        {
            using (SoodaTransaction tran = new SoodaTransaction())
            {
                Contact c = new Contact();
                c.Type = ContactType.Customer;
                c.PrimaryGroup = Group.GetRef(11);
                c.Roles.Add(Role.Employee);
                Contact.Mary.Roles.Remove(Role.Employee);

                Console.WriteLine(tran.Serialize());
                ContactList cl = Contact.GetList(tran, new SoodaWhereClause("Roles.Contains(Role where Name={0})", "Employee"), SoodaOrderBy.Unsorted);
                Assert.AreEqual(3, cl.Count);
                cl = Contact.GetList(tran, new SoodaWhereClause("Roles.Contains(Role where Name={0})", "Employee"), SoodaOrderBy.Unsorted);
                Assert.AreEqual(3, cl.Count);
                Console.WriteLine(tran.Serialize());
            }
        }
Exemplo n.º 15
0
        public void TestInsertedObject()
        {
            using (SoodaTransaction tran = new SoodaTransaction())
            {
                Contact c0 = new Contact();
                c0.Type = ContactType.Employee;

                ContactList cl = Contact.GetList(new SoodaWhereClause("Name = {0}", "Ala"));
                foreach (Contact c in cl)
                {
                    Console.WriteLine("c.Name = {0}", c.Name);
                }
            }
        }