public void SerializeDeserializeProxyStubEntityQuery()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                // Client-side query to load an Employee
                Employee emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                emp.Query.Where(emp.Query.EmployeeID == 1);

                // Use binary serialization to include the query
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, emp);
                byte[] query = ms.ToArray();

                // Send it to the server over the wire

                // Server-side deserialize
                bf = new BinaryFormatter();
                ms = new MemoryStream(query);
                Employee newEmp = bf.Deserialize(ms) as Employee;
                newEmp.es.Connection.Name        = "ForeignKeyTest";
                newEmp.Query.es2.Connection.Name = "ForeignKeyTest";

                // Now load it
                Assert.IsTrue(newEmp.Query.Load());
                Assert.AreEqual(1, newEmp.EmployeeID.Value);

                //  Server-side Create a Proxy and Serialize to XML string
                EmployeeProxyStub proxy =
                    new EmployeeProxyStub(newEmp);

                XmlSerializer sf =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringWriter sw = new StringWriter();
                sf.Serialize(sw, proxy);

                string packet = sw.ToString();

                // Send it back to the client over the wire

                // Client-side Proxy XML string deserialize
                XmlSerializer xs =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringReader sr = new StringReader(packet);

                proxy = xs.Deserialize(sr) as EmployeeProxyStub;
                emp   = proxy.Entity;

                Assert.AreEqual("Unchanged", emp.es.RowState.ToString());
                Assert.AreEqual(1, emp.EmployeeID.Value);
            }
        }
        public void TestJSONSerialization()
        {
            //---------------------------------------------------------------
            // Server Side
            //---------------------------------------------------------------
            Employee emp = new Employee();

            emp.es.Connection.Name = "ForeignKeyTest";

            emp.Query.es.Top = 1;
            emp.Query.Select
            (
                emp.Query.EmployeeID,
                emp.Query.FirstName,
                emp.Query.LastName,
                emp.Query.Age,
                (emp.Query.LastName + ", " + emp.Query.FirstName).As("Fullname")
            );
            emp.Query.Load();

            // Modifiy the first name ...
            emp.FirstName = "Freddy";

            //=======================

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(EmployeeProxyStub));
            MemoryStream ms = new MemoryStream();

            ser.WriteObject(ms, (EmployeeProxyStub)emp);

            string json = Encoding.Default.GetString(ms.ToArray());

            ms.Close();

            ms  = new MemoryStream(Encoding.Unicode.GetBytes(json));
            ser = new DataContractJsonSerializer(typeof(EmployeeProxyStub));
            EmployeeProxyStub empProxy = ser.ReadObject(ms) as EmployeeProxyStub;

            ms.Close();

            Employee emp2 = empProxy.Entity;
        }
        public void SerializeDeserializeProxyStubEntity()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                // Load an Employee
                Employee emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                emp.LoadByPrimaryKey(1);

                // Create a Proxy and Serialize into a string named "Packet"
                EmployeeProxyStub proxy =
                    new EmployeeProxyStub(emp);

                XmlSerializer sf =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringWriter sw = new StringWriter();
                sf.Serialize(sw, proxy);

                string packet = sw.ToString();

                // Now let's DeSerialize it
                XmlSerializer xs =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringReader sr = new StringReader(packet);

                proxy = xs.Deserialize(sr) as EmployeeProxyStub;

                Assert.AreEqual("Unchanged", proxy.Entity.es.RowState.ToString());
                Assert.AreEqual("Smith", proxy.Entity.LastName);
            }
        }
        public void SerializeDeserializeProxyStubEntityQuery()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                // Client-side query to load an Employee
                Employee emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                emp.Query.Where(emp.Query.EmployeeID == 1);

                // Use binary serialization to include the query
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, emp);
                byte[] query = ms.ToArray();

                // Send it to the server over the wire

                // Server-side deserialize
                bf = new BinaryFormatter();
                ms = new MemoryStream(query);
                Employee newEmp = bf.Deserialize(ms) as Employee;
                newEmp.es.Connection.Name = "ForeignKeyTest";
                newEmp.Query.es2.Connection.Name = "ForeignKeyTest";

                // Now load it 
                Assert.IsTrue(newEmp.Query.Load());
                Assert.AreEqual(1, newEmp.EmployeeID.Value);

                //  Server-side Create a Proxy and Serialize to XML string
                EmployeeProxyStub proxy =
                    new EmployeeProxyStub(newEmp);

                XmlSerializer sf =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringWriter sw = new StringWriter();
                sf.Serialize(sw, proxy);

                string packet = sw.ToString();

                // Send it back to the client over the wire

                // Client-side Proxy XML string deserialize
                XmlSerializer xs =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringReader sr = new StringReader(packet);

                proxy = xs.Deserialize(sr) as EmployeeProxyStub;
                emp = proxy.Entity;

                Assert.AreEqual("Unchanged", emp.es.RowState.ToString());
                Assert.AreEqual(1, emp.EmployeeID.Value);
            }
        }
        public void SerializeDeserializeProxyStubEntity()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                // Load an Employee
                Employee emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                emp.LoadByPrimaryKey(1);

                // Create a Proxy and Serialize into a string named "Packet"
                EmployeeProxyStub proxy =
                    new EmployeeProxyStub(emp);

                XmlSerializer sf =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringWriter sw = new StringWriter();
                sf.Serialize(sw, proxy);

                string packet = sw.ToString();

                // Now let's DeSerialize it
                XmlSerializer xs =
                    new XmlSerializer(typeof(EmployeeProxyStub));
                StringReader sr = new StringReader(packet);

                proxy = xs.Deserialize(sr) as EmployeeProxyStub;

                Assert.AreEqual("Unchanged", proxy.Entity.es.RowState.ToString());
                Assert.AreEqual("Smith", proxy.Entity.LastName);
            }
        }