public async Task UpdateComputedAsync() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; Assert.True(await db.InsertAsync(p)); if (p.FullName != null) { Assert.Equal("Alice Jones", p.FullName); } p.FirstName = "Greg"; p.LastName = "Smith"; p.CreatedOn = DateTime.UtcNow; Assert.True(await db.UpdateAsync(p)); if (p.FullName != null) { Assert.Equal("Greg Smith", p.FullName); } var gp = await db.GetAsync <PersonExcludedColumns>(p.IdentityId); Assert.Equal(p.IdentityId, gp.IdentityId); Assert.Null(gp.Notes); Assert.InRange(gp.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.InRange(gp.UpdatedOn.Value, dnow.AddMinutes(-1), dnow.AddMinutes(1)); // to cover clock skew, delay in DML, etc. Assert.Equal(p.FirstName, gp.FirstName); Assert.Equal(p.LastName, gp.LastName); } }
public void InsertComputed() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; Assert.True(db.Insert(p)); if (p.FullName != null) { Assert.Equal("Alice Jones", p.FullName); } var gp = db.Get <PersonExcludedColumns>(p.IdentityId); Assert.Equal(p.IdentityId, gp.IdentityId); Assert.Null(gp.Notes); Assert.Null(gp.UpdatedOn); Assert.InRange(gp.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.Equal(p.FirstName, gp.FirstName); Assert.Equal(p.LastName, gp.LastName); } }
public async Task UpsertPartialCallbacksAsync() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones" }; Assert.True(await db.UpsertAsync(p, (i) => i.CreatedOn = dnow, (u) => u.UpdatedOn = dnow)); Assert.True(p.IdentityId > 0); p.FirstName = "Greg"; p.LastName = "Smith"; p.CreatedOn = DateTime.UtcNow; Assert.True(await db.UpsertAsync(p, new[] { "LastName", "CreatedOn", "UpdatedOn" }, (i) => i.CreatedOn = dnow, (u) => u.UpdatedOn = dnow)); var gp = await db.GetAsync <PersonExcludedColumns>(p.IdentityId); Assert.Equal(p.IdentityId, gp.IdentityId); Assert.Equal("Alice", gp.FirstName); Assert.Equal("Smith", gp.LastName); Assert.InRange(gp.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.InRange(gp.UpdatedOn.Value, dnow.AddMinutes(-1), dnow.AddMinutes(1)); // to cover clock skew, delay in DML, etc. } }
public async Task UpsertListComputedAsync() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var q = new PersonExcludedColumns { FirstName = "Raj", LastName = "Padilla", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var r = new PersonExcludedColumns { FirstName = "Lidia", LastName = "Bain", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var s = new PersonExcludedColumns { FirstName = "Derren", LastName = "Southern", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var lst = new List <PersonExcludedColumns> { p, q, r }; Assert.True(await db.UpsertListAsync(lst)); p.FirstName = "Emily"; q.FirstName = "Jim"; r.FirstName = "Laura"; lst.Add(s); Assert.True(await db.UpsertListAsync(lst)); if (p.FullName != null) { Assert.Equal("Emily Jones", p.FullName); Assert.Equal("Jim Padilla", q.FullName); Assert.Equal("Laura Bain", r.FullName); Assert.Equal("Derren Southern", s.FullName); } var gp = await db.GetAsync <PersonExcludedColumns>(p.IdentityId); Assert.Equal(p.IdentityId, gp.IdentityId); Assert.Null(gp.Notes); Assert.InRange(gp.UpdatedOn.Value, dnow.AddMinutes(-1), dnow.AddMinutes(1)); // to cover clock skew, delay in DML, etc. Assert.InRange(gp.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.Equal(p.FirstName, gp.FirstName); Assert.Equal(p.LastName, gp.LastName); var gs = await db.GetAsync <PersonExcludedColumns>(s.IdentityId); Assert.Equal(s.IdentityId, gs.IdentityId); Assert.Null(gs.Notes); Assert.Null(gs.UpdatedOn); // to cover clock skew, delay in DML, etc. Assert.InRange(gs.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.Equal(s.FirstName, gs.FirstName); Assert.Equal(s.LastName, gs.LastName); } }
public async Task InsertListComputedAsync() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var q = new PersonExcludedColumns { FirstName = "Raj", LastName = "Padilla", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; var r = new PersonExcludedColumns { FirstName = "Lidia", LastName = "Bain", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; Assert.True(await db.InsertListAsync(new List <PersonExcludedColumns> { p, q, r })); if (p.FullName != null) { Assert.Equal("Alice Jones", p.FullName); Assert.Equal("Raj Padilla", q.FullName); Assert.Equal("Lidia Bain", r.FullName); } var gp = await db.GetAsync <PersonExcludedColumns>(p.IdentityId); Assert.Equal(p.IdentityId, gp.IdentityId); Assert.Null(gp.Notes); Assert.Null(gp.UpdatedOn); Assert.InRange(gp.CreatedOn.Value, dnow.AddSeconds(-1), dnow.AddSeconds(1)); // to cover fractional seconds rounded up/down (amounts supported between databases vary, but should all be ±1 second at most. ) Assert.Equal(p.FirstName, gp.FirstName); Assert.Equal(p.LastName, gp.LastName); } }