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 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(); } } }
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 RejectChangesCollection() { using (esTransactionScope scope = new esTransactionScope()) { aggTest = aggTestColl.AddNew(); aggTestColl.Save(); int aggTestId = aggTest.Id.Value; aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(31, aggTestColl.Count); aggTest = aggTestColl.FindByPrimaryKey(aggTestId); aggTest.MarkAsDeleted(); aggTestColl.AddNew(); aggTestColl.RejectChanges(); aggTestColl.Save(); aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(31, aggTestColl.Count); // Cleanup aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); aggTest.MarkAsDeleted(); aggTest.Save(); } }
public void SetIdentityKeyIgnored() { int key = -1; using (esTransactionScope scope = new esTransactionScope()) { aggTest.Id = 0; aggTest.LastName = "TestName"; aggTest.Save(); key = aggTest.Id.Value; Assert.Less(0, key); aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(key); Assert.AreEqual("TestName", aggTest.LastName); aggTest.MarkAsDeleted(); aggTest.Save(); } }
public void DynamicSaveNull() { int id = -1; //if (aggTestColl.es.Connection.SqlAccessType == // EntitySpaces.Interfaces.esSqlAccessType.DynamicSQL) //{ try { using (esTransactionScope scope = new esTransactionScope()) { // Create our test record aggTest = new AggregateTest(); aggTest.FirstName = "TestFirst"; aggTest.LastName = "TestLast"; aggTest.Save(); // Get the ID of the newly saved object id = aggTest.Id.Value; // Confirm it saved aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(id); Assert.AreEqual("TestFirst", aggTest.FirstName); Assert.AreEqual("TestLast", aggTest.LastName); // Set the LastName to null // FirstName to a empty string aggTest.FirstName = String.Empty; aggTest.LastName = null; aggTest.Save(); // Re-read it, confirm null/empty aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(id); // Oracle is not ANSI SQL compliant. // It treats an empty string as NULL. if (aggTest.es.Connection.ProviderSignature.DataProviderName == "EntitySpaces.OracleClientProvider") { Assert.IsNull(aggTest.FirstName); } else { Assert.AreEqual("", aggTest.FirstName); Assert.IsNotNull(aggTest.FirstName); } Assert.IsNull(aggTest.LastName); } } finally { // Clean up aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(id)) { aggTest.MarkAsDeleted(); aggTest.Save(); } } //} //else //{ // Assert.Ignore("DynamicSQL test only."); //} }
public void TestDateTimeMilliSeconds() { int testId = -1; AggregateTest test = new AggregateTest(); switch (test.es.Connection.ProviderSignature.DataProviderName) { case "EntitySpaces.SqlServerCeProvider": case "EntitySpaces.SqlServerCe4Provider": case "EntitySpaces.SqlClientProvider": Assert.Ignore("Requires SQL Server 2008 and datetime2 data type."); break; case "EntitySpaces.MySqlClientProvider": Assert.Ignore("Not supported."); break; default: try { using (esTransactionScope scope = new esTransactionScope()) { test.HireDate = Convert.ToDateTime("1901-01-01 01:01:01.001"); test.Save(); testId = test.Id.Value; test = new AggregateTest(); Assert.IsTrue(test.LoadByPrimaryKey(testId)); Assert.AreEqual(Convert.ToDateTime("1901-01-01 01:01:01.001"), test.HireDate.Value, "MilliSeconds"); } } finally { // Clean up test = new AggregateTest(); if (test.LoadByPrimaryKey(testId)) { test.MarkAsDeleted(); test.Save(); } } break; } }
public void UpdateOrInsertEntity() { using (esTransactionScope scope = new esTransactionScope()) { // The PK does not exist, so insert aggTest = new AggregateTest(); Assert.IsFalse(aggTest.LoadByPrimaryKey(0)); aggTest.LastName = "IsInsert"; aggTest.Save(); int aggTestId = aggTest.Id.Value; // The PK does exist, so update aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); Assert.AreEqual("IsInsert", aggTest.LastName); aggTest.LastName = "IsUpdate"; aggTest.Save(); aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); Assert.AreEqual("IsUpdate", aggTest.LastName); // Clean up aggTest.MarkAsDeleted(); aggTest.Save(); aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(30, aggTestColl.Count); } }
public void IsDirtyCollection() { using (esTransactionScope scope = new esTransactionScope()) { Assert.IsFalse(aggTestColl.IsDirty); aggTest = aggTestColl.AddNew(); Assert.IsTrue(aggTestColl.IsDirty); aggTestColl.Save(); Assert.IsFalse(aggTestColl.IsDirty); int tempId = aggTest.Id.Value; aggTest.LastName = "LastName"; Assert.IsTrue(aggTestColl.IsDirty); aggTestColl.Save(); Assert.IsFalse(aggTestColl.IsDirty); aggTest.MarkAsDeleted(); Assert.IsTrue(aggTestColl.IsDirty); aggTestColl.Save(); Assert.IsFalse(aggTestColl.IsDirty); aggTest = aggTestColl.AddNew(); aggTestColl.Save(); tempId = aggTest.Id.Value; aggTest = aggTestColl.AddNew(); aggTestColl.Save(); int tempId2 = aggTest.Id.Value; aggTest = aggTestColl.FindByPrimaryKey(tempId); aggTest.MarkAsDeleted(); aggTest = aggTestColl.FindByPrimaryKey(tempId2); aggTest.LastName = "Test"; aggTest = aggTestColl.AddNew(); aggTest.LastName = "Test2"; Assert.IsTrue(aggTestColl.IsDirty); aggTestColl.Save(); Assert.IsFalse(aggTestColl.IsDirty); int tempId3 = aggTest.Id.Value; // Cleanup aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(tempId)) { aggTest.MarkAsDeleted(); aggTest.Save(); } aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(tempId2); aggTest.MarkAsDeleted(); aggTest.Save(); aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(tempId3); aggTest.MarkAsDeleted(); aggTest.Save(); } }
public void IsDirtyEntity() { int tempId = 0; try { using (esTransactionScope scope = new esTransactionScope()) { aggTest = new AggregateTest(); Assert.IsTrue(aggTest.es.IsDirty); aggTest.Save(); Assert.IsFalse(aggTest.es.IsDirty); tempId = aggTest.Id.Value; aggTest.LastName = "LastName"; Assert.IsTrue(aggTest.es.IsDirty); aggTest.Save(); Assert.IsFalse(aggTest.es.IsDirty); aggTest.MarkAsDeleted(); Assert.IsTrue(aggTest.es.IsDirty); aggTest.Save(); Assert.IsFalse(aggTest.es.IsDirty); } } finally { // Cleanup aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(tempId)) { aggTest.MarkAsDeleted(); aggTest.Save(); } } }
public void RetrieveAutoIncrementingKey() { using (esTransactionScope scope = new esTransactionScope()) { aggTest = aggTestColl.AddNew(); aggTestColl.Save(); int aggTestId = aggTest.Id.Value; aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(31, aggTestColl.Count); aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); aggTest.MarkAsDeleted(); aggTest.Save(); aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(30, aggTestColl.Count); } }
public void EmptyEntity() { using (esTransactionScope scope = new esTransactionScope()) { aggTest = new AggregateTest(); aggTest.Save(); int aggTestId = aggTest.Id.Value; aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); // Clean up aggTest.MarkAsDeleted(); aggTest.Save(); aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(30, aggTestColl.Count); } }
public void NoAddNew() { int aggTestId = -1; try { using (esTransactionScope scope = new esTransactionScope()) { aggTest = new AggregateTest(); aggTest.Age = 30; aggTest.Save(); aggTestId = aggTest.Id.Value; aggTest = new AggregateTest(); Assert.IsTrue(aggTest.LoadByPrimaryKey(aggTestId)); Assert.AreEqual(30, aggTest.Age.Value); } } finally { // Clean up aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(aggTestId)) { aggTest.MarkAsDeleted(); aggTest.Save(); } aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(30, aggTestColl.Count); } }
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 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 UpdateOrInsertEntityCustom() { using (esTransactionScope scope = new esTransactionScope()) { // The PK does not exist, so insert AggregateTest entity = new AggregateTest(); entity.SaveUpdateOrInsert(-1, "IsInsert"); int aggTestId = entity.Id.Value; entity = new AggregateTest(); Assert.IsTrue(entity.LoadByPrimaryKey(aggTestId)); Assert.AreEqual("IsInsert", entity.LastName); // The PK does exist, so update entity = new AggregateTest(); entity.SaveUpdateOrInsert(aggTestId, "IsUpdate"); entity = new AggregateTest(); Assert.IsTrue(entity.LoadByPrimaryKey(aggTestId)); Assert.AreEqual("IsUpdate", entity.LastName); // Clean up entity.MarkAsDeleted(); entity.Save(); aggTestColl = new AggregateTestCollection(); aggTestColl.LoadAll(); Assert.AreEqual(30, aggTestColl.Count); } }
public void SaveTwice_LoadEntity() { string originalName = ""; int key = -1; using (esTransactionScope scope = new esTransactionScope()) { aggTestColl.LoadAll(); foreach (AggregateTest agg in aggTestColl) { key = agg.Id.Value; break; } aggTest.LoadByPrimaryKey(key); originalName = aggTest.LastName; aggTest.LastName = "TestName"; aggTest.Save(); aggTest.LastName = "TestName2"; aggTest.Save(); aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(key); Assert.AreEqual("TestName2", aggTest.LastName); aggTest.LastName = originalName; aggTest.Save(); } }
public void SaveTwice_NewEntity() { int key = -1; try { using (esTransactionScope scope = new esTransactionScope()) { aggTest.LastName = "TestName"; aggTest.Save(); key = aggTest.Id.Value; aggTest.LastName = "TestName2"; aggTest.Save(); aggTest = new AggregateTest(); aggTest.LoadByPrimaryKey(key); Assert.AreEqual("TestName2", aggTest.LastName); } } finally { // Clean up aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(key)) { aggTest.MarkAsDeleted(); aggTest.Save(); } } }
public void WhereNotLikeTextEscaped() { int tempId = -1; switch (aggTestColl.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; aggTestColl.Query .Select() .Where ( aggTestColl.Query.LastName.NotLike("%10!%%", '!') ); Assert.IsTrue(aggTestColl.Query.Load()); Assert.AreEqual(24, aggTestColl.Count); } } finally { // Clean up aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(tempId)) { aggTest.MarkAsDeleted(); aggTest.Save(); } } break; } }
public void SaveWithExtraColumns() { int aggTestId = -1; try { using (esTransactionScope scope = new esTransactionScope()) { // INSERT AggregateTest t = new AggregateTest(); t.Age = 50; t.SetColumn("extracolumn", 50); t.Save(); aggTestId = t.Id.Value; // UPDATE t.Age = 51; t.SetColumn("extracolumn", 51); t.Save(); // DELETE t.SetColumn("extracolumn", 52); t.MarkAsDeleted(); t.Save(); } } finally { // Clean up aggTest = new AggregateTest(); if (aggTest.LoadByPrimaryKey(aggTestId)) { aggTest.MarkAsDeleted(); aggTest.Save(); } } }