diff HowTo/Data/OpenConfig2.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HowTo/Data/OpenConfig2.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,68 @@
+using System;
+using System.Data;
+
+using NUnit.Framework;
+
+using BLToolkit.Data;
+
+namespace HowTo.Data
+{
+	[TestFixture]
+	public class OpenConfig2
+	{
+		const string sqlConnectionString =
+			"Server=.;Database=BLToolkitData;Integrated Security=SSPI";
+		const string oleDbConnectionString =
+			"Provider=SQLOLEDB;Data Source=.;Integrated Security=SSPI;Initial Catalog=BLToolkitData";
+
+		[Test]
+		public void Test1()
+		{
+			string defaultConfiguration = DbManager.DefaultConfiguration;
+			DbManager.DefaultConfiguration = ""; //to reset possible previous changes
+
+			try
+			{
+				/*[a]*/DbManager.AddConnectionString/*[/a]*/(
+					sqlConnectionString);   // connection string
+
+				using (DbManager db = /*[a]*/new DbManager()/*[/a]*/)
+				{
+					Assert.AreEqual(ConnectionState.Open, db.Connection.State);
+				}
+			}
+			finally
+			{
+				DbManager.DefaultConfiguration = defaultConfiguration; // to restore previous settings
+			}
+
+		}
+
+		[Test]
+		public void Test2()
+		{
+			/*[a]*/DbManager.AddConnectionString/*[/a]*/(
+				"NewConfig",            // configuration string
+				sqlConnectionString);   // connection string
+
+			using (DbManager db = /*[a]*/new DbManager("NewConfig")/*[/a]*/)
+			{
+				Assert.AreEqual(ConnectionState.Open, db.Connection.State);
+			}
+		}
+
+		[Test]
+		public void Test3()
+		{
+			/*[a]*/DbManager.AddConnectionString/*[/a]*/(
+				"OleDb",                // provider name
+				"NewConfig",            // configuration string
+				oleDbConnectionString); // connection string
+
+			using (DbManager db = /*[a]*/new DbManager("OleDb", "NewConfig")/*[/a]*/)
+			{
+				Assert.AreEqual(ConnectionState.Open, db.Connection.State);
+			}
+		}
+	}
+}