public void TestAssociateDissociateNew()
        {
            int terrKey = -1;
            int empKey  = -1;

            Employee emp = new Employee();

            emp.es.Connection.Name = "ForeignKeyTest";
            Territory terr = new Territory();

            terr.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    emp.LastName  = "Test Last";
                    emp.FirstName = "Test First";

                    terr.Description = "Some New Territory";
                    terr.Save();
                    terrKey = terr.TerritoryID.Value;

                    emp.AssociateTerritoryCollection(terr);
                    emp.Save();
                    empKey = emp.EmployeeID.Value;

                    Assert.AreEqual(1, emp.UpToTerritoryCollection.Count);
                    foreach (EmployeeTerritory et in emp.EmployeeTerritoryCollectionByEmpID)
                    {
                        Assert.AreEqual(terr.TerritoryID.Value, et.TerrID.Value);
                    }
                }
            }
            finally
            {
                // Clean up
                emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                if (emp.LoadByPrimaryKey(empKey))
                {
                    foreach (Territory t in emp.UpToTerritoryCollection)
                    {
                        emp.DissociateTerritoryCollection(t);
                    }
                    emp.MarkAsDeleted();
                    emp.Save();
                }

                terr = new Territory();
                terr.es.Connection.Name = "ForeignKeyTest";

                if (terr.LoadByPrimaryKey(terrKey))
                {
                    terr.MarkAsDeleted();
                    terr.Save();
                }
            }
        }
Esempio n. 2
0
        public void TestSaveWithAutoKey()
        {
            int       terrKey = -1;
            Territory terr    = new Territory();

            terr.es.Connection.Name = "ForeignKeyTest";
            TerritoryEx terrEx = new TerritoryEx();

            terrEx.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    terr.Description = "Some New Territory";

                    terrEx       = terr.TerritoryEx;
                    terrEx.Notes = "Test Group";

                    terr.Save();

                    terrKey = terr.TerritoryID.Value;

                    Assert.IsTrue(terr.TerritoryEx.es.HasData);
                    Assert.AreEqual(terr.TerritoryID.Value, terrEx.TerritoryID.Value);

                    terr = new Territory();
                    terr.es.Connection.Name = "ForeignKeyTest";

                    Assert.IsTrue(terr.LoadByPrimaryKey(terrKey));
                    Assert.IsTrue(terr.TerritoryEx.es.HasData);
                }
            }
            finally
            {
                // Clean up
                terr = new Territory();
                terr.es.Connection.Name = "ForeignKeyTest";

                if (terr.LoadByPrimaryKey(terrKey))
                {
                    terrEx = terr.TerritoryEx;
                    terrEx.MarkAsDeleted();
                    terr.MarkAsDeleted();
                    terr.Save();
                }
            }
        }
        public void TestSettingNull()
        {
            Employee emp = new Employee();

            emp.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    emp.LoadByPrimaryKey(5);
                    Assert.AreEqual(0, emp.UpToTerritoryCollection.Count);

                    Territory terr = new Territory();
                    terr.es.Connection.Name = "ForeignKeyTest";

                    terr.LoadByPrimaryKey(1);

                    emp.AssociateTerritoryCollection(terr);
                    emp.Save();

                    Assert.AreEqual(0, emp.UpToTerritoryCollection.Count);
                    emp.UpToTerritoryCollection = null;
                    Assert.AreEqual(1, emp.UpToTerritoryCollection.Count);
                }
            }
            finally
            {
                // Clean up
                emp = new Employee();
                emp.es.Connection.Name = "ForeignKeyTest";

                if (emp.LoadByPrimaryKey(5))
                {
                    foreach (Territory t in emp.UpToTerritoryCollection)
                    {
                        emp.DissociateTerritoryCollection(t);
                    }
                    emp.Save();
                }
            }
        }