源代码改用vs默认格式化

This commit is contained in:
28810
2019-06-27 09:40:35 +08:00
parent 873364c7ee
commit f8c3608fda
309 changed files with 73814 additions and 67594 deletions

View File

@ -3,41 +3,47 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using Xunit;
namespace FreeSql.Tests.Extensions {
public class LambadaExpressionExtensionsTest {
namespace FreeSql.Tests.Extensions
{
public class LambadaExpressionExtensionsTest
{
[Fact]
public void And() {
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
[Fact]
public void And()
{
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" = 1 AND a.\"num\" = 2)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num == 1).And(b => b.num == 2)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num == 1).And(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
}
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" > 0)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000' AND a.\"num\" = 1 AND a.\"num\" = 2)", g.sqlite.Select<testExpAddOr>().Where(where.And(b => b.num == 1).And(b => b.num == 2)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.And(false, b => b.num == 1).And(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
}
[Fact]
public void Or() {
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
[Fact]
public void Or()
{
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE ((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" > 0))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" = 1) OR a.\"num\" = 2))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num == 1).Or(b => b.num == 2)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num == 1).Or(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
}
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE ((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" > 0))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num > 0)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (((a.\"id\" = '00000000-0000-0000-0000-000000000000' OR a.\"num\" = 1) OR a.\"num\" = 2))", g.sqlite.Select<testExpAddOr>().Where(where.Or(b => b.num == 1).Or(b => b.num == 2)).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Or(false, b => b.num == 1).Or(false, c => c.num == 2)).ToSql().Replace("\r\n", ""));
}
[Fact]
public void Not() {
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
[Fact]
public void Not()
{
Expression<Func<testExpAddOr, bool>> where = a => a.id == Guid.Empty;
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (not(a.\"id\" = '00000000-0000-0000-0000-000000000000'))", g.sqlite.Select<testExpAddOr>().Where(where.Not()).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Not(false)).ToSql().Replace("\r\n", ""));
}
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (not(a.\"id\" = '00000000-0000-0000-0000-000000000000'))", g.sqlite.Select<testExpAddOr>().Where(where.Not()).ToSql().Replace("\r\n", ""));
Assert.Equal("SELECT a.\"id\", a.\"num\" FROM \"testExpAddOr\" a WHERE (a.\"id\" = '00000000-0000-0000-0000-000000000000')", g.sqlite.Select<testExpAddOr>().Where(where.Not(false)).ToSql().Replace("\r\n", ""));
}
class testExpAddOr {
public Guid id { get; set; }
class testExpAddOr
{
public Guid id { get; set; }
public int num { get; set; }
}
}
public int num { get; set; }
}
}
}

View File

@ -1,65 +1,70 @@
using Xunit;
namespace FreeSql.Tests.Extensions {
public class StringExtensionsTest {
[Fact]
public void FormatMySql() {
namespace FreeSql.Tests.Extensions
{
public class StringExtensionsTest
{
[Fact]
public void FormatMySql()
{
Assert.Empty(((string)null).FormatMySql("11"));
Assert.Equal("a=1", "a={0}".FormatMySql(1));
Assert.Equal("a =1", "a ={0}".FormatMySql(1));
Assert.Equal("a = 1", "a = {0}".FormatMySql(1));
Assert.Equal("a='a'", "a={0}".FormatMySql('a'));
Assert.Equal("a ='a'", "a ={0}".FormatMySql('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatMySql('a'));
Assert.Empty(((string)null).FormatMySql("11"));
Assert.Equal("a=1", "a={0}".FormatMySql(1));
Assert.Equal("a =1", "a ={0}".FormatMySql(1));
Assert.Equal("a = 1", "a = {0}".FormatMySql(1));
Assert.Equal("a='a'", "a={0}".FormatMySql('a'));
Assert.Equal("a ='a'", "a ={0}".FormatMySql('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatMySql('a'));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatMySql(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatMySql(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatMySql(1, null));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatMySql(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatMySql(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatMySql(1, null));
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatMySql(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatMySql(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatMySql(1, null, null));
}
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatMySql(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatMySql(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatMySql(1, null, null));
}
[Fact]
public void FormatSqlServer() {
[Fact]
public void FormatSqlServer()
{
Assert.Empty(((string)null).FormatSqlServer("11"));
Assert.Equal("a=1", "a={0}".FormatSqlServer(1));
Assert.Equal("a =1", "a ={0}".FormatSqlServer(1));
Assert.Equal("a = 1", "a = {0}".FormatSqlServer(1));
Assert.Equal("a='a'", "a={0}".FormatSqlServer('a'));
Assert.Equal("a ='a'", "a ={0}".FormatSqlServer('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatSqlServer('a'));
Assert.Empty(((string)null).FormatSqlServer("11"));
Assert.Equal("a=1", "a={0}".FormatSqlServer(1));
Assert.Equal("a =1", "a ={0}".FormatSqlServer(1));
Assert.Equal("a = 1", "a = {0}".FormatSqlServer(1));
Assert.Equal("a='a'", "a={0}".FormatSqlServer('a'));
Assert.Equal("a ='a'", "a ={0}".FormatSqlServer('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatSqlServer('a'));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatSqlServer(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatSqlServer(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatSqlServer(1, null));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatSqlServer(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatSqlServer(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatSqlServer(1, null));
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatSqlServer(1, null, null));
}
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatSqlServer(1, null, null));
}
[Fact]
public void FormatPostgreSQL() {
[Fact]
public void FormatPostgreSQL()
{
Assert.Empty(((string)null).FormatPostgreSQL("11"));
Assert.Equal("a=1", "a={0}".FormatPostgreSQL(1));
Assert.Equal("a =1", "a ={0}".FormatPostgreSQL(1));
Assert.Equal("a = 1", "a = {0}".FormatPostgreSQL(1));
Assert.Equal("a='a'", "a={0}".FormatPostgreSQL('a'));
Assert.Equal("a ='a'", "a ={0}".FormatPostgreSQL('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatPostgreSQL('a'));
Assert.Empty(((string)null).FormatPostgreSQL("11"));
Assert.Equal("a=1", "a={0}".FormatPostgreSQL(1));
Assert.Equal("a =1", "a ={0}".FormatPostgreSQL(1));
Assert.Equal("a = 1", "a = {0}".FormatPostgreSQL(1));
Assert.Equal("a='a'", "a={0}".FormatPostgreSQL('a'));
Assert.Equal("a ='a'", "a ={0}".FormatPostgreSQL('a'));
Assert.Equal("a = 'a'", "a = {0}".FormatPostgreSQL('a'));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatPostgreSQL(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatPostgreSQL(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatPostgreSQL(1, null));
Assert.Equal("a=1 and b IS NULL", "a={0} and b={1}".FormatPostgreSQL(1, null));
Assert.Equal("a =1 and b IS NULL", "a ={0} and b ={1}".FormatPostgreSQL(1, null));
Assert.Equal("a = 1 and b IS NULL", "a = {0} and b = {1}".FormatPostgreSQL(1, null));
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatPostgreSQL(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatSqlServer(1, null, null));
}
}
Assert.Equal("a=1 and b IS NULL and c in (1,2,3,4)", "a={0} and b={1} and c in {2}".FormatPostgreSQL(1, null, new[] { 1, 2, 3, 4 }));
Assert.Equal("a=1 and b IS NULL and c IS NULL", "a={0} and b={1} and c in {2}".FormatSqlServer(1, null, null));
Assert.Equal("a=1 and b IS NULL and c not IS NULL", "a={0} and b={1} and c not in {2}".FormatSqlServer(1, null, null));
}
}
}