static public void Delete(System.Int32 id, esSqlAccessType sqlAccessType) { var obj = new AggregateTest(); obj.Id = id; obj.AcceptChanges(); obj.MarkAsDeleted(); obj.Save(sqlAccessType); }
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 TestDeleteOnEntity() { aggTest = new AggregateTest(); aggTest.FirstName = "Mike"; aggTest.AcceptChanges(); Assert.IsFalse(aggTest.es.IsAdded); Assert.IsFalse(aggTest.es.IsDeleted); Assert.IsFalse(aggTest.es.IsModified); Assert.IsFalse(aggTest.es.IsDirty); Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0); Assert.IsTrue(aggTest.es.RowState == esDataRowState.Unchanged); // Let's mark it as deleted aggTest.MarkAsDeleted(); Assert.IsFalse(aggTest.es.IsAdded); Assert.IsTrue(aggTest.es.IsDeleted); Assert.IsFalse(aggTest.es.IsModified); Assert.IsTrue(aggTest.es.IsDirty); Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0); Assert.IsTrue(aggTest.es.RowState == esDataRowState.Deleted); }
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 DeleteWithoutLoading() { using (esTransactionScope scope = new esTransactionScope()) { AggregateTestCollection deleteList = new AggregateTestCollection(); deleteList.Query.Select(deleteList.Query.Id, deleteList.Query.LastName) .Where(deleteList.Query.LastName == "Doe"); Assert.IsTrue(deleteList.Query.Load()); foreach (AggregateTest entity in deleteList) { AggregateTest tempEntity = new AggregateTest(); tempEntity.Id = entity.Id; tempEntity.AcceptChanges(); // Sets RowState to Unchanged tempEntity.MarkAsDeleted(); // RowState is Deleted tempEntity.Save(); } AggregateTestCollection testList = new AggregateTestCollection(); testList.Query.Select(testList.Query.Id, testList.Query.LastName) .Where(testList.Query.LastName == "Doe"); Assert.IsFalse(testList.Query.Load()); } }
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 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 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_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(); } } }