Пример #1
0
        static public void Delete(System.Int64 id, esSqlAccessType sqlAccessType)
        {
            var obj = new ConcurrencyTestChild();

            obj.Id = id;
            obj.AcceptChanges();
            obj.MarkAsDeleted();
            obj.Save(sqlAccessType);
        }
        public void ConcurrencyOnUpdateDeleteAutoKey()
        {
            long oldKey = -1;
            ConcurrencyTestChildCollection collection = new ConcurrencyTestChildCollection();

            switch (collection.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlServerCeProvider":
                case "EntitySpaces.SqlServerCe4Provider":
                    Assert.Ignore("Not implemented for SqlCe");
                    break;

                default:
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            // Setup
                            ConcurrencyTestChild entity = new ConcurrencyTestChild();
                            entity.Name = "Test 1";
                            entity.DefaultTest = Convert.ToDateTime("2010-01-01");
                            entity.Save();
                            oldKey = entity.Id.Value;

                            // Test
                            entity = new ConcurrencyTestChild();
                            entity.LoadByPrimaryKey(oldKey);
                            entity.Name = "Test 2";

                            ConcurrencyTestChild entity2 = new ConcurrencyTestChild();
                            entity2.LoadByPrimaryKey(oldKey);
                            entity2.MarkAsDeleted();

                            entity.Save();
                            entity2.Save();
                            Assert.Fail("Concurrency Exception not thrown.");
                        }
                    }
                    catch (EntitySpaces.Interfaces.esConcurrencyException cex)
                    {
                        switch (collection.es.Connection.ProviderSignature.DataProviderName)
                        {
                            case "EntitySpaces.MSAccessProvider":
                            case "EntitySpaces.MySqlClientProvider":
                            case "EntitySpaces.SQLiteProvider":
                            case "EntitySpaces.SqlServerCeProvider":
                            case "EntitySpaces.SybaseSqlAnywhereProvider":
                            case "EntitySpaces.VistaDBProvider":
                            case "EntitySpaces.VistaDB4Provider":
                                Assert.AreEqual("Error in", cex.Message.Substring(0, 8));
                                break;

                            case "EntitySpaces.OracleClientProvider":
                                Assert.AreEqual("ORA-20101", cex.Message.Substring(0, 9));
                                break;

                            default:
                                Assert.AreEqual("Update failed", cex.Message.Substring(0, 13));
                                break;
                        }
                    }
                    finally
                    {
                        // Cleanup
                        ConcurrencyTestChild entity = new ConcurrencyTestChild();
                        if (entity.LoadByPrimaryKey(oldKey))
                        {
                            entity.MarkAsDeleted();
                            entity.Save();
                        }
                    }
                    break;
            }
        }
Пример #3
0
 public ConcurrencyTestChildProxyStub(ConcurrencyTestChild obj, bool dirtyColumnsOnly)
 {
     theEntity             = this.entity = obj;
     this.dirtyColumnsOnly = dirtyColumnsOnly;
 }
Пример #4
0
 public ConcurrencyTestChildProxyStub(ConcurrencyTestChild obj)
 {
     theEntity = this.entity = obj;
 }
        public void RetrieveDefaultOnInsert()
        {
            long id = -1;
            ConcurrencyTestChild entity = new ConcurrencyTestChild();

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    // Create test record
                    entity = new ConcurrencyTestChild();
                    entity.Name = "TestFirst";
                    entity.Save();

                    // Get the ID of the newly saved object
                    id = entity.Id.Value;

                    // Check default value is retrieved on insert
                    Assert.AreEqual(DateTime.Now.Day, entity.DefaultTest.Value.Day);
                }
            }
            finally
            {
                // Clean up
                entity = new ConcurrencyTestChild();
                if (entity.LoadByPrimaryKey(id))
                {
                    entity.MarkAsDeleted();
                    entity.Save();
                }
            }
        }
        public void RetrieveComputed()
        {
            long id = -1;
            ConcurrencyTestChild entity = new ConcurrencyTestChild();

            switch (entity.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlClientProvider":
                case "EntitySpaces.SybaseSqlAnywhereProvider":
                    try
                    {
                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            // Create test record
                            entity = new ConcurrencyTestChild();
                            entity.Name = "TestFirst";
                            entity.DefaultTest = Convert.ToDateTime("2010-01-01");
                            entity.ColumnA = 1;
                            entity.ColumnB = 2;
                            entity.Save();

                            // Get the ID of the newly saved object
                            id = entity.Id.Value;

                            // Check computed column is retrieved on insert
                            Assert.AreEqual(3, entity.ComputedAB.Value);

                            // Retrieve record for update
                            entity = new ConcurrencyTestChild();
                            entity.LoadByPrimaryKey(id);

                            // Set the columns for computation
                            entity.ColumnA = 10;
                            entity.ColumnB = 20;
                            entity.Save();

                            // Check computed values are retrieved on update
                            Assert.AreEqual(30, entity.ComputedAB.Value);
                        }
                    }
                    finally
                    {
                        // Clean up
                        entity = new ConcurrencyTestChild();
                        if (entity.LoadByPrimaryKey(id))
                        {
                            entity.MarkAsDeleted();
                            entity.Save();
                        }
                    }
                    break;

                default:
                    Assert.Ignore("SQL Server only");
                    break;
            }
        }