FirebirdDBTestProvider.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.IO;
  2. using System.Text;
  3. using FirebirdSql.Data.FirebirdClient;
  4. using FirebirdSql.Data.Isql;
  5. namespace PetaPoco.Tests.Integration.Databases.Firebird
  6. {
  7. public class FirebirdDBTestProvider : DBTestProvider
  8. {
  9. protected override string ConnectionName => "Firebird";
  10. protected override string ScriptResourceName => "PetaPoco.Tests.Integration.Scripts.FirebirdDbBuildDatabase.sql";
  11. public override IDatabase Execute()
  12. {
  13. var db = Database;
  14. FbScript script;
  15. using (var s = GetType().Assembly.GetManifestResourceStream(ScriptResourceName))
  16. {
  17. using (var r = new StreamReader(s, Encoding.UTF8))
  18. {
  19. script = new FbScript(r.ReadToEnd());
  20. script.Parse();
  21. }
  22. }
  23. try
  24. {
  25. using (var con = new FbConnection(db.ConnectionString))
  26. {
  27. con.Open();
  28. }
  29. }
  30. catch
  31. {
  32. FbConnection.CreateDatabase(db.ConnectionString);
  33. }
  34. using (var con = new FbConnection(db.ConnectionString))
  35. {
  36. var be = new FbBatchExecution(con);
  37. be.AppendSqlStatements(script);
  38. be.Execute();
  39. }
  40. return db;
  41. }
  42. }
  43. }