Lith 4 месяцев назад
Родитель
Сommit
30640a5bc9
20 измененных файлов с 152 добавлено и 13 удалено
  1. 3 0
      src/Vitorm.PostgreSQL/DataProvider.cs
  2. 2 0
      src/Vitorm.PostgreSQL/DbConfig.cs
  3. 1 2
      src/Vitorm.PostgreSQL/DbContext_Extensions_UsePostgreSQL.cs
  4. 6 2
      src/Vitorm.PostgreSQL/SqlTranslateService.cs
  5. 4 1
      src/Vitorm.PostgreSQL/TranslateService/ExecuteDeleteTranslateService.cs
  6. 3 0
      src/Vitorm.PostgreSQL/TranslateService/ExecuteUpdateTranslateService.cs
  7. 3 0
      src/Vitorm.PostgreSQL/TranslateService/QueryTranslateService.cs
  8. 2 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/CRUDAsync_Test.cs
  9. 3 3
      test/Vitorm.PostgreSQL.MsTest/CommonTest/CRUD_Test.cs
  10. 5 1
      test/Vitorm.PostgreSQL.MsTest/CommonTest/EntityLoader_CustomLoader_Test.cs
  11. 3 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_FilterRule_Test.cs
  12. 2 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_FilterRule_WithJoin_Test.cs
  13. 56 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Group_FirstOrDefault_Test.cs
  14. 2 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_MethodAsync_Test.cs
  15. 2 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Method_Test.cs
  16. 2 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_ToListAndTotalCount_Test.cs
  17. 44 0
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Where_In_Test.cs
  18. 5 4
      test/Vitorm.PostgreSQL.MsTest/CommonTest/Transaction_Test.cs
  19. 2 0
      test/Vitorm.PostgreSQL.MsTest/DataSource.cs
  20. 2 0
      test/Vitorm.PostgreSQL.MsTest/ExpressionNodesTest/ExpressionTester.cs

+ 3 - 0
src/Vitorm.PostgreSQL/DataProvider.cs

@@ -1,5 +1,8 @@
 using System.Collections.Generic;
 
+using Vitorm.DataProvider;
+using Vitorm.Sql;
+
 namespace Vitorm.PostgreSQL
 {
     public class DataProvider : SqlDataProvider

+ 2 - 0
src/Vitorm.PostgreSQL/DbConfig.cs

@@ -1,6 +1,8 @@
 using System.Collections.Generic;
 using System.Data;
 
+using Vitorm.Sql;
+
 using ConnectionStringBuilder = global::Npgsql.NpgsqlConnectionStringBuilder;
 using DbConnection = global::Npgsql.NpgsqlConnection;
 

+ 1 - 2
src/Vitorm.PostgreSQL/DbContext_Extensions_UsePostgreSQL.cs

@@ -1,4 +1,5 @@
 using Vitorm.PostgreSQL;
+using Vitorm.Sql;
 
 namespace Vitorm
 {
@@ -19,7 +20,5 @@ namespace Vitorm
             return dbContext;
         }
 
-
-
     }
 }

+ 6 - 2
src/Vitorm.PostgreSQL/SqlTranslateService.cs

@@ -1,8 +1,12 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using System.Linq.Expressions;
-using System.Text;
+
+using Vit.Linq;
+using Vit.Linq.ExpressionNodes.ComponentModel;
+
+using Vitorm.Entity;
+using Vitorm.Sql.SqlTranslate;
 
 namespace Vitorm.PostgreSQL
 {

+ 4 - 1
src/Vitorm.PostgreSQL/TranslateService/ExecuteDeleteTranslateService.cs

@@ -1,4 +1,7 @@
-namespace Vitorm.PostgreSQL.TranslateService
+using Vitorm.Sql.SqlTranslate;
+using Vitorm.StreamQuery;
+
+namespace Vitorm.PostgreSQL.TranslateService
 {
     public class ExecuteDeleteTranslateService : BaseQueryTranslateService
     {

+ 3 - 0
src/Vitorm.PostgreSQL/TranslateService/ExecuteUpdateTranslateService.cs

@@ -2,6 +2,9 @@
 using System.Collections.Generic;
 using System.Linq;
 
+using Vitorm.Sql.SqlTranslate;
+using Vitorm.StreamQuery;
+
 namespace Vitorm.PostgreSQL.TranslateService
 {
     public class ExecuteUpdateTranslateService : BaseQueryTranslateService

+ 3 - 0
src/Vitorm.PostgreSQL/TranslateService/QueryTranslateService.cs

@@ -1,5 +1,8 @@
 using System.Linq;
 
+using Vitorm.Sql.SqlTranslate;
+using Vitorm.StreamQuery;
+
 namespace Vitorm.PostgreSQL.TranslateService
 {
     public class QueryTranslateService : Vitorm.Sql.SqlTranslate.QueryTranslateService

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/CRUDAsync_Test.cs

@@ -2,6 +2,8 @@
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vit.Linq;
+
 namespace Vitorm.MsTest.CommonTest
 {
 

+ 3 - 3
test/Vitorm.PostgreSQL.MsTest/CommonTest/CRUD_Test.cs

@@ -78,7 +78,7 @@ namespace Vitorm.MsTest.CommonTest
             // #2 Query
             {
                 var userList = dbContext.Query<User>().ToList();
-                Assert.AreEqual(6, userList.Count());
+                Assert.AreEqual(6, userList.Count);
             }
         }
         #endregion
@@ -108,7 +108,7 @@ namespace Vitorm.MsTest.CommonTest
             {
                 var newUserList = User.NewUsers(4, 3, forAdd: false);
                 var userList = dbContext.Query<User>().Where(m => m.id >= 4).ToList();
-                Assert.AreEqual(newUserList.Count, userList.Count());
+                Assert.AreEqual(newUserList.Count, userList.Count);
                 Assert.AreEqual(0, userList.Select(m => m.id).Except(newUserList.Select(m => m.id)).Count());
                 Assert.AreEqual(0, userList.Select(m => m.name).Except(newUserList.Select(m => m.name)).Count());
             }
@@ -158,7 +158,7 @@ namespace Vitorm.MsTest.CommonTest
             // assert
             {
                 var userList = dbContext.Query<User>().ToList();
-                Assert.AreEqual(0, userList.Count());
+                Assert.AreEqual(0, userList.Count);
             }
         }
         #endregion

+ 5 - 1
test/Vitorm.PostgreSQL.MsTest/CommonTest/EntityLoader_CustomLoader_Test.cs

@@ -2,6 +2,10 @@
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vitorm.Entity;
+using Vitorm.Entity.Loader.DataAnnotations;
+using Vitorm.Entity.PropertyType;
+
 namespace Vitorm.MsTest.CommonTest
 {
     [TestClass]
@@ -151,7 +155,7 @@ namespace Vitorm.MsTest.CommonTest
 
                         return new PropertyDescriptor(
                             propertyInfo, propertyType: new PropertyValueType(propertyInfo.PropertyType),
-                        columnName: columnName,
+                            columnName: columnName,
                             isKey: isKey, isIdentity: isIdentity, isNullable: isNullable,
                             columnDbType: columnDbType,
                             columnOrder: columnOrder

+ 3 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_FilterRule_Test.cs

@@ -1,6 +1,9 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 using Vit.Core.Module.Serialization;
+using Vit.Linq;
+using Vit.Linq.ComponentModel;
+using Vit.Linq.FilterRules.ComponentModel;
 
 namespace Vitorm.MsTest.CommonTest
 {

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_FilterRule_WithJoin_Test.cs

@@ -1,6 +1,8 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 using Vit.Core.Module.Serialization;
+using Vit.Linq;
+using Vit.Linq.ComponentModel;
 
 namespace Vitorm.MsTest.CommonTest
 {

+ 56 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Group_FirstOrDefault_Test.cs

@@ -0,0 +1,56 @@
+using System.Data;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+
+namespace Vitorm.MsTest.CommonTest
+{
+    [TestClass]
+    public class Query_Group_FirstOrDefault_Test
+    {
+
+        [TestMethod]
+        public void Test_Group_FirstOrDefault()
+        {
+            using var dbContext = DataSource.CreateDbContext();
+            var userQuery = dbContext.Query<User>();
+
+            // Linq Expression
+            {
+                var query =
+                        from user in userQuery
+                        where user.fatherId != null
+                        group user by new { user.fatherId, user.motherId } into userGroup
+                        orderby userGroup.Key.fatherId, userGroup.Key.motherId
+                        select new { userGroup.Key.fatherId, userGroup.Key.motherId };
+
+                var row = query.FirstOrDefault();
+
+                Assert.AreEqual(4, row?.fatherId);
+                Assert.AreEqual(6, row?.motherId);
+            }
+
+            // Lambda Expression
+            {
+                var query =
+                        userQuery.Where(m => m.fatherId != null)
+                        .GroupBy(user => new { user.fatherId, user.motherId })
+                        .OrderBy(userGroup => userGroup.Key.fatherId).ThenBy(userGroup => userGroup.Key.motherId)
+                        .Select(userGroup => new
+                        {
+                            userGroup.Key.fatherId,
+                            userGroup.Key.motherId
+                        })
+                        ;
+
+                var row = query.FirstOrDefault();
+
+                Assert.AreEqual(4, row?.fatherId);
+                Assert.AreEqual(6, row?.motherId);
+            }
+        }
+
+
+
+    }
+}

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_MethodAsync_Test.cs

@@ -2,6 +2,8 @@
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vit.Linq;
+
 namespace Vitorm.MsTest.CommonTest
 {
 

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Method_Test.cs

@@ -2,6 +2,8 @@
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vit.Linq;
+
 namespace Vitorm.MsTest.CommonTest
 {
 

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_ToListAndTotalCount_Test.cs

@@ -2,6 +2,8 @@
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vit.Linq;
+
 namespace Vitorm.MsTest.CommonTest
 {
 

+ 44 - 0
test/Vitorm.PostgreSQL.MsTest/CommonTest/Query_Where_In_Test.cs

@@ -0,0 +1,44 @@
+using System.Data;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Vit.Linq;
+
+namespace Vitorm.MsTest.CommonTest
+{
+
+    [TestClass]
+    public class Query_Where_In_Test
+    {
+
+        [TestMethod]
+        public void Test_In()
+        {
+            using var dbContext = DataSource.CreateDbContext();
+            var userQuery = dbContext.Query<User>();
+
+            {
+                var ids = new[] { 1, 2 };
+                var userList = userQuery.Where(m => ids.Contains(m.id)).OrderBy(m => m.id).ToList();
+
+                var strIds = String.Join(',', userList.Select(m => m.id));
+                Assert.AreEqual(2, userList.Count);
+                Assert.AreEqual("1,2", strIds);
+            }
+
+
+            {
+                var ids = new List<int> { 1, 2 };
+                var userList = userQuery.Where(m => ids.Contains(m.id)).OrderBy(m => m.id).ToList();
+
+                var strIds = String.Join(',', userList.Select(m => m.id));
+                Assert.AreEqual(2, userList.Count);
+                Assert.AreEqual("1,2", strIds);
+            }
+
+        }
+
+
+
+    }
+}

+ 5 - 4
test/Vitorm.PostgreSQL.MsTest/CommonTest/Transaction_Test.cs

@@ -48,8 +48,7 @@ namespace Vitorm.MsTest.CommonTest
         }
 
 
-        // can not test for db is not durable
-        //[TestMethod]
+        [TestMethod]
         public void Test_Dispose()
         {
             {
@@ -72,11 +71,12 @@ namespace Vitorm.MsTest.CommonTest
                 }
                 Assert.AreEqual("u4003", userSet.Get(4).name);
             }
+
             {
-                using var dbContext = DataSource.CreateDbContext();
+                using var dbContext = DataSource.CreateDbContext(autoInit: false);
                 var userSet = dbContext.DbSet<User>();
 
-                //Assert.AreEqual("u4002", userSet.Get(4).name);
+                Assert.AreEqual("u4002", userSet.Get(4).name);
             }
 
         }
@@ -85,5 +85,6 @@ namespace Vitorm.MsTest.CommonTest
 
 
 
+
     }
 }

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/DataSource.cs

@@ -1,5 +1,7 @@
 using Vit.Core.Util.ConfigurationManager;
 
+using Vitorm.Sql;
+
 namespace Vitorm.MsTest
 {
     [System.ComponentModel.DataAnnotations.Schema.Table("User")]

+ 2 - 0
test/Vitorm.PostgreSQL.MsTest/ExpressionNodesTest/ExpressionTester.cs

@@ -3,6 +3,8 @@ using System.Linq.Expressions;
 
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
+using Vit.Linq;
+
 namespace Vit.Linq.ExpressionNodes.ExpressionNodesTest
 {