func RunFindAll(TM ITransactionManager, t *testing.T) { ResetDB(TM) // get the database context store := TM.Store() // the target entity var books []Book err := store.FindAll(&books, Book{PublisherId: ext.Int64(2)}) if err != nil { t.Fatalf("Failed RunFindAll: %s", err) } if len(books) != 2 { t.Fatalf("Failed RunFindAll: Expected 2 books, got %s", len(books)) } }
func RubFindFirst(TM ITransactionManager, t *testing.T) { ResetDB(TM) // get the database context store := TM.Store() // the target entity var book Book ok, err := store.FindFirst(&book, Book{PublisherId: ext.Int64(1)}) if err != nil { t.Fatalf("Failed RubFindFirst: %s", err) } if !ok { t.Fatalf("Failed RubFindFirst: Expected 1 books, got none.") } }
func RunStructUpdate(TM ITransactionManager, t *testing.T) { ResetDB(TM) var err error if err = TM.Transaction(func(store IDb) error { var publisher Publisher publisher.Name = ext.String("Untited Editors") publisher.Id = ext.Int64(1) publisher.Version = 1 affectedRows, err := store.Update(PUBLISHER).Submit(&publisher) // passing as a pointer if err != nil { t.Fatalf("Failed RunStructUpdate: %s", err) } if affectedRows != 1 { t.Fatal("The record was not updated") } if publisher.Version != 2 { t.Fatalf("Expected Version = 2, got %v", publisher.Version) } publisher.Name = ext.String("Super Duper Test") ok, err := store.Modify(&publisher) if err != nil { t.Fatalf("Failed RunStructUpdate: %s", err) } if !ok { t.Fatal("The record was not Modifyied") } if publisher.Version != 3 { t.Fatalf("Expected Version = 3, got %v", publisher.Version) } return nil }); err != nil { t.Fatalf("Failed Update Test: %s", err) } }
func RunStructDelete(TM ITransactionManager, t *testing.T) { ResetDB(TM) if err := TM.Transaction(func(store IDb) error { // clears any relation with book id = 2 store.Delete(AUTHOR_BOOK).Where(AUTHOR_BOOK_C_BOOK_ID.Matches(2)).Execute() store.Delete(BOOK_BIN).Where(BOOK_BIN_C_ID.Matches(2)).Execute() var book Book book.Id = ext.Int64(2) book.Version = 1 affectedRows, err := store.Delete(BOOK).Submit(book) if err != nil { t.Fatalf("Failed RunStructDelete (id=2): %s", err) } if affectedRows != 1 { t.Fatal("The record was not deleted") } // short version // clears any relation with book id = 3 store.Delete(AUTHOR_BOOK).Where(AUTHOR_BOOK_C_BOOK_ID.Matches(3)).Execute() store.Delete(BOOK_BIN).Where(BOOK_BIN_C_ID.Matches(3)).Execute() *book.Id = 3 var ok bool ok, err = store.Remove(book) if err != nil { t.Fatalf("Failed RunStructDelete (id=3): %s", err) } if !ok { t.Fatal("The record was not deleted") } return nil }); err != nil { t.Fatalf("Failed ... Test: %s", err) } }
func NewIdVersionDTO() IdVersionDTO { this := IdVersionDTO{} this.Version = ext.Int64(1) return this }