public void TestCompositeForeignKey() { Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; cust.LoadByPrimaryKey("01001", "001"); Assert.AreEqual(3, cust.OrderCollectionByCustID.Count); }
public void TestMultiDeleteEntity() { int empKey = -1; int ordKey = -1; CustomerGroup custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; EmployeeCollection empColl = new EmployeeCollection(); empColl.es.Connection.Name = "ForeignKeyTest"; Employee emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; Employee testEmp = new Employee(); testEmp.es.Connection.Name = "ForeignKeyTest"; Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Order ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; try { using (esTransactionScope scope = new esTransactionScope()) { // Setup custGroup.GroupID = "YYYYY"; custGroup.GroupName = "Test"; custGroup.Save(); emp = empColl.AddNew(); emp.LastName = "LastName"; emp.FirstName = "FirstName"; cust = emp.CustomerCollectionByStaffAssigned.AddNew(); cust.CustomerID = "YYYYY"; cust.CustomerSub = "YYY"; cust.CustomerName = "Test"; cust.str().DateAdded = "2007-01-01 00:00:00"; cust.Active = true; cust.Manager = 1; ord = emp.OrderCollectionByEmployeeID.AddNew(); ord.CustID = "YYYYY"; ord.CustSub = "YYY"; ord.str().OrderDate = "2007-01-01"; empColl.Save(); empKey = emp.EmployeeID.Value; ordKey = ord.OrderID.Value; Assert.AreEqual(1, emp.CustomerCollectionByStaffAssigned.Count); Assert.AreEqual(1, emp.OrderCollectionByEmployeeID.Count); Assert.AreEqual(emp.EmployeeID.Value, cust.StaffAssigned.Value); Assert.AreEqual(emp.EmployeeID.Value, ord.EmployeeID.Value); // Test testEmp.LoadByPrimaryKey(empKey); testEmp.OrderCollectionByEmployeeID.MarkAllAsDeleted(); testEmp.CustomerCollectionByStaffAssigned.MarkAllAsDeleted(); testEmp.MarkAsDeleted(); testEmp.Save(); emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(emp.LoadByPrimaryKey(empKey)); ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(ord.LoadByPrimaryKey(ordKey)); cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Assert.IsFalse(cust.LoadByPrimaryKey("YYYYY", "YYY")); } } finally { // Clean up ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; if (ord.LoadByPrimaryKey(ordKey)) { ord.MarkAsDeleted(); ord.Save(); } cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; if (cust.LoadByPrimaryKey("YYYYY", "YYY")) { cust.MarkAsDeleted(); cust.Save(); } emp = new Employee(); emp.es.Connection.Name = "ForeignKeyTest"; if (emp.LoadByPrimaryKey(empKey)) { emp.MarkAsDeleted(); emp.Save(); } custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; if (custGroup.LoadByPrimaryKey("YYYYY")) { custGroup.MarkAsDeleted(); custGroup.Save(); } } }
public void TestSaveComposite() { int ordKey = -1; CustomerGroup custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; Customer cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; Order ord = new Order(); ord.es.Connection.Name = "ForeignKeyTest"; try { using (esTransactionScope scope = new esTransactionScope()) { custGroup.GroupID = "XXXXX"; custGroup.GroupName = "Test"; custGroup.Save(); cust.CustomerID = "XXXXX"; cust.CustomerSub = "XXX"; cust.CustomerName = "Test"; cust.str().DateAdded = "2007-01-01 00:00:00"; cust.Active = true; cust.Manager = 1; ord = cust.OrderCollectionByCustID.AddNew(); ord.str().OrderDate = "2007-12-31 00:00:00"; cust.Save(); ordKey = ord.OrderID.Value; Assert.AreEqual(1, cust.OrderCollectionByCustID.Count); } } finally { // Clean up cust = new Customer(); cust.es.Connection.Name = "ForeignKeyTest"; if (cust.LoadByPrimaryKey("XXXXX", "XXX")) { OrderCollection ordColl = cust.OrderCollectionByCustID; ordColl.MarkAllAsDeleted(); cust.MarkAsDeleted(); cust.Save(); } custGroup = new CustomerGroup(); custGroup.es.Connection.Name = "ForeignKeyTest"; if (custGroup.LoadByPrimaryKey("XXXXX")) { custGroup.MarkAsDeleted(); custGroup.Save(); } } }