public void GetRecordVersion() { var db = new PostulateDb(); db.DeleteOneWhere <TableB>("[Description]='Yadda Yadda'", null); int[] orgIds; using (var cn = db.GetConnection()) { cn.Open(); orgIds = cn.Query <int>("SELECT [Id] FROM [Organization]").ToArray(); } var itemB = new TableB() { Description = "Yadda Yadda", OrganizationId = orgIds[0] }; db.Save(itemB); itemB.OrganizationId = orgIds[1]; db.Save(itemB); int version; db.Find <TableB>(itemB.Id, out version); Assert.IsTrue(version == 2); }
private static void InitTestRecords(out PostulateDb db, out TableB[] tableBItems) { db = new PostulateDb(); db.GetConnection().Execute("DELETE [TableB] WHERE [Description] IN ('whatever', 'this thing', 'circumscribed', 'least confident')"); tableBItems = new TableB[] { new TableB() { Description = "whatever", OrganizationId = 1, CreatedBy = "adamo" }, new TableB() { Description = "this thing", OrganizationId = 1, CreatedBy = "adamo" }, new TableB() { Description = "circumscribed", OrganizationId = 1, CreatedBy = "adamo" }, new TableB() { Description = "least confident", OrganizationId = 1, CreatedBy = "adamo" } }; }
public void DropTestTables() { var db = new PostulateDb(); using (IDbConnection cn = db.GetConnection()) { cn.Open(); DropTablesIfExists(cn, "TableA", "TableB", "TableC"); } }
public void CreateDeleteOrg() { Organization org = new Organization(); org.Name = DefaultOrgName(); org.BillingRate = 10; PostulateDb db = new PostulateDb(); db.TraceCallback = (cn, qt) => { QueryUtil.SaveTrace(cn, qt, db); }; using (IDbConnection cn = db.GetConnection()) { cn.Open(); db.Save(cn, org); db.DeleteOne(cn, org); } }
public void TrackTableBChanges() { var db = new PostulateDb(); int[] orgIds = null; using (var cn = db.GetConnection()) { cn.Open(); if (!db.Syntax.TableExists(cn, typeof(TableB))) { CreateTable ct = new CreateTable(db.Syntax, db.Syntax.GetTableInfoFromType(typeof(TableB))); foreach (var cmd in ct.SqlCommands(cn)) { cn.Execute(cmd); } } orgIds = cn.Query <int>("SELECT TOP (2) [Id] FROM [Organization]").ToArray(); } db.DeleteOneWhere <TableB>("[Description]='Whatever'", null); string oldName = db.Find <Organization>(orgIds[0]).Name; string newName = db.Find <Organization>(orgIds[1]).Name; db.TraceCallback = (cn, trace) => { Debug.WriteLine(trace.Sql); }; TableB b = new TableB() { OrganizationId = orgIds[0], Description = "Whatever" }; db.Save(b); b.OrganizationId = orgIds[1]; db.Save(b); var history = db.QueryChangeHistory <TableB>(b.Id); var changes = history.First().Properties.ToDictionary(item => item.PropertyName); Assert.IsTrue(changes["OrganizationId"].OldValue.Equals(oldName) && changes["OrganizationId"].NewValue.Equals(newName)); }
public void FindAndUpdateOrg() { Organization org = new Organization(); org.Name = DefaultOrgName(); org.BillingRate = 10; PostulateDb db = new PostulateDb(); using (IDbConnection cn = db.GetConnection()) { cn.Open(); db.Save(cn, org); org = db.Find <Organization>(cn, org.Id); org.Name = $"Another Sample {DateTime.Now}"; org.BillingRate = 11; db.Save(cn, org); } }
public void TrackTableAChanges() { var db = new PostulateDb(); using (var cn = db.GetConnection()) { cn.Open(); if (!db.Syntax.TableExists(cn, typeof(TableA))) { CreateTable ct = new CreateTable(db.Syntax, db.Syntax.GetTableInfoFromType(typeof(TableA))); foreach (var cmd in ct.SqlCommands(cn)) { cn.Execute(cmd); } } } TableA a = new TableA() { FirstName = "Julio", LastName = "Arragato" }; db.DeleteOneWhere <TableA>("[FirstName]=@FirstName AND [LastName]=@LastName", a); db.DeleteOneWhere <TableA>("[FirstName]=@FirstName AND [LastName]=@LastName", new { FirstName = "Geoffrey", LastName = "Arragato" }); db.Save(a); a.FirstName = "Geoffrey"; db.Save(a); var history = db.QueryChangeHistory <TableA>(a.Id); var changes = history.First().Properties.ToDictionary(item => item.PropertyName); Assert.IsTrue(changes["FirstName"].OldValue.Equals("Julio") && changes["FirstName"].NewValue.Equals("Geoffrey")); }
public void TableDInsertStatement_ShouldIncludeIdentity() { var tableD = new TableD() { FieldOne = "whatever", Id = 0 }; var db = new PostulateDb(); using (var cn = db.GetConnection()) { if (!db.Syntax.TableExists(cn, typeof(TableD))) { var ct = new CreateTable(db.Syntax, new TableInfo("TableD", "dbo", typeof(TableD))); foreach (var cmd in ct.SqlCommands(cn)) { cn.Execute(cmd); } } db.TraceCallback = (cn1, qt) => { Assert.IsTrue(qt.Sql.Equals("hello")); }; db.Save(tableD); } }