Click here to Skip to main content
15,896,063 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 44K   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;

namespace Technewlogic.ObjectLounge.Test
{
	[TestFixture]
	public class BaseTest
	{
		protected Engine<CrmContext> _engine;
		protected CrmContext _context;
		protected DataContextMockSyncProvider _syncProvider;

		[TestFixtureSetUp]
		public virtual void TestFixtureSetUp()
		{
		}

		[SetUp]
		public virtual void SetUp()
		{
			_context = new CrmContext();
			_syncProvider = new DataContextMockSyncProvider(new DataContextMock());
			_engine = EngineFactory.CreateEngine(_syncProvider, _context);
		}

		[TearDown]
		public virtual void TearDown()
		{
			try
			{
				_engine.Close();
			}
			catch { }
		}

		#region Helper Methods

		protected Customer GetOldCustomer()
		{
			return _context.Customers.Single(it => it.Name == Customer.SKName);
		}

		protected Customer GetNewCustomer()
		{
			var newCustomer = _engine.CreateInstance<Customer>();
			newCustomer._name = Customer.NewName;
			return newCustomer;
		}

		protected Order GetOldOrder()
		{
			return _context.Orders.Single(it => it.OrderID == Order.CmmsID);
		}

		protected Order GetNewOrder()
		{
			var newOrder = _engine.CreateInstance<Order>();
			newOrder._orderID = Order.NewID;
			return newOrder;
		}

		protected OrderType GetOldOrderType()
		{
			return _context.OrderTypes.Single(it => it.Name == OrderType.HighPriorityName);
		}

		protected OrderType GetNewOrderType()
		{
			var newOrderType = _engine.CreateInstance<OrderType>();
			newOrderType._name = OrderType.NewName;
			return newOrderType;
		}

		protected Material GetOldMaterial()
		{
			return _context.Materials.Single(m => m.DefinitionID == Material.HardwareServerDefinitionID);
		}

		protected Material GetNewMaterial()
		{
			var newMaterial = _engine.CreateInstance<Material>();
			newMaterial._definitionID = "NewMaterial";
			return newMaterial;
		}

		protected OrderTypeCompositor GetOldOrderTypeCompositor()
		{
			return _context.OrderTypeCompositors.Single(it => it.Name == OrderTypeCompositor.StandardCompositorName);
		}

		protected OrderTypeCompositor GetNewOrderTypeCompositor()
		{
			var newCompositor = _engine.CreateInstance<OrderTypeCompositor>();
			newCompositor._name = OrderTypeCompositor.NewCompositorName;
			return newCompositor;
		}

		protected void AssertAllEmpty()
		{
			AssertSyncStateCollection(new object[] { }, _syncProvider.Inserted);
			AssertSyncStateCollection(new object[] { }, _syncProvider.Updated);
			AssertSyncStateCollection(new object[] { }, _syncProvider.Deleted);
		}

		protected void AssertInserted(params object[] inserted)
		{
			AssertSyncStateCollection(inserted, _syncProvider.Inserted);
		}

		protected void AssertUpdated(params object[] updated)
		{
			AssertSyncStateCollection(updated, _syncProvider.Updated);
		}

		protected void AssertDeleted(params object[] deleted)
		{
			AssertSyncStateCollection(deleted, _syncProvider.Deleted);
		}

		private void AssertSyncStateCollection(
			IEnumerable<object> expected, List<IUnitOfWorkConcern> syncList)
		{
			if (expected == null)
				expected = new List<object>();

			Assert.AreEqual(expected.Count(), syncList.Count);
			foreach (var it in expected)
				Assert.AreEqual(it, syncList.Single(it2 => it2 == it));
		}

		#endregion
	}
}

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