コード例 #1
0
 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();
 }
コード例 #2
0
 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'");
        }
コード例 #4
0
        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);
        }
コード例 #5
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>();
            }
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
        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>();
            }
        }