Exemplo n.º 1
0
        public void TestGetDataTable()
        {
            var fields = new List <string> {
                "Name", "Age", "Birth", "Unknown"
            };
            var list = new List <Person>
            {
                new Person {
                    Name = "Test1", Age = 1, Birth = new DateTime(1999, 6, 10)
                },
                new Person {
                    Name = "Test2", Age = 2, Birth = new DateTime(2000, 8, 15)
                }
            };

            var table = ReflectorHelper.InvokeMethod(new MsSqlToSqlite(), "GetDataTable", fields, list) as DataTable;

            table.Should().NotBeNull();
            table?.Columns.Count.Should().Be(3);
            table?.Columns[0].ColumnName.Should().Be("Name");
            table?.Columns[1].ColumnName.Should().Be("Age");
            table?.Columns[2].ColumnName.Should().Be("Birth");
            table?.Rows.Count.Should().Be(2);
            table?.Rows[0][0].Should().Be("Test1");
            table?.Rows[0][1].Should().Be(1);
            table?.Rows[0][2].Should().Be(list[0].Birth);
            table?.Rows[1][0].Should().Be("Test2");
            table?.Rows[1][1].Should().Be(2);
            table?.Rows[1][2].Should().Be(list[1].Birth);
        }
Exemplo n.º 2
0
        public void TestChangeConfig()
        {
            var frm = new FrmInit();

            ReflectorHelper.InvokeMethod(frm, "ChangeConfig", "test1");

            ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString.Should().Be("test1");
        }
Exemplo n.º 3
0
        public void TestCreateSqliteTables()
        {
            var instance = new MsSqlToSqlite();

            ReflectorHelper.InvokeMethod(instance, "CreateSqliteTables");

            var sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='TrainNoLine';";
            var res = _sqliteHelper.ExecuteScalar(_connStr, CommandType.Text, sql);

            res.Should().NotBeNull();
            res?.ToString().Should().Be("TrainNoLine");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将源数据库中需要拷贝到 sqlite 数据库中的所有表的所有数据拷贝入 sqlite 数据库
        /// </summary>
        private void CopyFromSourceDb()
        {
            foreach (var pair in _tableFields)
            {
                // 根据表名获取对应的 bll 对象
                object bll;
                try
                {
                    // 对无法创建对应的 Bll 层对象的表名
                    // 程序会认为它不存在于服务器数据库中
                    // 因此对此类表予以忽略
                    bll = BllFactory.GetBllInstance(pair.Key);
                }
                catch (Exception ex)
                {
                    continue;
                }

                var list  = ReflectorHelper.InvokeMethod(bll, "QueryAll") as IEnumerable;
                var table = GetDataTable(pair.Value, list);

                Sqlite.BulkInsert(_sqliteConnStr, pair.Key, table);
            }
        }
Exemplo n.º 5
0
 public void TestCopyFull()
 {
     ReflectorHelper.InvokeMethod(new MsSqlToSqlite(), "CopyFull");
 }