public async Task UpdateComputedAsync() { var dnow = DateTime.UtcNow; using (var connection = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones", Notes = "Hello", CreatedOn = dnow, UpdatedOn = dnow }; Assert.True(await connection.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 connection.UpdateAsync(p)); if (p.FullName != null) { Assert.Equal("Greg Smith", p.FullName); } var gp = await connection.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 void UpsertPartialCallbacks() { var dnow = DateTime.UtcNow; using (var db = GetSqlDatabase()) { var p = new PersonExcludedColumns { FirstName = "Alice", LastName = "Jones" }; Assert.True(db.Upsert(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(db.Upsert(p, new[] { "LastName", "CreatedOn", "UpdatedOn" }, (i) => i.CreatedOn = dnow, (u) => u.UpdatedOn = dnow)); var gp = db.Get <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. } }