28810 994cc475c2 - 解决 表名名称包含点,无法进行 CRUD 的问题,由于测试的复杂性,此类情况仅支持 MySql/Sqlite CodeFirst 自动迁移;
> 注意:尽量不要使用带点的表名,只有 MySql/Sqlite 对此类表名支持 CodeFirst。但是它不影响 CRUD 功能,使用 [Table(Name = "`sys.config`")] 解决
2020-01-11 02:22:16 +08:00

79 lines
2.5 KiB
C#

using FreeSql.DataAnnotations;
using FreeSql;
using System;
using System.Collections.Generic;
using Xunit;
using System.Linq;
using Newtonsoft.Json.Linq;
using NpgsqlTypes;
using Npgsql.LegacyPostgis;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Data.SqlClient;
using kwlib;
using System.Diagnostics;
using System.IO;
using System.Text;
using FreeSql.Internal;
namespace FreeSql.InternalTests
{
public class CommonUtilsTest
{
[Fact]
public void GetSplitTableNames()
{
var tbname = CommonUtils.GetSplitTableNames("table1", '`', '`', 2);
Assert.Equal("table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("table1", '"', '"', 2);
Assert.Equal("table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("table1", '[', ']', 2);
Assert.Equal("table1", tbname[0]);
//---
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '`', '`', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '"', '"', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("schema1.table1", '[', ']', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("table1", tbname[1]);
//---
tbname = CommonUtils.GetSplitTableNames("`sys.table1`", '`', '`', 2);
Assert.Equal("sys.table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("\"sys.table1\"", '"', '"', 2);
Assert.Equal("sys.table1", tbname[0]);
tbname = CommonUtils.GetSplitTableNames("[sys.table1]", '[', ']', 2);
Assert.Equal("sys.table1", tbname[0]);
//---
tbname = CommonUtils.GetSplitTableNames("`schema1`.`sys.table1`", '`', '`', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("\"schema1\".\"sys.table1\"", '"', '"', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
tbname = CommonUtils.GetSplitTableNames("[schema1].[sys.table1]", '[', ']', 2);
Assert.Equal("schema1", tbname[0]);
Assert.Equal("sys.table1", tbname[1]);
}
}
}