public void TestHasData()
		{
			Assert.IsFalse(aggTestColl.HasData);

			Assert.IsTrue(aggTestColl.LoadAll());
			Assert.AreEqual(30, aggTestColl.Count);
			Assert.IsTrue(aggTestColl.HasData);

			aggTestColl = new AggregateTestCollection();
			Assert.IsFalse(aggTestColl.HasData);
			Assert.IsFalse(aggTest.es.HasData);

			aggTest = aggTestColl.AddNew();
			Assert.IsTrue(aggTestColl.HasData);
			Assert.IsTrue(aggTest.es.HasData);

			aggTest = new AggregateTest();
			Assert.IsFalse(aggTest.es.HasData);
            aggTest.Age = 40;
			Assert.IsTrue(aggTest.es.HasData);
		}
		public static void RefreshDatabase(string connectionName)
		{
            AggregateTestCollection aggTestColl = new AggregateTestCollection();
			if (connectionName.Length != 0)
			{
				aggTestColl.es.Connection.Name = connectionName;
			}

			aggTestColl.LoadAll();
            aggTestColl.MarkAllAsDeleted();
			aggTestColl.Save();

			aggTestColl = new AggregateTestCollection();
			AggregateTest aggTest = new AggregateTest();
			if (connectionName.Length != 0)
			{
				aggTestColl.es.Connection.Name = connectionName;
				aggTest.es.Connection.Name = connectionName;
			}

            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "David";
            aggTest.str().LastName = "Doe";
            aggTest.str().Age = "16";
            aggTest.str().HireDate = "2000-02-16 05:59:31";
            aggTest.str().Salary = "34.71";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "1";
            aggTest.str().FirstName = "Sarah";
            aggTest.str().LastName = "McDonald";
            aggTest.str().Age = "28";
            aggTest.str().HireDate = "1999-03-25 00:00:00";
            aggTest.str().Salary = "11.06";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "David";
            aggTest.str().LastName = "Vincent";
            aggTest.str().Age = "43";
            aggTest.str().HireDate = "2000-10-17 00:00:00";
            aggTest.str().Salary = "10.27";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "2";
            aggTest.str().FirstName = "Fred";
            aggTest.str().LastName = "Smith";
            aggTest.str().Age = "15";
            aggTest.str().HireDate = "1999-03-15 00:00:00";
            aggTest.str().Salary = "15.15";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Sally";
            aggTest.str().LastName = "Johnson";
            aggTest.str().Age = "30";
            aggTest.str().HireDate = "2000-10-07 00:00:00";
            aggTest.str().Salary = "14.36";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "5";
            aggTest.str().FirstName = "Jane";
            aggTest.str().LastName = "Rapaport";
            aggTest.str().Age = "44";
            aggTest.str().HireDate = "2002-05-02 00:00:00";
            aggTest.str().Salary = "13.56";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "Paul";
            aggTest.str().LastName = "Gellar";
            aggTest.str().Age = "16";
            aggTest.str().HireDate = "2000-09-27 00:00:00";
            aggTest.str().Salary = "18.44";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "2";
            aggTest.str().FirstName = "John";
            aggTest.str().LastName = "Jones";
            aggTest.str().Age = "31";
            aggTest.str().HireDate = "2002-04-22 00:00:00";
            aggTest.str().Salary = "17.65";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Michelle";
            aggTest.str().LastName = "Johnson";
            aggTest.str().Age = "45";
            aggTest.str().HireDate = "2003-11-14 00:00:00";
            aggTest.str().Salary = "16.86";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "2";
            aggTest.str().FirstName = "David";
            aggTest.str().LastName = "Costner";
            aggTest.str().Age = "17";
            aggTest.str().HireDate = "2002-04-11 00:00:00";
            aggTest.str().Salary = "21.74";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "William";
            aggTest.str().LastName = "Gellar";
            aggTest.str().Age = "32";
            aggTest.str().HireDate = "2003-11-04 00:00:00";
            aggTest.str().Salary = "20.94";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Sally";
            aggTest.str().LastName = "Rapaport";
            aggTest.str().Age = "39";
            aggTest.str().HireDate = "2002-04-01 00:00:00";
            aggTest.str().Salary = "25.82";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "5";
            aggTest.str().FirstName = "Jane";
            aggTest.str().LastName = "Vincent";
            aggTest.str().Age = "18";
            aggTest.str().HireDate = "2003-10-25 00:00:00";
            aggTest.str().Salary = "25.03";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "2";
            aggTest.str().FirstName = "Fred";
            aggTest.str().LastName = "Costner";
            aggTest.str().Age = "33";
            aggTest.str().HireDate = "1998-05-20 00:00:00";
            aggTest.str().Salary = "24.24";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "1";
            aggTest.str().FirstName = "John";
            aggTest.str().LastName = "Johnson";
            aggTest.str().Age = "40";
            aggTest.str().HireDate = "2003-10-15 00:00:00";
            aggTest.str().Salary = "29.12";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Michelle";
            aggTest.str().LastName = "Rapaport";
            aggTest.str().Age = "19";
            aggTest.str().HireDate = "1998-05-10 00:00:00";
            aggTest.str().Salary = "28.32";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "Sarah";
            aggTest.str().LastName = "Doe";
            aggTest.str().Age = "34";
            aggTest.str().HireDate = "1999-12-03 00:00:00";
            aggTest.str().Salary = "27.53";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "William";
            aggTest.str().LastName = "Jones";
            aggTest.str().Age = "41";
            aggTest.str().HireDate = "1998-04-30 00:00:00";
            aggTest.str().Salary = "32.41";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "1";
            aggTest.str().FirstName = "Sarah";
            aggTest.str().LastName = "McDonald";
            aggTest.str().Age = "21";
            aggTest.str().HireDate = "1999-11-23 00:00:00";
            aggTest.str().Salary = "31.62";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "Jane";
            aggTest.str().LastName = "Costner";
            aggTest.str().Age = "28";
            aggTest.str().HireDate = "1998-04-20 00:00:00";
            aggTest.str().Salary = "36.50";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "2";
            aggTest.str().FirstName = "Fred";
            aggTest.str().LastName = "Douglas";
            aggTest.str().Age = "42";
            aggTest.str().HireDate = "1999-11-13 00:00:00";
            aggTest.str().Salary = "35.71";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Sarah";
            aggTest.str().LastName = "Jones";
            aggTest.str().Age = "22";
            aggTest.str().HireDate = "2001-06-07 00:00:00";
            aggTest.str().Salary = "34.91";
            aggTest.str().IsActive = "false";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "3";
            aggTest.str().FirstName = "Michelle";
            aggTest.str().LastName = "Doe";
            aggTest.str().Age = "29";
            aggTest.str().HireDate = "1999-11-03 00:00:00";
            aggTest.str().Salary = "39.79";
            aggTest.str().IsActive = "true";
            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "4";
            aggTest.str().FirstName = "Paul";
            aggTest.str().LastName = "Costner";
            aggTest.str().Age = "43";
            aggTest.str().HireDate = "2001-05-28 00:00:00";
            aggTest.str().Salary = "39.00";
            aggTest.str().IsActive = "true";

            aggTest = aggTestColl.AddNew();
            aggTest.str().DepartmentID = "0";
            aggTest.str().FirstName = "";
            aggTest.str().LastName = "";
            aggTest.str().Age = "0";
            aggTest.str().Salary = "0";

            aggTest = aggTestColl.AddNew();
            aggTest = aggTestColl.AddNew();
            aggTest = aggTestColl.AddNew();
            aggTest = aggTestColl.AddNew();
            aggTest = aggTestColl.AddNew();

            aggTestColl.Save();

        }
        public void TestDeleteOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();
            aggTest.FirstName = "Mike";

            aggTestColl.AcceptChanges();
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's mark it as deleted
            aggTest.MarkAsDeleted();
            Assert.IsTrue(aggTestColl.IsDirty);
        }
        public void TestTrueIsDirtyLogicOnCollection()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();
            aggTest.FirstName = "Mike";

            aggTestColl.AcceptChanges();
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's change it
            aggTest.FirstName = "Joe";
            Assert.IsTrue(aggTestColl.IsDirty);

            // Now let's set it back to it's original value
            aggTest.FirstName = "Mike";
            Assert.IsFalse(aggTestColl.IsDirty);

            // Let's change it again, notice we are no longer dirty now
            aggTest.FirstName = "Joe";
            Assert.IsTrue(aggTestColl.IsDirty);
        }
        public void TestRejectChangesOnCollection2()
        {
            aggTestColl = new AggregateTestCollection();

            AggregateTest aggTest = aggTestColl.AddNew();
            aggTest.FirstName = "Mike";

            aggTestColl.AcceptChanges();

            Assert.IsFalse(aggTestColl.IsDirty);

            aggTest.FirstName = "Joe";
            aggTest.RejectChanges();

            Assert.IsFalse(aggTestColl.IsDirty);
        }
        public void TestAddNewOnCollection()
        {
            aggTestColl = new AggregateTestCollection();
            Assert.IsFalse(aggTestColl.IsDirty);

            AggregateTest t = aggTestColl.AddNew();
            Assert.IsTrue(aggTestColl.IsDirty);
        }
        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();
            }
        }