public void TwoFilteredViewsOnFilteredCollection()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Load();
            Assert.AreEqual(30, collection.Count);
            collection.Filter = collection.AsQueryable().Where(f => f.LastName == "Doe");
            Assert.AreEqual(3, collection.Count);

            esEntityCollectionView <AggregateTest> view1 =
                new esEntityCollectionView <AggregateTest>(collection);

            Assert.AreEqual(30, view1.Count);
            view1.Filter = view1.AsQueryable().Where(f => f.Age > 20);
            Assert.AreEqual(18, view1.Count);
            Assert.AreEqual(3, collection.Count);

            esEntityCollectionView <AggregateTest> view2 =
                new esEntityCollectionView <AggregateTest>(collection);

            Assert.AreEqual(30, view2.Count);
            view2.Filter = view2.AsQueryable().Where(f => f.FirstName == "John");
            Assert.AreEqual(2, view2.Count);
            Assert.AreEqual(18, view1.Count);
            Assert.AreEqual(3, collection.Count);
        }
        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 SelectWithAlias()
        {
            aggTestColl.Query
            .Select(aggTestColl.Query.Salary.As("S2"), aggTestColl.Query.FirstName, aggTestColl.Query.FirstName.As("FN"))
            .OrderBy(aggTestColl.Query.Id.Ascending);

            Assert.IsTrue(aggTestColl.Query.Load());
            Assert.AreEqual(30, aggTestColl.Count);

            AggregateTestCollection aggControl = new AggregateTestCollection();

            aggControl.Query.OrderBy(aggControl.Query.Id.Ascending);
            aggControl.Query.Load();

            int i = 0;

            foreach (AggregateTest agg in aggTestColl)
            {
                if (aggControl[i].Salary.HasValue)
                {
                    Assert.AreEqual(aggControl[i].Salary.Value,
                                    agg.GetColumn("S2"));
                }
                else
                {
                    Assert.AreEqual(null, agg.GetColumn("S2") as string);
                }
                Assert.AreEqual(aggControl[i].FirstName,
                                agg.GetColumn("FN") as string);
                i++;
            }
        }
 public void TestAttachDetachEntityAdded()
 {
     try
     {
         using (esTransactionScope scope = new esTransactionScope())
         {
             AggregateTestCollection aggTestColl  = new AggregateTestCollection();
             AggregateTestCollection aggCloneColl = new AggregateTestCollection();
             aggCloneColl.LoadAll();
             foreach (AggregateTest entity in aggCloneColl)
             {
                 if (entity.LastName == "Doe")
                 {
                     entity.MarkAllColumnsAsDirty(esDataRowState.Added);
                     aggTestColl.AttachEntity(aggCloneColl.DetachEntity(entity));
                     break;
                 }
             }
             Assert.IsTrue(aggTestColl.IsDirty);
             aggTestColl.Save();
             Assert.IsFalse(aggTestColl.IsDirty, "Collection is still dirty");
             aggTestColl.LoadAll();
             Assert.AreEqual(31, aggTestColl.Count);
         }
     }
     finally
     {
         UnitTestBase.RefreshDatabase();
     }
 }
示例#5
0
        public void TestDateWithPaging()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

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

            case "EntitySpaces.SQLiteProvider":
                collection.Query.Where(collection.Query.HireDate.Date().Equal("2000-02-16"));
                break;

            default:
                collection.Query.Where(
                    collection.Query.HireDate.Date().Equal(Convert.ToDateTime("2000-02-16")));
                break;
            }

            collection.Query.OrderBy(collection.Query.LastName.Ascending);
            collection.Query.es.PageNumber = 1;
            collection.Query.es.PageSize   = 10;
            Assert.IsTrue(collection.Query.Load());
            Assert.AreEqual(1, collection.Count);
        }
示例#6
0
        public void PagingWithTop()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            if (collection.es.Connection.Name == "SqlCe" ||
                collection.es.Connection.ProviderMetadataKey ==
                "esSqlCe4" ||
                collection.es.Connection.ProviderMetadataKey ==
                "esSqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                switch (collection.es.Connection.ProviderSignature.DataProviderName)
                {
                case "EntitySpaces.MSAccessProvider":
                case "EntitySpaces.VistaDBProvider":
                case "EntitySpaces.VistaDB4Provider":
                    Assert.Ignore("Not supported");
                    break;

                default:
                    AggregateTestCollection all = new AggregateTestCollection();

                    all.Query.es.Top = 20;
                    all.Query
                    .OrderBy(all.Query.LastName, esOrderByDirection.Ascending)
                    .OrderBy(all.Query.Id, esOrderByDirection.Ascending);
                    all.Query.Load();

                    collection = new AggregateTestCollection();

                    collection.Query.es.Top = 20;
                    collection.Query
                    .Select(collection.Query.Id, collection.Query.LastName, collection.Query.FirstName, collection.Query.IsActive)
                    .OrderBy(collection.Query.LastName, esOrderByDirection.Ascending)
                    .OrderBy(collection.Query.Id, esOrderByDirection.Ascending);
                    collection.Query.es.PageNumber = 1;
                    collection.Query.es.PageSize   = 8;

                    Assert.IsTrue(collection.Query.Load(), "Load 1");
                    Assert.AreEqual(8, collection.Count, "Count 1");

                    AggregateTest all0        = (AggregateTest)all[0];
                    AggregateTest collection0 = (AggregateTest)collection[0];
                    Assert.AreEqual(all0.Id.Value, collection0.Id.Value, "Compare 1");

                    collection.Query.es.PageNumber = 2;
                    Assert.IsTrue(collection.Query.Load(), "Load 2");
                    Assert.AreEqual(8, collection.Count, "Count 2");

                    all0        = (AggregateTest)all[8];
                    collection0 = (AggregateTest)collection[0];
                    Assert.AreEqual(all0.Id.Value, collection0.Id.Value, "Compare 2");

                    break;
                }
            }
        }
        public void IterateSortedViewAndCollection()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Load();
            collection.Filter = collection.AsQueryable().OrderBy(s => s.LastName);

            esEntityCollectionView <AggregateTest> view1 =
                new esEntityCollectionView <AggregateTest>(collection);

            view1.Filter = view1.AsQueryable().OrderByDescending(s => s.LastName);

            string prevName = collection[0].LastName;

            foreach (AggregateTest at in collection)
            {
                Assert.IsTrue(String.Compare(prevName, at.LastName) <= 0);
                prevName = at.LastName;
            }

            prevName = view1[0].LastName;
            foreach (AggregateTest at in view1)
            {
                Assert.IsTrue(String.Compare(prevName, at.LastName) >= 0);
                prevName = at.LastName;
            }
        }
示例#8
0
        public void TestDatePartInWhere()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.NpgsqlProvider":
            case "EntitySpaces.Npgsql2Provider":
            case "EntitySpaces.MySqlClientProvider":
            case "EntitySpaces.SybaseSqlAnywhereProvider":
                collection.Query.Where(
                    collection.Query.HireDate.DatePart("month") == 5);
                break;

            case "EntitySpaces.OracleClientProvider":
                collection.Query.Where(
                    collection.Query.HireDate.DatePart("MONTH") == 5);
                break;

            case "EntitySpaces.SQLiteProvider":
                collection.Query.Where(
                    collection.Query.HireDate.DatePart("'%m'") == "05");
                break;

            default:
                collection.Query.Where(
                    collection.Query.HireDate.DatePart("m") == 5);
                break;
            }

            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
        }
示例#9
0
        public void TestDatePartInOrderBy()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
            case "EntitySpaces.NpgsqlProvider":
            case "EntitySpaces.Npgsql2Provider":
            case "EntitySpaces.MySqlClientProvider":
            case "EntitySpaces.SybaseSqlAnywhereProvider":
                collection.Query.OrderBy(
                    collection.Query.HireDate.DatePart("month").Ascending);
                break;

            case "EntitySpaces.OracleClientProvider":
                collection.Query.OrderBy(
                    collection.Query.HireDate.DatePart("MONTH").Ascending);
                break;

            case "EntitySpaces.SQLiteProvider":
                collection.Query.OrderBy(
                    collection.Query.HireDate.DatePart("'%m'").Ascending);
                break;

            default:
                collection.Query.OrderBy(
                    collection.Query.HireDate.DatePart("m").Ascending);
                break;
            }

            Assert.IsTrue(collection.Query.Load());
        }
示例#10
0
        public void TestToUpper()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.ToUpper() == "DOE");
            collection.Query.Load();
            Assert.AreEqual(3, collection.Count);
        }
示例#11
0
        public void TestSubstringWithNotNull()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.Substring(1, 2).IsNotNull());
            collection.Query.Load();
            Assert.AreEqual(24, collection.Count);
        }
示例#12
0
        public void TestToUpperWithLike()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.ToUpper().Like("DO%"));
            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
        }
示例#13
0
        public void TestToLowerWithIn()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.ToLower().In("doe", "douglas"));
            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
        }
示例#14
0
        public void TestLTrim()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.LTrim() == "Doe");
            collection.Query.Load();
            Assert.AreEqual(3, collection.Count);
        }
示例#15
0
        public void TestSubstring()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.Substring(1, 2) == "Do");
            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
        }
示例#16
0
        public void TestLTrimWithBetween()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.LTrim().Between("Doe", "Douglas"));
            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
        }
示例#17
0
        public void TestTrimWithNotEqual()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.Trim().NotEqual("Doe"));
            collection.Query.Load();
            Assert.AreEqual(21, collection.Count);
        }
 public void Init2()
 {
     aggTestColl   = new AggregateTestCollection();
     aggTest       = new AggregateTest();
     aggTestQuery  = new AggregateTestQuery();
     aggCloneColl  = new AggregateTestCollection();
     aggClone      = new AggregateTest();
     aggCloneQuery = new AggregateTestQuery();
 }
示例#19
0
        public void TestAddNewOnCollection()
        {
            aggTestColl = new AggregateTestCollection();
            Assert.IsFalse(aggTestColl.IsDirty);

            AggregateTest t = aggTestColl.AddNew();

            Assert.IsTrue(aggTestColl.IsDirty);
        }
示例#20
0
        public void TestRoundInSelectPositive()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Select(collection.Query.Salary.Round(1));
            collection.Query.Where(collection.Query.FirstName == "David");
            collection.Query.Where(collection.Query.LastName == "Doe");
            collection.Query.Load();
            Assert.AreEqual(34.7000m, collection[0].Salary.Value);
        }
        public void GetColumnWithAliasCollection()
        {
            AggregateTestCollection coll = new AggregateTestCollection();

            coll.Query.es.CountAll      = true;
            coll.Query.es.CountAllAlias = "Count";
            coll.Query.Load();

            Assert.AreEqual(30, Convert.ToInt32(coll[0].GetColumn("Count")));
        }
示例#22
0
        public void TestLength()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.Length() == 3);
            string lq = collection.Query.Parse();

            collection.Query.Load();
            Assert.AreEqual(3, collection.Count);
        }
示例#23
0
        public void TestToUpperInSelect()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Select(collection.Query.LastName.ToUpper());
            collection.Query.Where(collection.Query.LastName == "Doe");
            collection.Query.Load();
            Assert.AreEqual(3, collection.Count);
            Assert.AreEqual("DOE", collection[0].LastName);
        }
示例#24
0
        public void TestRoundInWherePositive()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.Salary.Round(1) == 34.7);

            string lq = collection.Query.Parse();

            collection.Query.Load();
            Assert.AreEqual(1, collection.Count);
        }
示例#25
0
        public void TestSubstringNoStart()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.LastName.Substring(2) == "Do");
            collection.Query.OrderBy(collection.Query.Id,
                                     EntitySpaces.DynamicQuery.esOrderByDirection.Ascending);
            collection.Query.Load();
            Assert.AreEqual(4, collection.Count);
            Assert.AreEqual("Doe", collection[0].LastName);
        }
示例#26
0
        public void TestRoundInWhereZero()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Where(collection.Query.Salary.Round(0) == 35);

            string lq = collection.Query.Parse();

            collection.Query.Load();
            Assert.AreEqual(2, collection.Count);
        }
示例#27
0
        public void AliasAndGetColumn()
        {
            int totalNo = 0;
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Select(
                collection.Query.Age.Sum().As("total"));
            collection.Query.Load();
            totalNo = Convert.ToInt32(collection[0].GetColumn("total"));
            Assert.AreEqual(726, totalNo);
        }
示例#28
0
        public void TestDateInSelect()
        {
            AggregateTestCollection collection = new AggregateTestCollection();

            collection.Query.Select(collection.Query.HireDate.Date());
            string lq = collection.Query.Parse();

            collection.Query.Load();
            Assert.AreEqual(30, collection.Count);
            collection.Filter = collection.AsQueryable().Where(f => f.HireDate != null && f.HireDate.Value.ToShortDateString() == "2/16/2000");
            Assert.AreEqual(1, collection.Count);
        }
示例#29
0
        public void TestRejectChangesOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();

            aggTest.FirstName = "Mike";

            aggTestColl.RejectChanges();

            Assert.IsFalse(aggTestColl.IsDirty);
        }
        public void TestForEach()
        {
            AggregateTestCollection aggTestColl = new AggregateTestCollection();

            aggTestColl.LoadAll();
            foreach (AggregateTest entity in aggTestColl)
            {
                entity.LastName = "E_" + entity.LastName;
            }
            aggTestColl.Filter = aggTestColl.AsQueryable().Where(f => f.LastName.Contains("E_"));
            Assert.AreEqual(30, aggTestColl.Count);
        }