public void CreateStatementsTests(SqlTestData.ExpectedTable expectedTable)
        {
            Assert.True(SqlParser.TryParse(expectedTable.Sql, out SqlTableDefinition definition));
            Assert.NotNull(definition);

            SqlTestData.Compare(definition, expectedTable);
        }
예제 #2
0
        public void CreateStatementsTests(string file, string tableName, SqlTestData.ExpectedTable expectedTable)
        {
            Assert.True(SqlParser.TryParse(expectedTable.Sql, out SqlTableDefinition definition));
            Assert.NotNull(definition);

            SqlTestData.Compare(definition, expectedTable);

            // To create new dumps:
            //using var sw = new StreamWriter(@"N:\Git\Personal\MBW.Utilities.ManagedSqlite\src\MBW.Utilities.ManagedSqlite.Sql.Tests\Data\From_Windows11ActivityDb.new.txt", true);
            //SqlTestData.AppendActual(sw, expectedTable.Sql, definition);
        }
예제 #3
0
        public void ReadCreateStatementsFromDbTests(string dbFile, SqlTestData data)
        {
            Assembly assembly = typeof(SqlCreateStatements).Assembly;

            using (MemoryStream ms = new MemoryStream())
            {
                using (Stream fs = assembly.GetManifestResourceStream(dbFile))
                    using (GZipStream gz = new GZipStream(fs, CompressionMode.Decompress))
                    {
                        gz.CopyTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                    }

                // Ensure that the DB matches the expectations
                using (Sqlite3Database db = new Sqlite3Database(ms))
                {
                    List <Sqlite3SchemaRow> dbTables = db.GetTables().Where(s => !s.TableName.StartsWith("sqlite_", StringComparison.Ordinal)).Where(s => s.Type == "table").ToList();

                    Assert.Equal(data.Statements.Count, dbTables.Count);

                    List <string> dbTableNames        = dbTables.Select(s => s.TableName).ToList();
                    List <string> expectedTabledNames = data.Statements.Select(s => s.Name).ToList();

                    Assert.All(dbTableNames, x => Assert.Contains(x, expectedTabledNames));
                    Assert.All(expectedTabledNames, x => Assert.Contains(x, dbTableNames));

                    Assert.All(dbTables, tbl =>
                    {
                        SqlTestData.ExpectedTable expected = data.Statements.First(s => s.Name == tbl.TableName);
                        SqlTableDefinition definition      = tbl.GetTableDefinition();

                        SqlTestData.Compare(definition, expected);
                    });
                }
            }
        }