public void Apply(string connectionString) { FbDatabase database = new FbDatabase(connectionString); Up(database); QueryParameters parameters = new QueryParameters("id", Id); parameters.Add("dateMigration", DateTime.Now); database.ExecuteQuery(Common.InsertMigrationInfo, parameters); }
public void TearDown() { if (_temporaryDatabase == null) { return; } FbDatabase.DropDatabase(_temporaryDatabase.ConnectionString); _temporaryDatabase.Dispose(); _temporaryDatabase = null; }
public void SqlDatabaseCreationWorksWithConnectionString() { // --- Arrange var connStr = ConfigurationManager.ConnectionStrings["Seemplest"].ConnectionString; // --- Act var db = new FbDatabase(connStr); // --- Assert db.ConnectionOrName.ShouldEqual(connStr); db.ConnectionString.ShouldEqual(connStr); }
public async Task InsertAsyncWithNullRaisesException() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); await db.InsertAsync <SampleRecord>(null); }
public void UpdateWithNullRaisesException() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act db.Update <SampleRecord>(null); }
public void ExecuteFailsWithInvalidParameters() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act db.Execute(@"select ""Id"" from ""sample"" where ""Id""=@0", "hello"); }
public async Task PageAsyncWorksAsExpected() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); for (var i = 1; i <= 13; i++) { await db.InsertAsync(new SampleRecord { Id = i, Name = "Record " + i }); } // --- Act var sqlExpr = SqlExpression.New.Select <SampleRecord>().From <SampleRecord>().OrderBy(@"""Id"""); var page1 = await db.PageAsync <SampleRecord>(0, 6, sqlExpr); var page2 = await db.PageAsync <SampleRecord>(1, 6, sqlExpr); var page3 = await db.PageAsync <SampleRecord>(2, 6, sqlExpr); var page4 = await db.PageAsync <SampleRecord>(3, 6, sqlExpr); // --- Assert page1.CurrentPage.ShouldEqual(0); page1.ItemsPerPage.ShouldEqual(6); page1.Items.ShouldHaveCountOf(6); page1.TotalItems.ShouldEqual(13); page1.TotalPages.ShouldEqual(3); page2.CurrentPage.ShouldEqual(1); page2.ItemsPerPage.ShouldEqual(6); page2.Items.ShouldHaveCountOf(6); page2.TotalItems.ShouldEqual(13); page2.TotalPages.ShouldEqual(3); page3.CurrentPage.ShouldEqual(2); page3.ItemsPerPage.ShouldEqual(6); page3.Items.ShouldHaveCountOf(1); page3.TotalItems.ShouldEqual(13); page3.TotalPages.ShouldEqual(3); page4.CurrentPage.ShouldEqual(3); page4.ItemsPerPage.ShouldEqual(6); page4.Items.ShouldHaveCountOf(0); page4.TotalItems.ShouldEqual(13); page4.TotalPages.ShouldEqual(3); }
public void InvalidMappingRaisesAnException() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" blob not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act db.Fetch <SampleRecordWithEnum>(); }
public void SingleRaisesExceptionWithMoreThanOneRecord() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act db.Single <SampleRecord>(@"where ""Id"" < 10"); }
public void ExecuteScalarWorksWithNullResult() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act var rows = db.ExecuteScalar <int?>(@"select ""Name"" from ""sample"""); // --- Assert rows.ShouldBeNull(); }
private void OnEnable() { m_fbDatabase = m_gameManager.GetComponent <FbDatabase>(); m_IPAs = LoadLocalDatabase(); m_currentImageIndex = m_IPAs.Count - 1; m_nextButton.interactable = true; m_previousButton.interactable = true; ProcessCurrentFrame(); CheckNext(); CheckPrevious(); }
private int GetCurrentDbVersion() { FbDatabase database = new FbDatabase(ConnectionString); int isReadyForMigration = (int)database.ExecuteScalar(Common.CheckMigrationReady); if (isReadyForMigration == 0) { PrepareDatabase(database); } object lastId = database.ExecuteScalar(Common.GetLastMigrationId); return(lastId == null || DBNull.Value.Equals(lastId) ? 0 : (int)lastId); }
public void DisposeClosesOpenConnection() { // --- Arrange var db = new FbDatabase(DB_CONN, executeMode: SqlDirectExecuteMode.Disable); var disposed = false; db.OpenSharedConnection(); db.Connection.Disposed += (sender, args) => disposed = true; // -- Act db.Dispose(); // --- Assert disposed.ShouldBeTrue(); }
public void UpdateWithNoPkRaisesException() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); var record = new SampleRecordWithNoPk { Name = "First" }; // --- Act db.Update(record); }
public void ExecuteWorksWithParameters() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act db.Execute(@"insert into ""sample"" values(@0, @1)", 1, "hello"); var name = db.ExecuteScalar <string>(@"select ""Name"" from ""sample"" where ""Id""=1"); // --- Assert name.ShouldEqual("hello"); }
public void PageAutomaticallyAddsSelect() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); for (var i = 1; i <= 13; i++) { db.Insert(new SampleRecord { Id = i, Name = "Record " + i }); } // --- Act var sqlExpr = SqlExpression.New.From <SampleRecord>().Where(@"""Id"" > 0"); var page1 = db.Page <SampleRecord>(0, 6, sqlExpr); var page2 = db.Page <SampleRecord>(1, 6, sqlExpr); var page3 = db.Page <SampleRecord>(2, 6, sqlExpr); var page4 = db.Page <SampleRecord>(3, 6, sqlExpr); // --- Assert page1.CurrentPage.ShouldEqual(0); page1.ItemsPerPage.ShouldEqual(6); page1.Items.ShouldHaveCountOf(6); page1.TotalItems.ShouldEqual(13); page1.TotalPages.ShouldEqual(3); page2.CurrentPage.ShouldEqual(1); page2.ItemsPerPage.ShouldEqual(6); page2.Items.ShouldHaveCountOf(6); page2.TotalItems.ShouldEqual(13); page2.TotalPages.ShouldEqual(3); page3.CurrentPage.ShouldEqual(2); page3.ItemsPerPage.ShouldEqual(6); page3.Items.ShouldHaveCountOf(1); page3.TotalItems.ShouldEqual(13); page3.TotalPages.ShouldEqual(3); page4.CurrentPage.ShouldEqual(3); page4.ItemsPerPage.ShouldEqual(6); page4.Items.ShouldHaveCountOf(0); page4.TotalItems.ShouldEqual(13); page4.TotalPages.ShouldEqual(3); }
public async Task SingleByIdAsyncRaisesExceptionWhenNoRecordFound() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id1"" int not null, ""Id2"" int not null, ""Name"" varchar(50), ""Description"" varchar(50))"); await db.CompleteTransactionAsync(); await db.InsertAsync(new SampleRecordWithMultiplePk { Id1 = 1, Id2 = 2, Name = "First" }); await db.InsertAsync(new SampleRecordWithMultiplePk { Id1 = 1, Id2 = 3, Name = "Second" }); // --- Act await db.SingleByIdAsync <SampleRecordWithMultiplePk>(2, 3); }
public void SimplePocoRaisesExceptionWithDelete() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); var record = new SimplePoco { Id = 1, Name = "First" }; db.Insert(record); // --- Act db.Delete(record); }
public void SimpleFetchWorksAsExpected() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act var rows = db.Fetch <SampleRecord>(); // --- Assert rows.ShouldHaveCountOf(2); }
public async Task DeleteAsyncWithNoPkRaisesException() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); var record = new SampleRecordWithNoPk { Name = "First" }; // --- Act await db.DeleteAsync(record); }
public void InvalidConverterRaisesException() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); var record = new SampleRecordWithInvalidConverter { Id = 1, Name = new List <string> { "1", "2", "3", "4" } }; // --- Act db.Insert(record); }
public static void InitializeClass(TestContext context) { var dc = new FbDatabase(DB_CONN); dc.Execute( @"EXECUTE BLOCK AS BEGIN if (exists(select 1 from rdb$relations where rdb$relation_name = 'Data')) then execute statement 'drop table ""Data"";'; END"); dc.Execute( @"create table ""Data"" ( ""Id"" int not null, ""Name"" varchar(64) not null, constraint ""pk_data"" primary key(""Id"") )"); }
public async Task SingleAsyncRaisesExceptionWithZeroRecord() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); await db.ExecuteAsync(@"insert into ""sample"" values(1, 'First')"); await db.ExecuteAsync(@"insert into ""sample"" values(2, 'Second')"); // --- Act await db.SingleAsync <SampleRecord>(@"where ""Id"" = 3"); }
public void ExecuteScalarWorksWithDbNullResult() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act var value1 = db.ExecuteScalar <int?>(@"select max(""Id"") from ""sample"""); var value2 = db.ExecuteScalar <int?>(@"select count(*) from ""sample"""); // --- Assert value1.ShouldBeNull(); value2.ShouldNotBeNull(); }
public async Task DeleteByIdAsyncWorksWithCancellation() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); await db.InsertAsync(new SampleRecord { Id = 1, Name = "First" }); var cts = new CancellationTokenSource(); // --- Act cts.Cancel(); await db.DeleteByIdAsync <SampleRecord>(cts.Token, 1); }
public async Task PageAsyncWorksWithZeroRecord() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); for (var i = 1; i <= 13; i++) { await db.InsertAsync(new SampleRecord { Id = i, Name = "Record " + i }); } // --- Act const string SQL_EXPR = @"select * from ""sample"" group by ""Id"", ""Name"" having sum(""Id"") > 100000"; await db.PageAsync <SampleRecord>(0, 6, SQL_EXPR); }
public void UnusedSourceConverterIsSkipped() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act var rows = db.Fetch <SampleRecordUnusedConverter>(@"order by ""Id"""); // --- Assert rows.ShouldHaveCountOf(2); rows[0].Name.ShouldEqual("First"); rows[1].Name.ShouldEqual("Second"); }
public async Task SimplePocoRaisesExceptionWithUpdateAsync() { // --- Arrange var db = new FbDatabase(DB_CONN); await db.BeginTransactionAsync(); await db.ExecuteAsync(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); await db.CompleteTransactionAsync(); var record = new SimplePoco { Id = 1, Name = "First" }; await db.InsertAsync(record); // --- Act record.Name = "NewFirst"; await db.UpdateAsync(record); }
public void ExecuteWithSqlStringWorks() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); // --- Act db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); var rows = db.ExecuteScalar <int>(@"select count(*) from ""sample"""); db.Execute(@"drop table ""sample"""); // --- Assert rows.ShouldEqual(2); }
public void FetchWorksWithMissingClrField() { // --- Arrange var db = new FbDatabase(DB_CONN); db.BeginTransaction(); db.Execute(@"create table ""sample"" (""Id"" int not null, ""Name"" varchar(50))"); db.CompleteTransaction(); db.Execute(@"insert into ""sample"" values(1, 'First')"); db.Execute(@"insert into ""sample"" values(2, 'Second')"); // --- Act var rows = db.Fetch <SampleRecordWithMissingField>( @"select ""Id"", ""Name"" from ""sample"" order by ""Name"""); // --- Assert rows.ShouldHaveCountOf(2); rows[0].Name.ShouldEqual("First"); rows[1].Name.ShouldEqual("Second"); }