public async Task Insert_InTransaction() { SqliteDb.OpenConnection(() => { var tr = SqliteDb.DbConnection.BeginTransaction(); DbAdapter.Transaction = tr; // insert var newCompany = new CompanyModelAnnotated(); newCompany.Id = 5000; // should be ignored newCompany.Name = null; DbAdapter.Insert(newCompany); Assert.True(newCompany.Id.HasValue && newCompany.Id.Value != 5000); Assert.Equal(1, DbAdapter.Select(new Query("companies", (QField)"title" == DBNull.Value).Select(QField.Count)).Single <int>()); tr.Rollback(); // do not save }); }
public async Task InsertUpdateDelete_PocoModelAsync() { // insert var newCompany = new CompanyModelAnnotated(); newCompany.Id = 5000; // should be ignored newCompany.Name = "Test Super Corp"; newCompany.registered = false; // should be ignored Assert.Equal(1, await DbAdapter.InsertAsync(newCompany).ConfigureAwait(false)); Assert.True(newCompany.Id.HasValue); Assert.NotEqual(5000, newCompany.Id.Value); Assert.Equal("Test Super Corp", DbAdapter.Select(new Query("companies", (QField)"id" == (QConst)newCompany.Id.Value).Select("title")).Single <string>()); newCompany.Name = "Super Corp updated"; Assert.Equal(1, await DbAdapter.UpdateAsync(newCompany).ConfigureAwait(false)); Assert.Equal(newCompany.Name, DbAdapter.Select(new Query("companies", (QField)"id" == (QConst)newCompany.Id.Value).Select("title")).Single <string>()); Assert.Equal(1, await DbAdapter.DeleteAsync(newCompany).ConfigureAwait(false)); }
public void InsertUpdateDelete_PocoModel() { // insert var newCompany = new CompanyModelAnnotated(); newCompany.Id = 5000; // should be ignored newCompany.Name = "Test Super Corp"; newCompany.registered = false; // should be ignored newCompany.Logo = new byte[] { 1, 2, 3 }; // lets assume this is sample binary data DbAdapter.Insert(newCompany); Assert.True(newCompany.Id.HasValue); Assert.NotEqual(5000, newCompany.Id.Value); Assert.Equal("Test Super Corp", DbAdapter.Select(new Query("companies", (QField)"id" == (QConst)newCompany.Id.Value).Select("title")).Single <string>()); newCompany.Name = "Super Corp updated"; Assert.Equal(1, DbAdapter.Update(newCompany)); Assert.Equal(newCompany.Name, DbAdapter.Select(new Query("companies", (QField)"id" == (QConst)newCompany.Id.Value).Select("title")).Single <string>()); Assert.Equal(1, DbAdapter.Delete(newCompany)); }