public void SerializeDeserializeLoadEntityBinary()
		{
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                int key = 0;
                aggTest.Query.Where(
                    aggTest.Query.LastName == "Douglas",
                    aggTest.Query.FirstName == "Fred");
                aggTest.Query.Load();
                key = aggTest.Id.Value;

                aggTest = new AggregateTest();
                aggTest.LoadByPrimaryKey(key);

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, aggTest);

                ms.Position = 0;
                aggClone = (AggregateTest)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual("Douglas", aggClone.str().LastName);
            }
		}
		public void Init2()
		{
            aggTestColl = new AggregateTestCollection();
            aggTest = new AggregateTest();
            aggTestQuery = new AggregateTestQuery();
			aggCloneColl = new AggregateTestCollection();
			aggClone = new AggregateTest();
			aggCloneQuery = new AggregateTestQuery();
		}
        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 TestRejectChangesOnEntity1()
        {
            aggTest = new AggregateTest();
            aggTest.FirstName = "Mike";
            aggTest.RejectChanges();

            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);
        }
        public void TestAddNewOnEntity()
        {
            aggTest = new AggregateTest();
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 0);
           // Assert.IsTrue(aggTest.es.RowState == esDataRowState.Detached);

            // We set a property which creates the DataTable
            aggTest.FirstName = "Mike";

            Assert.IsTrue(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsFalse(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Added);
        }
        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 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 SerializeDeserializeNewEntityBinary()
		{
            if (aggTest.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                aggTest.LastName = "Griffinski";

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, aggTest);

                ms.Position = 0;
                aggClone = (AggregateTest)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual("Griffinski", aggClone.str().LastName);
            }
		}
		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 AggregateTestProxyStub(AggregateTest obj)
 {
     theEntity = this.entity = obj;
 }
        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 TestCommandTimeoutConfig()
        {
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.SqlClientProvider":
                    // Collection
                    aggTestColl = new AggregateTestCollection();
                    Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                    Assert.IsTrue(aggTestColl.Query.Load(), "Query.Load");
                    aggTestColl = new AggregateTestCollection();
                    Assert.AreEqual(39, aggTestColl.es.Connection.CommandTimeout);
                    Assert.IsTrue(aggTestColl.LoadAll(), "LoadAll");

                    // Entity
                    aggTest = new AggregateTest();
                    Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                    aggTest.Query.es.Top = 1;
                    Assert.IsTrue(aggTest.Query.Load(), "Query.Load");
                    int aggKey = aggTest.Id.Value;
                    aggTest = new AggregateTest();
                    Assert.AreEqual(39, aggTest.es.Connection.CommandTimeout);
                    Assert.IsTrue(aggTest.LoadByPrimaryKey(aggKey), "LoadByPK");
                    break;

                default:
                    Assert.Ignore("tested for SQL Server only");
                    break;
            }
        }
		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 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 AggregateInOrderBy()
		{
            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.MSAccessProvider":
                    Assert.Ignore("Not supported");
					break;

				default:
					aggTestColl.Query
						.Select
						(
							aggTestColl.Query.DepartmentID,
							aggTestColl.Query.Salary.Min()
						)
						.OrderBy
						(
							aggTestColl.Query.Salary.Descending
						)
						.GroupBy
						(
							aggTestColl.Query.DepartmentID
						);
					aggTestColl.Query.Load();
                    break;
			}

            AggregateTest test = new AggregateTest();

            switch (aggTestColl.es.Connection.ProviderSignature.DataProviderName)
            {
                case "EntitySpaces.NpgsqlProvider":
                case "EntitySpaces.Npgsql2Provider":
                case "EntitySpaces.OracleClientProvider":
                    test = (AggregateTest)aggTestColl[1];
                    break;

                default:
                    test = (AggregateTest)aggTestColl[0];
                    break;
            }

			Assert.AreEqual(4, test.DepartmentID.Value);
			Assert.AreEqual(18.44, Math.Round(test.Salary.Value, 2));
		}
        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 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 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 TestTrueIsDirtyLogicOnEntity()
        {
            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 change it
            aggTest.FirstName = "Joe";

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsTrue(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Modified);

            // Now let's set it back to it's original value
            aggTest.FirstName = "Mike";

            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 change it again, notice we are no longer dirty now
            aggTest.FirstName = "Joe";

            Assert.IsFalse(aggTest.es.IsAdded);
            Assert.IsFalse(aggTest.es.IsDeleted);
            Assert.IsTrue(aggTest.es.IsModified);
            Assert.IsTrue(aggTest.es.IsDirty);
            Assert.IsTrue(aggTest.es.ModifiedColumns.Count == 1);
            Assert.IsTrue(aggTest.es.RowState == esDataRowState.Modified);
        }
        public void GetColumnWithAliasEntity()
        {
            AggregateTest entity = new AggregateTest();
            entity.Query.es.CountAll = true;
            entity.Query.es.CountAllAlias = "Count";
            entity.Query.Load();

            Assert.AreEqual(30, Convert.ToInt32(entity.GetColumn("Count")));
        }
        public void ConfigNotReadOnly()
        {
            AggregateTest entity = new AggregateTest();
            Assert.AreEqual("AggregateDb", entity.es.Connection.Name);

            string oldDefault = esConfigSettings.ConnectionInfo.Default;
            esConfigSettings.ConnectionInfo.Default = "ForeignKeyTest";

            entity = new AggregateTest();
            Assert.AreEqual("ForeignKeyTest", entity.es.Connection.Name);

            if (entity.es.Connection.ProviderSignature.DataProviderName == "EntitySpaces.OracleClientProvider")
            {
                Assert.IsTrue(entity.es.Connection.ConnectionString.ToLower().Contains("hierarchical"));
            }
            else
            {
                Assert.IsTrue(entity.es.Connection.ConnectionString.ToLower().Contains("foreignkeytest"));
            }

            entity.es.Connection.ConnectionString = "Test";
            Assert.AreEqual("Test", entity.es.Connection.ConnectionString);

            esConfigSettings.ConnectionInfo.Default = oldDefault;
        }
		public void ChangeMetadata()
		{
			AggregateTest entity = new AggregateTest();

			Assert.IsTrue(entity.GetAutoKey() == true);
			entity.ToggleAutoKey();
			Assert.IsTrue(entity.GetAutoKey() == false);
			entity.ToggleAutoKey();
			Assert.IsTrue(entity.GetAutoKey() == true);
		}
 public AggregateTestProxyStub(AggregateTest obj, bool dirtyColumnsOnly)
 {
     theEntity             = this.entity = obj;
     this.dirtyColumnsOnly = dirtyColumnsOnly;
 }
        public void CollectionChangesBinary()
        {
            if (aggTestColl.es.Connection.Name == "SqlCe")
            {
                Assert.Ignore("Not tested for SqlCe.");
            }
            else
            {
                aggTestColl.LoadAll();
                Assert.AreEqual(30, aggTestColl.Count, "Old");
                aggTestColl.Filter = aggTestColl.AsQueryable().OrderBy(s => s.Id);

                aggTestColl[0].MarkAsDeleted();
                foreach (AggregateTest entity in aggTestColl)
                {
                    if (entity.LastName == "Doe")
                    {
                        entity.LastName = "Changed";
                    }
                }
                aggTest = aggTestColl.AddNew();
                aggTest.LastName = "New";

                int rowCount = 0;
                foreach (AggregateTest r in aggTestColl)
                {
                    if (r.es.IsAdded || r.es.IsModified)
                    {
                        rowCount++;
                    }
                }
                foreach (AggregateTest r in aggTestColl.es.DeletedEntities)
                {
                    rowCount++;
                }
                //aggTestColl.RowStateFilter = DataViewRowState.ModifiedCurrent |
                //    DataViewRowState.Deleted |
                //    DataViewRowState.Added;

                Assert.AreEqual(4, rowCount, "OldFiltered");

                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, aggTestColl);

                ms.Position = 0;
                aggCloneColl = (AggregateTestCollection)bf.Deserialize(ms);
                ms.Close();

                Assert.AreEqual(30, aggCloneColl.Count, "New");

                rowCount = 0;
                foreach (AggregateTest r in aggTestColl)
                {
                    if (r.es.IsAdded|| r.es.IsModified)
                    {
                        rowCount++;
                    }
                }
                foreach (AggregateTest r in aggTestColl.es.DeletedEntities)
                {
                    rowCount++;
                }
                //aggCloneColl.RowStateFilter = DataViewRowState.ModifiedCurrent |
                //    DataViewRowState.Deleted |
                //    DataViewRowState.Added;

                Assert.AreEqual(4, rowCount, "NewFiltered");
            }
        }
        public void SaveTwice_LoadEntity()
        {
            string originalName = "";
            int key = -1;

            using (esTransactionScope scope = new esTransactionScope())
            {
                aggTestColl.LoadAll();
                foreach (AggregateTest agg in aggTestColl)
                {
                    key = agg.Id.Value;
                    break;
                }

                aggTest.LoadByPrimaryKey(key);
                originalName = aggTest.LastName;
                aggTest.LastName = "TestName";
                aggTest.Save();

                aggTest.LastName = "TestName2";
                aggTest.Save();

                aggTest = new AggregateTest();
                aggTest.LoadByPrimaryKey(key);
                Assert.AreEqual("TestName2", aggTest.LastName);

                aggTest.LastName = originalName;
                aggTest.Save();
            }
        }
        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 TestFailedTransaction()
        {
            switch (aggTest.es.Connection.Name)
            {
                case "SQLStoredProcEnterprise":
                case "SQLDynamicEnterprise":
                case "ORACLEStoredProcEnterprise":
                case "ORACLEDynamicEnterprise":
                case "VistaDBDynamic":
                    Assert.Ignore("Using esTransactionScope only");
                    break;

                default:
                    try
                    {
                        aggTest = new AggregateTest();
                        AggregateTest aggTest2 = new AggregateTest();
                        int tempId1 = -1;
                        int tempId2 = -1;
                        aggTest2.str().HireDate = "1/1/1";

                        using (esTransactionScope scope = new esTransactionScope())
                        {
                            try
                            {
                                aggTest.Save();
                                tempId1 = aggTest.Id.Value;
                                aggTest2.Save();
                                tempId2 = aggTest2.Id.Value;

                                throw new Exception();

                                scope.Complete();
                            }
                            catch
                            {
                            }
                        }
                        aggTest = new AggregateTest();
                        Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId1));

                        aggTest = new AggregateTest();
                        Assert.IsFalse(aggTest.LoadByPrimaryKey(tempId2));
                    }
                    catch (Exception ex)
                    {
                        Assert.Fail(ex.ToString());
                    }
                    break;
            }
        }
		public void SerializeDeserializeFindEntityBinary()
		{
            int key = 0;
            aggTestColl.LoadAll();
            foreach (AggregateTest test in aggTestColl)
            {
                if (test.LastName == "Doe")
                {
                    key = test.Id.Value;
                    break;
                }
            }
            aggTest = aggTestColl.FindByPrimaryKey(key);

            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, aggTest);

            ms.Position = 0;
            aggClone = (AggregateTest)bf.Deserialize(ms);
            ms.Close();

            Assert.AreEqual("Doe", aggClone.str().LastName);
		}
		public void Init2()
		{
            aggTestColl = new AggregateTestCollection();
            aggTest = new AggregateTest();
		}
		public void EntityQueryReset()
		{
			aggTest.Query
				.Where
				(
					aggTest.Query.FirstName.Equal("Sarah"),
					aggTest.Query.LastName.Equal("Doe")
				);
			Assert.IsTrue(aggTest.Query.Load());

            aggTest = new AggregateTest();
			aggTest.Query
				.Where
				(
					aggTest.Query.FirstName.Equal("Fred"),
					aggTest.Query.LastName.Equal("Costner")
				);
			aggTest.Query.Load();
			Assert.IsTrue(aggTest.Query.Load());

			Assert.AreEqual("Costner", aggTest.str().LastName);
			Assert.AreEqual("Fred", aggTest.str().FirstName);
		}
        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 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 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);
            }
        }