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; } }
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(); } }
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); }
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; } }
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); }
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()); }
public void TestToUpper() { AggregateTestCollection collection = new AggregateTestCollection(); collection.Query.Where(collection.Query.LastName.ToUpper() == "DOE"); collection.Query.Load(); Assert.AreEqual(3, collection.Count); }
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); }
public void TestToUpperWithLike() { AggregateTestCollection collection = new AggregateTestCollection(); collection.Query.Where(collection.Query.LastName.ToUpper().Like("DO%")); collection.Query.Load(); Assert.AreEqual(4, collection.Count); }
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); }
public void TestLTrim() { AggregateTestCollection collection = new AggregateTestCollection(); collection.Query.Where(collection.Query.LastName.LTrim() == "Doe"); collection.Query.Load(); Assert.AreEqual(3, collection.Count); }
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); }
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); }
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(); }
public void TestAddNewOnCollection() { aggTestColl = new AggregateTestCollection(); Assert.IsFalse(aggTestColl.IsDirty); AggregateTest t = aggTestColl.AddNew(); Assert.IsTrue(aggTestColl.IsDirty); }
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"))); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }