public void Execute_with_missing_param(string paramName) { using var db = new SQLiteDatastore(); db.Invoking(x => x.Execute($"Select {paramName};", "'hello world'")) .Should().Throw <SQLException>() .And.CommandText.Should().NotBeNullOrEmpty(); }
public void Query_With_Invalid_SQL() { using (var ds = new SQLiteDatastore()) { ds.Invoking(x => x.Query <POCOMultiTypeObject>("Invalid SQL;").ToArray()) .Should().Throw <SQLException>(); } }
public void Execute_with_param() { using var db = new SQLiteDatastore(); db.Invoking(x => x.ExecuteScalar <string>("Select ?;", "'hello world'")) .Should().Throw <SQLException>() .And.CommandText.Should().NotBeNullOrEmpty(); // var result = db.ExecuteScalar<string>("Select ?;", "'hello world'"); }
protected void VerifySQLiteDatastore(SQLiteDatastore ds) { ds.Should().NotBeNull(); ds.Exists.Should().BeTrue(); ds.Invoking(x => x.Execute("EXPLAIN SELECT 1;")).Should().NotThrow(); ds.GetRowCount("sqlite_master", null, null).Should().BeGreaterThan(0); }
public void ReadOnly_Throws_On_BeginTransaction() { var path = _testReadOnlyPath; Output.WriteLine(path); using (var ds = new SQLiteDatastore(path)) { ds.Execute(TestDBBuilder.CREATE_AUTOINCREMENT_TABLE); ds.CreateTable("Tbl", new ColumnInfo[] { new ColumnInfo() { Name = "Data", DBType = System.Data.DbType.String } }, false); System.IO.File.Exists(path).Should().BeTrue(); System.IO.File.SetAttributes(path, System.IO.FileAttributes.ReadOnly); ds.Invoking(x => x.BeginTransaction()).Should().Throw <ReadOnlyException>(); } }
public void CreateTableTest() { using (var ds = new SQLiteDatastore()) { var cols = new ColumnInfo[] { new ColumnInfo("ID", System.Data.DbType.Int64) { AutoIncrement = true }, new ColumnInfo("Field1", System.Data.DbType.AnsiString) }; ds.CreateTable("TableA", cols, false); ds.Invoking(x => x.Execute("EXPLAIN SELECT * FROM TableA;")).Should().NotThrow(); ds.CheckTableExists("TableA").Should().BeTrue(); } }
public void ReadOnly_Throws_On_Insert() { var path = _testReadOnlyPath; Output.WriteLine(path); using (var ds = new SQLiteDatastore(path)) { ds.Execute(TestDBBuilder.CREATE_AUTOINCREMENT_TABLE); ds.CreateTable("Tbl", new ColumnInfo[] { new ColumnInfo() { Name = "Data", DBType = System.Data.DbType.String } }, false); System.IO.File.Exists(path).Should().BeTrue(); System.IO.File.SetAttributes(path, System.IO.FileAttributes.ReadOnly); //TODO assert that connection is not open and transaction depth is 0 ds.Invoking(x => x.Execute("INSERT INTO Tbl (Data) VALUES ('something');")).Should().Throw <ReadOnlyException>(); } }