public void QueryToIEnumerableTest() { SqlDataAccess data = new SqlDataAccess(STR_ConnectionString); var swatch = new Stopwatch(); swatch.Start(); var enumerable = data.Query<WebLogEntry>("select * from ApplicationLog"); var recs = new List<WebLogEntry>(); foreach (var entry in enumerable) { recs.Add(entry); } swatch.Stop(); Assert.IsNotNull(recs, "Null"); Assert.IsTrue(recs.Count > 0, "Count < 1"); Assert.IsTrue(recs[0].Entered > DateTime.MinValue); Console.WriteLine(swatch.ElapsedMilliseconds); Console.WriteLine(recs.Count); }
public void QueryWithNoMatchingDataTest() { SqlDataAccess data = new SqlDataAccess(STR_ConnectionString); // no records returned from query var entries = data.Query<WebLogEntry>("select * from ApplicationLog where 1=2"); var ent = entries.ToList(); Console.WriteLine(ent.Count); Assert.IsNotNull(entries, "IEnumerable should not be null - only null on failure."); }
public void QueryToCustomer() { using (var data = new SqlDataAccess(STR_ConnectionString)) { var custList = data.Query<Customer>("select * from customers where LastName like @0", "S%"); Assert.IsNotNull(custList, data.ErrorMessage); foreach (var customer in custList) { Console.WriteLine(customer.Company + " " + customer.Entered); } } }
public void QueryTest() { using (var data = new SqlDataAccess(STR_ConnectionString)) { var swatch = Stopwatch.StartNew(); var logEntries = data.Query<WebLogEntry>( "select * from ApplicationLog where entered > @0 and entered < @1 order by Entered", DateTime.Now.AddYears(-115), DateTime.Now.AddYears(-1)).ToList(); Assert.IsNotNull(logEntries, data.ErrorMessage); Console.WriteLine(logEntries.Count); foreach (var logEntry in logEntries) { Console.WriteLine(logEntry.Entered); } swatch.Stop(); Console.WriteLine(swatch.ElapsedMilliseconds + "ms"); } }
public void QueryException() { using (var data = new SqlDataAccess(STR_ConnectionString) { ThrowExceptions = true }) { try { var logEntries = data.Query<WebLogEntry>("select * from ApplicationLogggg"); Assert.Fail("Invalid Sql Statement should not continue"); } catch (Exception ex) { Console.WriteLine("Error caught correctly: " + ex.Message); } } }
public void NewParametersExecuteEntityTest() { using (var data = new SqlDataAccess(STR_ConnectionString)) { //var cmd = data.CreateCommand("select * from ApplicationLog where entered > @0 and entered > @1",CommandType.Text, DateTime.Now.AddYears(-10), DateTime.Now.AddYears(-)); //var table = data.ExecuteTable("TLogs", cmd); var swatch = Stopwatch.StartNew(); var entries = data.Query<WebLogEntry>( "select * from ApplicationLog where entered > @0 and entered < @1 order by Entered", DateTime.Now.AddYears(-115), DateTime.Now.AddYears(-1)); var logEntries = entries.ToList(); Assert.IsNotNull(logEntries, data.ErrorMessage); Console.WriteLine(logEntries.Count); foreach (var logEntry in logEntries) { Console.WriteLine(logEntry.Entered); } swatch.Stop(); Console.WriteLine(swatch.ElapsedMilliseconds + "ms"); } }
public void ExecuteDataReaderToListTest() { SqlDataAccess data = new SqlDataAccess(STR_ConnectionString); var swatch = new Stopwatch(); swatch.Start(); var recs = data.Query<WebLogEntry>("select * from ApplicationLog").ToList(); swatch.Stop(); Assert.IsNotNull(recs, "Null"); Assert.IsTrue(recs.Count > 0, "Count < 1"); Assert.IsTrue(recs[0].Entered > DateTime.MinValue); Console.WriteLine(swatch.ElapsedMilliseconds); Console.WriteLine(recs.Count); }