public void SerializeDeserializeLoadEntityBinary()
        {
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                int key = 0;
                aggTest.Query.Where(
                    aggTest.Query.LastName == "Douglas",
                    aggTest.Query.FirstName == "Fred");
                aggTest.Query.Load();
                key = aggTest.Id.Value;

                aggTest = new AggregateTest();
                aggTest.LoadByPrimaryKey(key);

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, aggTest);

                ms.Position = 0;
                aggClone    = (AggregateTest)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual("Douglas", aggClone.str().LastName);
            }
        }
        public void TestCommandTimeoutConfig()
        {
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.SqlClientProvider":
                // Collection
                aggTestColl = new AggregateTestCollection();
                Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTestColl.Query.Load(), "Query.Load");
                aggTestColl = new AggregateTestCollection();
                Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTestColl.LoadAll(), "LoadAll");

                // Entity
                aggTest = new AggregateTest();
                Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                aggTest.Query.es.Top = 1;
                Assert.IsTrue(aggTest.Query.Load(), "Query.Load");
                int aggKey = aggTest.Id.Value;
                aggTest = new AggregateTest();
                Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                Assert.IsTrue(aggTest.LoadByPrimaryKey(aggKey), "LoadByPK");
                break;

            default:
                Assert.Ignore("tested for SQL Server only");
                break;
            }
        }
示例#3
0
        public void TestFailedTransaction()
        {
            switch (aggTest.es.Connection.Name)
            {
            case "SQLStoredProcEnterprise":
            case "SQLDynamicEnterprise":
            case "ORACLEStoredProcEnterprise":
            case "ORACLEDynamicEnterprise":
            case "VistaDBDynamic":
                Assert.Ignore("Using esTransactionScope only");
                break;

            default:
                try
                {
                    aggTest = new AggregateTest();
                    AggregateTest aggTest2  = new AggregateTest();
                    int           tempId1   = -1;
                    int           tempId2   = -1;
                    aggTest2.str().HireDate = "1/1/1";

                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        try
                        {
                            aggTest.Save();
                            tempId1 = aggTest.Id.Value;
                            aggTest2.Save();
                            tempId2 = aggTest2.Id.Value;

                            throw new Exception();

                            scope.Complete();
                        }
                        catch
                        {
                        }
                    }
                    aggTest = new AggregateTest();
                    Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId1));

                    aggTest = new AggregateTest();
                    Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId2));
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.ToString());
                }
                break;
            }
        }
        public void TestDateTimeMicroSeconds()
        {
            int           testId = -1;
            AggregateTest test   = new AggregateTest();

            switch (test.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("MS Access only resolves to MilliSeconds.");
                break;

            case "EntitySpaces.MySqlClientProvider":
                Assert.Ignore("Not supported.");
                break;

            case "EntitySpaces.SqlServerCeProvider":
            case "EntitySpaces.SqlServerCe4Provider":
            case "EntitySpaces.SqlClientProvider":
                Assert.Ignore("Requires SQL Server 2008 and datetime2 data type.");
                break;

            default:
                try
                {
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        test.HireDate = Convert.ToDateTime("1902-01-01 01:01:01.000001");
                        test.Save();
                        testId = test.Id.Value;

                        test = new AggregateTest();
                        Assert.IsTrue(test.LoadByPrimaryKey(testId));
                        Assert.AreEqual(Convert.ToDateTime("1902-01-01 01:01:01.000001"), test.HireDate.Value, "MicroSeconds");
                    }
                }
                finally
                {
                    // Clean up
                    test = new AggregateTest();
                    if (test.LoadByPrimaryKey(testId))
                    {
                        test.MarkAsDeleted();
                        test.Save();
                    }
                }
                break;
            }
        }
        public void EntityLoadByPrimaryKey()
        {
            aggTest.Query
            .Select()
            .Where
            (
                aggTest.Query.FirstName.Equal("Sarah"),
                aggTest.Query.LastName.Equal("Doe")
            );
            Assert.IsTrue(aggTest.Query.Load());
            int primaryKey = aggTest.Id.Value;

            Assert.IsTrue(aggClone.LoadByPrimaryKey(primaryKey));
            Assert.AreEqual("Doe", aggClone.str().LastName);
            Assert.AreEqual("Sarah", aggClone.str().FirstName);
        }
示例#6
0
        public void WhereLikeEscapedMultiWithSubOp()
        {
            int tempId = -1;
            AggregateTestCollection collection = new AggregateTestCollection();
            AggregateTest           aggTest    = new AggregateTest();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.MSAccessProvider":
                Assert.Ignore("Not supported.");
                break;

            default:
                try
                {
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        aggTest.LastName = "a 10% name";
                        aggTest.Save();
                        tempId = aggTest.Id.Value;

                        collection.Query
                        .Select()
                        .Where
                        (
                            collection.Query.LastName.Trim().Like("%10!%%", '!'),
                            collection.Query.LastName.Like("%a%")
                        );
                        Assert.IsTrue(collection.Query.Load());
                        Assert.AreEqual(1, collection.Count);
                    }
                }
                finally
                {
                    // Clean up
                    aggTest = new AggregateTest();
                    if (aggTest.LoadByPrimaryKey(tempId))
                    {
                        aggTest.MarkAsDeleted();
                        aggTest.Save();
                    }
                }
                break;
            }
        }
示例#7
0
        public void TestTransactions()
        {
            switch (aggTest.es.Connection.Name)
            {
            case "SQLStoredProcEnterprise":
            case "SQLDynamicEnterprise":
            case "ORACLEStoredProcEnterprise":
            case "ORACLEDynamicEnterprise":
            case "VistaDBDynamic":
                Assert.Ignore("Using esTransactionScope only");
                break;

            default:
                int tempId1 = 0;
                int tempId2 = 0;

                aggTest = new AggregateTest();
                AggregateTest aggTest2 = new AggregateTest();

                using (esTransactionScope scope = new esTransactionScope())
                {
                    aggTest.Save();
                    tempId1 = aggTest.Id.Value;
                    aggTest2.Save();
                    tempId2 = aggTest2.Id.Value;

                    scope.Complete();
                }

                aggTest = new AggregateTest();
                Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId1));
                aggTest.MarkAsDeleted();
                aggTest.Save();

                aggTest = new AggregateTest();
                Assert.IsTrue(aggTest.LoadByPrimaryKey(tempId2));
                aggTest.MarkAsDeleted();
                aggTest.Save();

                break;
            }
        }
        public void TestDateTime()
        {
            int testId = -1;
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
            AggregateTest           test        = new AggregateTest();

            try
            {
                using (EntitySpaces.Interfaces.esTransactionScope scope =
                           new EntitySpaces.Interfaces.esTransactionScope())
                {
                    aggTestColl.Query.Load();
                    aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);
                    test = (AggregateTest)aggTestColl[0];
                    DateTime date = test.HireDate.Value;
                    Assert.AreEqual(Convert.ToDateTime("02/16/2000 05:59:31"), date);

                    test          = new AggregateTest();
                    test.HireDate = Convert.ToDateTime("12/31/9999");
                    test.Save();
                    testId = test.Id.Value;

                    test = new AggregateTest();
                    Assert.IsTrue(test.LoadByPrimaryKey(testId));
                    Assert.AreEqual(Convert.ToDateTime("12/31/9999"), test.HireDate.Value);
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
            finally
            {
                // Clean up
                test = new AggregateTest();
                if (test.LoadByPrimaryKey(testId))
                {
                    test.MarkAsDeleted();
                    test.Save();
                }
            }
        }
示例#9
0
        public void TestTransactionWithoutComplete()
        {
            switch (aggTest.es.Connection.Name)
            {
            case "SQLStoredProcEnterprise":
            case "SQLDynamicEnterprise":
            case "ORACLEStoredProcEnterprise":
            case "ORACLEDynamicEnterprise":
            case "VistaDBDynamic":
                Assert.Ignore("Using esTransactionScope only");
                break;

            default:
                int tempId = 0;
                try
                {
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        aggTest.Save();
                        tempId = aggTest.Id.Value;
                    }
                    aggTest = new AggregateTest();
                    Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId));
                }
                finally
                {
                    aggTest = new AggregateTest();
                    if (aggTest.LoadByPrimaryKey(tempId))
                    {
                        aggTest.MarkAsDeleted();
                        aggTest.Save();
                    }
                }
                break;
            }
        }
 public void EntityLoadByPrimaryKeyFalse()
 {
     Assert.IsFalse(aggTest.LoadByPrimaryKey(-1));
 }