public void AllowNullInsert() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var org = new Organization(); org.Name = "My Organization"; var key = db.Insert("Organization", org._AsDictionary()); //Verify that only 1 row exists with the key of this inserted organization Assert.AreEqual(1, db.RawRead("Organization", key).Count()); }
public void Delete() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var person = new Person(); person.FirstName = "bob"; person.LastName = "morris"; var key = db.Insert("Person", person._AsDictionary()); db.Delete("Person", key); Assert.AreEqual(0, db.RawRead("Person", key).Count()); }
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); }
public void Insert() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var contents = db.ReadAll<Person>(); var person = new Person(); person.FirstName = "test"; person.LastName = "person"; db.Insert("Person", person._AsDictionary()); Assert.AreEqual(contents.Count() + 1, db.ReadAll<Person>().Count()); }
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); }
public void CanConnectToDB() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); Assert.IsNull(db.ReadPK("Person", -1)); }
public void Update() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var person = new Person(); person.FirstName = "test"; person.LastName = "person"; var keys = db.Insert("Person", person._AsDictionary()); //Retrieve the saved person so we can verify it saved with our intended data var retrieved = db.RawRead("Person", keys).First(); Assert.AreEqual(person.FirstName, retrieved["FirstName"]); Assert.AreEqual(person.LastName, retrieved["LastName"]); person.FirstName = "newFirst"; person.LastName = "newLastName"; //Update and retrieve the person again so we can verify that the Update worked db.Update("Person", person._AsDictionary(), keys); retrieved = db.RawRead("Person", keys).First(); Assert.AreEqual(person.FirstName, retrieved["FirstName"]); Assert.AreEqual(person.LastName, retrieved["LastName"]); }
public void TransactionSuccessful() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var transaction = db.BeginTransaction(); var person = new Person(); person.FirstName = "test"; person.LastName = "person"; var keys = db.Insert("Person", person._AsDictionary(), transaction); transaction.Commit(); Assert.AreEqual(1, db.RawRead("Person", keys).Count()); }
public void TransactionAbandoned() { var keys = new Dictionary<string, object>(); using (var db = new RealDB(connString, new SQL2005DBAnalyzer(connString))) { var transaction = db.BeginTransaction(); var person = new Person(); person.FirstName = "test"; person.LastName = "person"; keys = db.Insert("Person", person._AsDictionary(), transaction); } var conn = new RealDB(connString, new SQL2005DBAnalyzer(connString)); Assert.AreEqual(0, conn.RawRead("Person", keys).Count()); }
public void RealUpdate() { var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)); var person = new Person(); person.FirstName = "test"; person.LastName = "person"; var keys = db.Insert("Person", person._AsDictionary()); //Retrieve the saved person so we can verify it saved with our intended data var retrieved = db.RawRead("Person", keys).First(); Assert.AreEqual(person.FirstName, retrieved["FirstName"]); Assert.AreEqual(person.LastName, retrieved["LastName"]); person.FirstName = "newFirst"; person.LastName = "newLastName"; //Update and retrieve the person again so we can verify that the Update worked var data = person._AsDictionary().Where(kv => !keys.Keys.Contains(kv.Key)) .ToDictionary(i => i.Key, i => i.Value); db.RealUpdate("Person", data, keys); retrieved = db.RawRead("Person", keys).First(); Assert.AreEqual(person.FirstName, retrieved["FirstName"]); Assert.AreEqual(person.LastName, retrieved["LastName"]); }