12using System.Data.SqlClient;
14using System.Configuration;
17using Microsoft.VisualStudio.TestTools.UnitTesting;
20using TestClass = NUnit.Framework.TestFixtureAttribute;
21using TestInitialize = NUnit.Framework.SetUpAttribute;
22using TestCleanup = NUnit.Framework.TearDownAttribute;
23using TestMethod = NUnit.Framework.TestAttribute;
32 private const string InvalidTestDBConnection =
"DataPortalTestDatabaseConnectionStringXXXXXXX";
37 #region Invalid connection strings
39 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
48 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
57 [ExpectedException(typeof(System.Collections.Generic.KeyNotFoundException))]
67 [ExpectedException(typeof(SqlException))]
69 public void ConnectionSetting_with_Invalid_DB_Throws_ConfigurationErrorsException_for_SqlConnection()
81 [ExpectedException(typeof(SqlException))]
83 public void ConnectionSetting_with_Invalid_DB_Throws_ConfigurationErrorsException_for_LinqToSqlContextDataContext()
87 Assert.IsNotNull(objectContextManager);
89 var count = objectContextManager.DataContext.Table1s.GetNewBindingList().Count;
94 [ExpectedException(typeof(EntityException))]
95 [TestCategory(
"SkipWhenLiveUnitTesting")]
96 public void ConnectionSetting_with_Invalid_DB_Throws_ConfigurationErrorsException_for_EntitiesContextDataContext()
100 Assert.IsNotNull(objectContextManager);
102 var table = (from p in objectContextManager.ObjectContext.Table2
116 public void ExecuteReader_on_Table2_returns_reader_with_3_fields()
120 Assert.IsNotNull(objectContextManager);
121 using (var command =
new SqlCommand(
"Select * From Table2", objectContextManager.Connection))
123 command.CommandType = CommandType.Text;
125 Assert.IsTrue(reader.FieldCount == 3,
"Did not get reader");
134 public void Table1_retreived_through_LingToSqlDataContext_has_records()
138 Assert.IsNotNull(objectContextManager);
139 Assert.IsTrue(objectContextManager.DataContext.Table1s.GetNewBindingList().Count > 0,
"Data in table is missing");
144 [TestCategory(
"SkipWhenLiveUnitTesting")]
145 public void Table2_retreived_through_LingToEntitiesDataContext_has_records()
149 Assert.IsNotNull(objectContextManager);
151 var query = from p in objectContextManager.ObjectContext.Table2
154 Assert.IsTrue(query.ToList().Count > 0,
"Data in table is missing");
160 #region Transaction Manager
165 public void Using_TransactionManager_Insert_of_2records_rolls_back_if_second_record_fails_insert()
167 ApplicationContext.LocalContext.Clear();
168 var list = TransactionContextUserList.GetList();
169 int counter = list.Count;
171 list.Add(
new TransactionContextUser
178 list.Add(
new TransactionContextUser
180 FirstName =
"First1",
182 SmallColumn =
"bbbbbbbbbbbbbb"
185 bool gotError =
false;
190 catch (DataPortalException ex)
196 Assert.IsTrue(gotError,
"SQL should have thrown an error");
198 foreach (var r
in ApplicationContext.LocalContext.Keys)
199 if (r.ToString().StartsWith(
"__transaction:"))
201 Assert.AreEqual(0, tCount,
"Transaction context should have been null");
203 list = TransactionContextUserList.GetList();
204 Assert.AreEqual(counter, list.Count,
"Data should not have been saved.");
210 public void Using_TransactionManager_Insert_2records_increases_count_by2_then_removing_them_decreases_count_by2()
212 ApplicationContext.LocalContext.Clear();
213 var list = TransactionContextUserList.GetList();
214 int beforeInsertCount = list.Count;
218 new TransactionContextUser
224 new TransactionContextUser
226 FirstName =
"First1",
235 foreach (var r
in ApplicationContext.LocalContext.Keys)
236 if (r.ToString().StartsWith(
"__transaction:"))
238 Assert.AreEqual(0, tCount,
"Transaction context should have been null");
240 list = TransactionContextUserList.GetList();
241 Assert.AreEqual(beforeInsertCount + 2, list.Count,
"Data should have been saved.");
243 list.Remove(list.Last(o => o.LastName ==
"Last"));
244 list.Remove(list.Last(o => o.LastName ==
"Last"));
249 foreach (var r
in ApplicationContext.LocalContext.Keys)
250 if (r.ToString().StartsWith(
"__transaction:"))
252 Assert.AreEqual(0, tCount,
"Transaction context should have been null");
254 list = TransactionContextUserList.GetList();
255 Assert.AreEqual(beforeInsertCount, list.Count,
"Data should not have been saved.");
260 public void TestTransactionsManaagerConnectionProperty()
264 Assert.AreSame(manager.Connection, manager.Transaction.Connection,
"COnnection is not correct");
265 Assert.IsNotNull(manager.Connection,
"Connection should not be null.");
266 Assert.IsNotNull(manager.Transaction,
"Transaction should not be null.");
Provides an automated way to reuse open database connections within the context of a single data port...
ConnectionManager GetManager(string database)
Gets the ConnectionManager object for the specified database.
Provides an automated way to reuse LINQ data context objects within the context of a single data port...
ContextManager< C > GetManager(string database)
Gets the ContextManager object for the specified database.
Provides an automated way to reuse Entity Framework object context objects within the context of a si...
ObjectContextManager< C > GetManager(string database)
Gets the ObjectContextManager object for the specified database.
This is an IDataReader that 'fixes' any null values before they are returned to our business code.
Provides an automated way to reuse open database connections and associated ADO.NET transactions with...
TransactionManager< C, T > GetManager(string database)
Gets the TransactionManager object for the specified database.
void InvalidConnectionSetting_Throws_ConfigurationErrorsException_for_SqlConnection()
void InvalidConnectionSetting_Throws_ConfigurationErrorsException_for_EntitiesContextDataContext()
void InvalidConnectionSetting_Throws_ConfigurationErrorsException_for_LinqToSqlContextDataContext()
static string DataPortalTestDatabase
static string DataPortalTestDatabaseWithInvalidDBValue