public void ReadAll() { var db = ConnectTo.Sql2005(Config.TestDBConnectionString); var results = db.ReadAll<Person>(); int actualCount = int.MinValue; using (var conn = new SqlConnection(Config.TestDBConnectionString)) { actualCount = conn.ExecuteSingleValue<int>("select count(*) from Person"); } Assert.AreEqual(results.Count(), actualCount); }
public void ReadAllCustomFields() { var db = ConnectTo.Sql2005(Config.TestDBConnectionString); db.Insert("Person", new Person { FirstName = "Foo" }); var desiredColumns = new List<string>(){ "PersonId", "FirstName" }; var results = db.ReadAll("Person", desiredColumns); int actualCount = int.MinValue; using (var conn = new SqlConnection(Config.TestDBConnectionString)) { actualCount = conn.ExecuteSingleValue<int>("select count(*) from Person"); } //Make sure we get all of the rows in the table Assert.AreEqual(results.Count(), actualCount); //Make sure we only got the columns we requested rather than entire rows Assert.AreEqual(results.First().Keys.ToList(), desiredColumns); }
public void ReadAllCustomFields() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var desiredColumns = new List<string>(){ "PersonId", "FirstName" }; var results = db.RawReadAllCustomFields("Person", desiredColumns); int actualCount = int.MinValue; using (var conn = new SqlConnection(connString)) { actualCount = conn.ExecuteSingleValue<int>("select count(*) from Person"); } //Make sure we get all of the rows in the table Assert.AreEqual(results.Count(), actualCount); //Make sure we only got the columns we requested rather than entire rows Assert.AreEqual(results.First().Keys.ToList(), desiredColumns); }
private int? sqlInsert(string sql, ITransaction transaction, Dictionary<string, object> values = null) { if (values == null) values = new Dictionary<string, object>(); //If no transaction is passed in we will make our own connection if (transaction == null) { using (var conn = new SqlConnection(connectionString)) { return conn.ExecuteSingleValue<int?>(sql, values); } } //If a transaction is passed in we will use the global connection else { var command = new SqlCommand(sql, _conn, (transaction as RealDBTransaction).UnderlyingTransaction); return command.ExecuteSingleValue<int?>(sql, values); } }
public void ReadAll() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var results = db.ReadAll<Person>(); int actualCount = int.MinValue; using (var conn = new SqlConnection(connString)) { actualCount = conn.ExecuteSingleValue<int>("select count(*) from Person"); } Assert.AreEqual(results.Count(), actualCount); }