Click here to Skip to main content
15,881,803 members
Articles / Programming Languages / C#

ObjectLounge - An Object-Oriented Database Framework

Rate me:
Please Sign up or sign in to vote.
4.07/5 (8 votes)
30 Jul 2009LGPL310 min read 43.6K   425   45  
Host your Domain Models "Out Of The Box" + No storage or schema needed + Transactions on Domain Models + Validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technewlogic.ObjectLounge.Test.Model;
using NUnit.Framework;
using Technewlogic.ObjectLounge.Framework.BaseConcerns;
using Technewlogic.ObjectLounge.Framework.Proxy;

namespace Technewlogic.ObjectLounge.Test
{
	public class C_ChangeTracking_CompositeLinkTests : BaseTest
	{
		#region Add

		[Test]
		public void Add_NewParent_NewChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order newOrder = GetNewOrder();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(newMaterial);
				});

			AssertAllEmpty();
		}

		[Test]
		public void Add_NewParent_NewChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order newOrder = GetNewOrder();
			Material oldMaterial = GetOldMaterial();
			Order oldParentOrder = oldMaterial.Order;

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(oldMaterial);
				});

			AssertInserted();
			AssertUpdated(oldParentOrder);
			AssertDeleted(oldMaterial);
		}

		[Test]
		public void Add_NewParent_OldChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order oldOrder = GetOldOrder();
			Customer oldParentCustomer = oldOrder.Customer;
			Material oldMaterial = oldOrder.Materials.Single(); // wird auch mitgelöscht
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(oldOrder);
					oldOrder.Materials.Add(newMaterial);
				});

			AssertInserted();
			AssertUpdated(oldParentCustomer);
			AssertDeleted(oldOrder, oldMaterial);
		}

		[Test]
		public void Add_NewParent_OldChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order oldOrder = GetOldOrder();
			Customer oldParentCustomer = oldOrder.Customer;
			Material oldMaterial = GetOldMaterial();

			_engine.ExecuteTransaction(() =>
				newCustomer.Orders.Add(oldOrder));

			AssertInserted();
			AssertUpdated(oldParentCustomer);
			AssertDeleted(oldOrder, oldMaterial);
		}

		[Test]
		public void Add_OldParent_NewChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order newOrder = GetNewOrder();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					oldCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(newMaterial);
				});

			AssertInserted(newOrder, newMaterial);
			AssertUpdated(oldCustomer);
			AssertDeleted();
		}

		[Test]
		public void Add_OldParent_NewChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order newOrder = GetNewOrder();
			Material oldMaterial = GetOldMaterial();
			Order oldParentOrder = oldMaterial.Order;

			_engine.ExecuteTransaction(() =>
				{
					newOrder.Materials.Add(oldMaterial);
					oldCustomer.Orders.Add(newOrder);
				});

			AssertInserted(newOrder);
			AssertUpdated(oldParentOrder, oldCustomer, oldMaterial);
			AssertDeleted();
		}

		[Test]
		public void Add_OldParent_OldChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			// Man kann hier nicht die CMMS-Order nehmen, weil sie schon im oldCustomer ist
			Order oldOrder = _context.Orders.Single(it => it.OrderID == Order.BillingSystemID);
			Customer oldParentCustomer = oldOrder.Customer;
			var orderChild1 = oldOrder.Materials.First();
			var orderChild2 = oldOrder.Materials.Last();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					oldOrder.Materials.Add(newMaterial);
					oldCustomer.Orders.Add(oldOrder);
				});

			AssertInserted(newMaterial);
			AssertUpdated(oldCustomer, oldOrder, oldParentCustomer, orderChild1, orderChild2); // IMP: Wenn RemoveForRelocate richtig funktionieren würde, wäre die Children nicht drin.
			AssertDeleted();
		}

		[Test]
		public void Add_OldParent_OldChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			// Man kann hier nicht die CMMS-Order nehmen, weil sie schon im oldCustomer ist
			Order oldOrder = _context.Orders.Single(it => it.OrderID == Order.BillingSystemID);
			Customer oldParentCustomer = oldOrder.Customer;
			var orderChild1 = oldOrder.Materials.First();
			var orderChild2 = oldOrder.Materials.Last();
			Material oldMaterial = GetOldMaterial(); // Dieses Material war nicht in oldOrder drin.
			Order oldParentOrder = oldMaterial.Order;

			_engine.ExecuteTransaction(() =>
				{
					oldOrder.Materials.Add(oldMaterial);
					oldCustomer.Orders.Add(oldOrder);
				});

			AssertInserted();
			AssertUpdated(oldCustomer, oldOrder, oldParentCustomer, oldMaterial, oldParentOrder, orderChild1, orderChild2); // IMP: Wenn RemoveForRelocate richtig funktionieren würde, wäre die Children nicht drin.
			AssertDeleted();
		}

		#endregion

		#region Remove

		[Test]
		public void Remove_NewParent_NewChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order newOrder = GetNewOrder();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(newMaterial);
					newCustomer.Orders.Remove(newOrder);
				});

			AssertAllEmpty();
		}

		[Test]
		public void Remove_NewParent_NewChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order newOrder = GetNewOrder();
			Material oldMaterial = GetOldMaterial();
			Order oldParentOrder = oldMaterial.Order;

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(oldMaterial);
					newCustomer.Orders.Remove(newOrder);
				});

			AssertInserted();
			AssertUpdated(oldParentOrder);
			AssertDeleted(oldMaterial);
		}

		[Test]
		public void Remove_NewParent_OldChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order oldOrder = GetOldOrder();
			Customer oldParentCustomer = oldOrder.Customer;
			Material oldAncestor = oldOrder.Materials.Single();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(oldOrder);
					oldOrder.Materials.Add(newMaterial);
					newCustomer.Orders.Remove(oldOrder);
				});

			AssertInserted();
			AssertUpdated(oldParentCustomer);
			AssertDeleted(oldOrder, oldAncestor);
		}

		[Test]
		public void Remove_NewParent_OldChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer newCustomer = GetNewCustomer();
			Order oldOrder = GetOldOrder();
			Customer oldParentCustomer = oldOrder.Customer;
			Material oldMaterial = GetOldMaterial();

			_engine.ExecuteTransaction(() =>
				{
					newCustomer.Orders.Add(oldOrder);
					newCustomer.Orders.Remove(oldOrder);
				});

			AssertInserted();
			AssertUpdated(oldParentCustomer);
			AssertDeleted(oldOrder, oldMaterial);
		}

		[Test]
		public void Remove_OldParent_NewChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order newOrder = GetNewOrder();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					oldCustomer.Orders.Add(newOrder);
					newOrder.Materials.Add(newMaterial);
					oldCustomer.Orders.Remove(newOrder);
				});

			AssertInserted();
			AssertUpdated(oldCustomer);
			AssertDeleted();
		}

		[Test]
		public void Remove_OldParent_NewChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order newOrder = GetNewOrder();
			Material oldMaterial = GetOldMaterial();
			Order oldParentOrder = oldMaterial.Order;

			_engine.ExecuteTransaction(() =>
				{
					newOrder.Materials.Add(oldMaterial);
					oldCustomer.Orders.Add(newOrder);
					oldCustomer.Orders.Remove(newOrder);
				});

			AssertInserted();
			AssertUpdated(oldCustomer, oldParentOrder);
			AssertDeleted(oldMaterial);
		}

		[Test]
		public void Remove_OldParent_OldChild_NewAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order oldOrder = GetOldOrder();
			Material oldAncestor = oldOrder.Materials.Single();
			Material newMaterial = GetNewMaterial();

			_engine.ExecuteTransaction(() =>
				{
					oldOrder.Materials.Add(newMaterial);
					oldCustomer.Orders.Remove(oldOrder);
				});

			AssertInserted();
			AssertUpdated(oldCustomer);
			AssertDeleted(oldOrder, oldAncestor);
		}

		[Test]
		public void Remove_OldParent_OldChild_OldAncestor()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();
			Order oldOrder = GetOldOrder();
			Material oldMaterial = GetOldMaterial();

			_engine.ExecuteTransaction(() =>
				oldCustomer.Orders.Remove(oldOrder));

			AssertInserted();
			AssertUpdated(oldCustomer);
			AssertDeleted(oldOrder, oldMaterial);
		}

		#endregion

		/// <summary>
		/// Exemplarisch für die Rekursion.
		/// </summary>
		[Test]
		public void PropertyChange_OldParent_OldChildren()
		{
			throw new NotImplementedException();

			Customer oldCustomer = GetOldCustomer();

			_engine.ExecuteTransaction(() =>
				oldCustomer.Name += "4711");

			AssertInserted();
			AssertUpdated(oldCustomer);
			AssertDeleted();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) www.technewlogic.de
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions