Esempio n. 1
0
        static public void Delete(System.Int32 autoKey, esSqlAccessType sqlAccessType)
        {
            var obj = new CustomClientAliased();

            obj.AutoKey = autoKey;
            obj.AcceptChanges();
            obj.MarkAsDeleted();
            obj.Save(sqlAccessType);
        }
        public void ClientSideAliased()
        {
            int keyId = -1;
            CustomClientAliasedCollection coll = new CustomClientAliasedCollection();

            switch (coll.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.EffiProzProvider":
                    Assert.Ignore("Not implemented");
                    break;

                default:
                    using (esTransactionScope scope = new esTransactionScope())
                    {
                        // Setup
                        CustomClientAliased entity = new CustomClientAliased();

                        entity = new CustomClientAliased();
                        entity.FirstName = "Test";
                        entity.LastName = "One";

                        // Insert
                        entity.Save();
                        keyId = entity.AutoKey.Value;

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "One");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 1);

                        // Update
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "One");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 1);

                        DateTime modified = entity.DateModified.Value;
                        entity.LastName = "Two";
                        System.Threading.Thread.Sleep(4);
                        entity.Save();

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value.Day, DateTime.UtcNow.Day);
                        Assert.AreEqual(entity.DateModified.Value.Day, DateTime.UtcNow.Day);
                        Assert.Greater(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        // No Update
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);
                        DateTime added = entity.DateAddedAlias.Value;
                        modified = entity.DateModified.Value;

                        entity.Save();

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value, added);
                        Assert.AreEqual(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        // Clean up
                        entity = new CustomClientAliased();
                        entity.LoadByPrimaryKey(keyId);

                        Assert.AreEqual(entity.FirstName, "Test");
                        Assert.AreEqual(entity.LastName, "Two");
                        Assert.AreEqual(entity.Age.Value, 40);
                        Assert.AreEqual(entity.DateAddedAlias.Value, added);
                        Assert.AreEqual(entity.DateModified.Value, modified);
                        Assert.AreEqual(entity.AddedBy, "AddedBy Client User");
                        Assert.AreEqual(entity.ModifiedByAlias, "ModifiedBy Client User");
                        Assert.AreEqual(entity.EsVersion.Value, 2);

                        entity.MarkAsDeleted();
                        entity.Save();

                        entity = new CustomClientAliased();
                        if (entity.LoadByPrimaryKey(keyId))
                        {
                            Assert.Fail("Not deleted");
                        }
                    }
                    break;
            }
        }