Browse Source

Update Unit Test

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
084ecc9b02
  1. 17
      Src/Asp.Net/SqlServerTest/UnitTest/Insert.cs
  2. 15
      Src/Asp.Net/SqlServerTest/UnitTest/Update.cs
  3. 16
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs

17
Src/Asp.Net/SqlServerTest/UnitTest/Insert.cs

@ -124,6 +124,23 @@ new List<SugarParameter>() {
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
new SugarParameter("@Name","张三")
}, t11.Key, t11.Value, "Insert t11 error");
var t12 = db.Insertable<Student>(new { Name = "a" }).ToSql();
base.Check(@"INSERT INTO [STudent]
([Name])
VALUES
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
new SugarParameter("@Name","a")
}, t12.Key, t12.Value, "Insert t12 error");
var t13 = db.Insertable<Student>(new Dictionary<string, object>() { {"id",0 },{ "name","2"} }).ToSql();
base.Check(@"INSERT INTO [STudent]
([Name])
VALUES
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
new SugarParameter("@Name","2")
}, t13.Key, t13.Value, "Insert t13 error");
}
}

15
Src/Asp.Net/SqlServerTest/UnitTest/Update.cs

@ -144,6 +144,21 @@ namespace OrmTest.UnitTest
"Update 12 error"
);
var t13 = db.Updateable<Student>(new { Name = "a", id=1 }).ToSql();
base.Check(@"UPDATE [STudent] SET
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
new SugarParameter("@Name","a"),
new SugarParameter("@ID",1)
}, t13.Key, t13.Value, "Insert t13 error");
var t14 = db.Updateable<Student>(new Dictionary<string, object>() { { "id", 0 }, { "name", "2" } }).ToSql();
base.Check(@"UPDATE [STudent] SET
[Name]=@Name WHERE [Id]=@Id", new List<SugarParameter>() {
new SugarParameter("@Name", "2"),
new SugarParameter("@ID", 0)
}, t14.Key, t14.Value, "Insert t14 error");
}
}

16
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -265,7 +265,8 @@ namespace SqlSugar
{
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Insertable.columnDictionary can't be null");
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
return this.Insertable(insertObject);
var columns = columnDictionary.Select(it => it.Key).ToList();
return this.Insertable(insertObject).InsertColumns(it => columns.Any(c => it.Equals(c,StringComparison.CurrentCultureIgnoreCase))); ;
}
public virtual IInsertable<T> Insertable<T>(dynamic insertDynamicObject) where T : class, new()
{
@ -275,8 +276,9 @@ namespace SqlSugar
}
else
{
var insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(insertDynamicObject));
return this.Insertable(insertObject);
var columns= ((object)insertDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
T insertObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(insertDynamicObject));
return this.Insertable(insertObject).InsertColumns(it=> columns.Any(c=>it.Equals(c,StringComparison.CurrentCultureIgnoreCase)));
}
}
#endregion
@ -338,7 +340,8 @@ namespace SqlSugar
{
Check.Exception(columnDictionary == null || columnDictionary.Count == 0, "Updateable.columnDictionary can't be null");
var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(columnDictionary));
return this.Updateable(updateObject);
var columns = columnDictionary.Select(it => it.Key).ToList();
return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
}
public virtual IUpdateable<T> Updateable<T>(dynamic updateDynamicObject) where T : class, new()
{
@ -348,8 +351,9 @@ namespace SqlSugar
}
else
{
var updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(updateDynamicObject));
return this.Updateable(updateObject);
var columns = ((object)updateDynamicObject).GetType().GetProperties().Select(it => it.Name).ToList();
T updateObject = this.RewritableMethods.DeserializeObject<T>(this.RewritableMethods.SerializeObject(updateDynamicObject));
return this.Updateable(updateObject).UpdateColumns(it => columns.Any(c => it.Equals(c, StringComparison.CurrentCultureIgnoreCase))); ;
}
}
#endregion

Loading…
Cancel
Save