Click here to Skip to main content
15,897,518 members
Articles / Hosted Services / Azure

Kerosene ORM: a dynamic, configuration-less and self-adaptive ORM for POCO objects supporting a SQL-like syntax from C#

Rate me:
Please Sign up or sign in to vote.
4.96/5 (71 votes)
1 Mar 2015CPOL35 min read 549.5K   4.6K   212  
The seventh version of the dynamic, configuration-less and self-adaptive Kerosene ORM library, that provides full real support for POCO objects, natural SQL-like syntax from C#, and advanced capabilities while being extremely easy to use.
// ======================================================== Test_DataLink.cs
namespace Kerosene.ORM.Direct.Test
{
	using Kerosene.Tools;
	using Microsoft.VisualStudio.TestTools.UnitTesting;
	using System;
	using System.Linq;

	// ==================================================== 
	[TestClass]
	public class Test_DataLink
	{
		[TestMethod]
		public void Create_With_Engine_And_Without_ConnectionString()
		{
			Direct.EngineFactory.InitializeEngines();

			var engine = Direct.EngineFactory.Locate();
			var link = Direct.LinkFactory.Create(engine);
			Assert.IsNotNull(link);
			Assert.IsNull(link.ConnectionString);
			ConsoleEx.WriteLine("\n> Link: {0}", link);

			try { link.Open(); Assert.Fail(); } // Because null string
			catch (InvalidOperationException) { }
		}

		[TestMethod]
		public void Create_From_Partial_Engine_Name()
		{
			Direct.EngineFactory.InitializeEngines();

			var link = Direct.LinkFactory.Create("SqlClient");
			Assert.IsNotNull(link);
			Assert.IsNull(link.ConnectionString);
			ConsoleEx.WriteLine("\n> Link: {0}", link);

			try { link.Open(); Assert.Fail(); }
			catch (InvalidOperationException) { }
		}

		[TestMethod]
		public void Create_With_Engine_Name_And_Connection_String()
		{
			Direct.EngineFactory.InitializeEngines();

			var link = Direct.LinkFactory.Create("SqlClient",
				"Server=localhost;Database=KeroseneDB;Integrated Security=true");

			Assert.IsNotNull(link);
			Assert.IsNotNull(link.ConnectionString);
			ConsoleEx.WriteLine("\n> Link: {0}", link);
			ConsoleEx.WriteLine("- Connection String: {0}", link.ConnectionString);

			link.Open();
			link.Close();
		}

		[TestMethod]
		public void Create_From_Default_Entry()
		{
			Direct.EngineFactory.InitializeEngines();

			var link = Direct.LinkFactory.Create();

			Assert.IsNotNull(link);
			Assert.IsNotNull(link.ConnectionString);
			ConsoleEx.WriteLine("\n> Link: {0}", link);
			ConsoleEx.WriteLine("- Connection String: {0}", link.ConnectionString);

			link.Open();
			link.Dispose();
		}
	}
}
// ======================================================== 

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 Code Project Open License (CPOL)


Written By
Spain Spain
mbarbac has worked in start-ups, multinational tech companies, and consulting ones, serving as CIO, CTO, SW Development Director, and Consulting Director, among many other roles.

Solving complex puzzles and getting out of them business value has ever been among his main interests - and that's why he has spent his latest 25 years trying to combine his degree in Theoretical Physics with his MBA... and he is still trying to figure out how all these things can fit together.

Even if flying a lot across many countries, along with the long working days that are customary in IT management and Consultancy, he can say that, after all, he lives in Spain (at least the weekends).

Comments and Discussions