Преглед изворни кода

crud interface get multiple with order by; tests

tags/v0.1.0
Robin Thoni пре 8 година
родитељ
комит
95d991ec82

+ 9
- 1
Luticate2.Auth/Controllers/LuticateExtensions.cs Прегледај датотеку

@@ -1,8 +1,11 @@
1
-using Luticate2.Auth.Business;
1
+using System.Collections.Generic;
2
+using Luticate2.Auth.Business;
2 3
 using Luticate2.Auth.DataAccess;
3 4
 using Luticate2.Auth.Middlewares;
5
+using Luticate2.Utils.Controllers;
4 6
 using Luticate2.Utils.Dbo.OrderBy;
5 7
 using Microsoft.AspNetCore.Builder;
8
+using Microsoft.AspNetCore.Http;
6 9
 using Microsoft.AspNetCore.Mvc;
7 10
 using Microsoft.Extensions.DependencyInjection;
8 11
 
@@ -37,5 +40,10 @@ namespace Luticate2.Auth.Controllers
37 40
             app.UseMiddleware<LuAuthMiddleware>();
38 41
             return app;
39 42
         }
43
+
44
+        public static object GetLuCurrentUser(this HttpContext context)
45
+        {
46
+            return context.GetLuItems()["currentUser"];//TODO
47
+        }
40 48
     }
41 49
 }

+ 32
- 26
Luticate2.Utils/Business/LuCrudBusiness.cs Прегледај датотеку

@@ -1,6 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using Luticate2.Utils.Dbo;
4
+using Luticate2.Utils.Dbo.OrderBy;
4 5
 using Luticate2.Utils.Interfaces;
5 6
 
6 7
 namespace Luticate2.Utils.Business
@@ -11,11 +12,11 @@ namespace Luticate2.Utils.Business
11 12
         where TDboRead : class
12 13
         where TDboUpdate : class
13 14
     {
14
-        protected readonly TNextCrud Db;
15
+        protected readonly TNextCrud NextCrud;
15 16
 
16
-        protected LuCrudBusiness(TNextCrud db)
17
+        protected LuCrudBusiness(TNextCrud nextCrud)
17 18
         {
18
-            Db = db;
19
+            NextCrud = nextCrud;
19 20
         }
20 21
 
21 22
         protected virtual LuResult<TDboCreate> CheckAdd(TDboCreate obj)
@@ -72,7 +73,7 @@ namespace Luticate2.Utils.Business
72 73
             {
73 74
                 return res.To<T>();
74 75
             }
75
-            return Db.Add(res.Data, returnFunc);
76
+            return NextCrud.Add(res.Data, returnFunc);
76 77
         }
77 78
 
78 79
         public LuResult<T> Add<T>(TDboCreate obj, Func<TDboRead, T> returnFunc)
@@ -82,7 +83,7 @@ namespace Luticate2.Utils.Business
82 83
             {
83 84
                 return res.To<T>();
84 85
             }
85
-            return Db.Add(res.Data, returnFunc);
86
+            return NextCrud.Add(res.Data, returnFunc);
86 87
         }
87 88
 
88 89
         public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
@@ -92,7 +93,7 @@ namespace Luticate2.Utils.Business
92 93
             {
93 94
                 return res.To<IEnumerable<string>>();
94 95
             }
95
-            return Db.AddGuid(res.Data);
96
+            return NextCrud.AddGuid(res.Data);
96 97
         }
97 98
 
98 99
         public LuResult<string> AddGuid(TDboCreate obj)
@@ -102,7 +103,7 @@ namespace Luticate2.Utils.Business
102 103
             {
103 104
                 return res.To<string>();
104 105
             }
105
-            return Db.AddGuid(res.Data);
106
+            return NextCrud.AddGuid(res.Data);
106 107
         }
107 108
 
108 109
         public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
@@ -112,7 +113,7 @@ namespace Luticate2.Utils.Business
112 113
             {
113 114
                 return res.To<IEnumerable<long>>();
114 115
             }
115
-            return Db.AddId(res.Data);
116
+            return NextCrud.AddId(res.Data);
116 117
         }
117 118
 
118 119
         public LuResult<long> AddId(TDboCreate obj)
@@ -122,7 +123,7 @@ namespace Luticate2.Utils.Business
122 123
             {
123 124
                 return res.To<long>();
124 125
             }
125
-            return Db.AddId(res.Data);
126
+            return NextCrud.AddId(res.Data);
126 127
         }
127 128
 
128 129
         public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
@@ -132,7 +133,7 @@ namespace Luticate2.Utils.Business
132 133
             {
133 134
                 return res.To<IEnumerable<TDboRead>>();
134 135
             }
135
-            return Db.AddDbo(res.Data);
136
+            return NextCrud.AddDbo(res.Data);
136 137
         }
137 138
 
138 139
         public LuResult<TDboRead> AddDbo(TDboCreate obj)
@@ -142,7 +143,7 @@ namespace Luticate2.Utils.Business
142 143
             {
143 144
                 return res.To<TDboRead>();
144 145
             }
145
-            return Db.AddDbo(res.Data);
146
+            return NextCrud.AddDbo(res.Data);
146 147
         }
147 148
 
148 149
 
@@ -150,17 +151,22 @@ namespace Luticate2.Utils.Business
150 151
 
151 152
         public LuResult<TDboRead> GetSingleByKeys(params KeyValuePair<string, object>[] keys)
152 153
         {
153
-            return Db.GetSingleByKeys(keys);
154
+            return NextCrud.GetSingleByKeys(keys);
154 155
         }
155 156
 
156 157
         public LuResult<TDboRead> GetSingleById(string id)
157 158
         {
158
-            return Db.GetSingleById(id);
159
+            return NextCrud.GetSingleById(id);
159 160
         }
160 161
 
161 162
         public LuResult<TDboRead> GetSingleById(long id)
162 163
         {
163
-            return Db.GetSingleById(id);
164
+            return NextCrud.GetSingleById(id);
165
+        }
166
+
167
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
168
+        {
169
+            return NextCrud.GetMultiple(orderBy, 0, perPage);
164 170
         }
165 171
 
166 172
 
@@ -173,7 +179,7 @@ namespace Luticate2.Utils.Business
173 179
             {
174 180
                 return obj.To<T>();
175 181
             }
176
-            return Db.EditSingleById(id, obj.Data, returnFunc);
182
+            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
177 183
         }
178 184
 
179 185
         public LuResult<long> EditSingleByIdId(long id, TDboUpdate update)
@@ -183,7 +189,7 @@ namespace Luticate2.Utils.Business
183 189
             {
184 190
                 return obj.To<long>();
185 191
             }
186
-            return Db.EditSingleByIdId(id, obj.Data);
192
+            return NextCrud.EditSingleByIdId(id, obj.Data);
187 193
         }
188 194
 
189 195
         public LuResult<TDboRead> EditSingleByIdDbo(long id, TDboUpdate update)
@@ -193,7 +199,7 @@ namespace Luticate2.Utils.Business
193 199
             {
194 200
                 return obj.To<TDboRead>();
195 201
             }
196
-            return Db.EditSingleByIdDbo(id, obj.Data);
202
+            return NextCrud.EditSingleByIdDbo(id, obj.Data);
197 203
         }
198 204
 
199 205
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
@@ -203,7 +209,7 @@ namespace Luticate2.Utils.Business
203 209
             {
204 210
                 return obj.To<T>();
205 211
             }
206
-            return Db.EditSingleById(id, obj.Data, returnFunc);
212
+            return NextCrud.EditSingleById(id, obj.Data, returnFunc);
207 213
         }
208 214
 
209 215
         public LuResult<string> EditSingleByIdGuid(string id, TDboUpdate update)
@@ -213,7 +219,7 @@ namespace Luticate2.Utils.Business
213 219
             {
214 220
                 return obj.To<string>();
215 221
             }
216
-            return Db.EditSingleByIdGuid(id, obj.Data);
222
+            return NextCrud.EditSingleByIdGuid(id, obj.Data);
217 223
         }
218 224
 
219 225
         public LuResult<TDboRead> EditSingleByIdDbo(string id, TDboUpdate update)
@@ -223,7 +229,7 @@ namespace Luticate2.Utils.Business
223 229
             {
224 230
                 return obj.To<TDboRead>();
225 231
             }
226
-            return Db.EditSingleByIdDbo(id, obj.Data);
232
+            return NextCrud.EditSingleByIdDbo(id, obj.Data);
227 233
         }
228 234
 
229 235
 
@@ -231,32 +237,32 @@ namespace Luticate2.Utils.Business
231 237
 
232 238
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
233 239
         {
234
-            return Db.DeleteSingleById(id, returnFunc);
240
+            return NextCrud.DeleteSingleById(id, returnFunc);
235 241
         }
236 242
 
237 243
         public LuResult<string> DeleteSingleByIdGuid(string id)
238 244
         {
239
-            return Db.DeleteSingleByIdGuid(id);
245
+            return NextCrud.DeleteSingleByIdGuid(id);
240 246
         }
241 247
 
242 248
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
243 249
         {
244
-            return Db.DeleteSingleByIdDbo(id);
250
+            return NextCrud.DeleteSingleByIdDbo(id);
245 251
         }
246 252
 
247 253
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
248 254
         {
249
-            return Db.DeleteSingleById(id, returnFunc);
255
+            return NextCrud.DeleteSingleById(id, returnFunc);
250 256
         }
251 257
 
252 258
         public LuResult<long> DeleteSingleByIdId(long id)
253 259
         {
254
-            return Db.DeleteSingleByIdId(id);
260
+            return NextCrud.DeleteSingleByIdId(id);
255 261
         }
256 262
 
257 263
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
258 264
         {
259
-            return Db.DeleteSingleByIdDbo(id);
265
+            return NextCrud.DeleteSingleByIdDbo(id);
260 266
         }
261 267
     }
262 268
 }

+ 1
- 3
Luticate2.Utils/Controllers/LuController.cs Прегледај датотеку

@@ -10,9 +10,7 @@ namespace Luticate2.Utils.Controllers
10 10
     {
11 11
         protected IConnectionManager ConnectionManager { get; set; }
12 12
 
13
-        protected IDictionary<object, object> LuItems => (IDictionary<object, object>) HttpContext.Items["luticateItems"];
14
-
15
-//        protected UsersDbo LuCurrentUser => (UsersDbo) LuItems["luticateItems"];
13
+        protected IDictionary<object, object> LuItems => HttpContext.GetLuItems();
16 14
 
17 15
         protected T Handle<T>(LuResult<T> result)
18 16
         {

+ 13
- 0
Luticate2.Utils/Controllers/LuUtilsExtensions.cs Прегледај датотеку

@@ -0,0 +1,13 @@
1
+using System.Collections.Generic;
2
+using Microsoft.AspNetCore.Http;
3
+
4
+namespace Luticate2.Utils.Controllers
5
+{
6
+    public static class LuUtilsExtensions
7
+    {
8
+        public static IDictionary<object, object> GetLuItems(this HttpContext context)
9
+        {
10
+            return (IDictionary<object, object>) context.Items["luticateItems"];
11
+        }
12
+    }
13
+}

Luticate2.Utils/DataAccess/LuEfCrudInterface.cs → Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs Прегледај датотеку

@@ -2,13 +2,15 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Linq.Expressions;
5
+using System.Reflection;
5 6
 using Luticate2.Utils.Dbo;
7
+using Luticate2.Utils.Dbo.OrderBy;
6 8
 using Luticate2.Utils.Interfaces;
7 9
 using Microsoft.EntityFrameworkCore;
8 10
 
9 11
 namespace Luticate2.Utils.DataAccess
10 12
 {
11
-    public abstract class LuEfCrudInterface<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext> :
13
+    public abstract class LuEfCrudDataAccess<TModel, TDboCreate, TDboRead, TDboUpdate, TDbContext> :
12 14
             LuEfDataAccess<TModel, TDbContext>, ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate>
13 15
         where TModel : class
14 16
         where TDboCreate : class
@@ -16,7 +18,7 @@ namespace Luticate2.Utils.DataAccess
16 18
         where TDboUpdate : class
17 19
         where TDbContext : DbContext
18 20
     {
19
-        protected LuEfCrudInterface(TDbContext db, DbSet<TModel> table) : base(db, table)
21
+        protected LuEfCrudDataAccess(TDbContext db, DbSet<TModel> table) : base(db, table)
20 22
         {
21 23
         }
22 24
 
@@ -26,6 +28,13 @@ namespace Luticate2.Utils.DataAccess
26 28
 
27 29
         protected abstract TDboRead GetDboFromModel(TModel model);
28 30
 
31
+        protected string GetFieldName(string name)
32
+        {
33
+            return
34
+                string.Concat(name.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString()))
35
+                    .ToLower();
36
+        }
37
+
29 38
         protected Func<TDboRead, T> GetIdFunc<T>()
30 39
         {
31 40
             var param = Expression.Parameter(typeof(TDboRead), "x");
@@ -130,9 +139,9 @@ namespace Luticate2.Utils.DataAccess
130 139
         }
131 140
 
132 141
 
133
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IQueryable<TModel>> orderBy,
142
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
134 143
             Expression<Func<TModel, bool>> predicate, int page = 0, int perPage = int.MaxValue,
135
-            params Func<DbSet<TModel>, IQueryable<TModel>>[] otherOrderBy)
144
+            params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
136 145
         {
137 146
             return Execute(() =>
138 147
             {
@@ -140,7 +149,7 @@ namespace Luticate2.Utils.DataAccess
140 149
                 var ordered = orderBy(Table);
141 150
                 foreach (var func in otherOrderBy)
142 151
                 {
143
-                    ordered = func(Table);
152
+                    ordered = func(ordered);
144 153
                 }
145 154
                 var data = ordered.Where(predicate).Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
146 155
                 var result = new LuPaginatedDbo<TDboRead>
@@ -157,12 +166,12 @@ namespace Luticate2.Utils.DataAccess
157 166
             params Expression<Func<TModel, object>>[] otherOrderBy)
158 167
         {
159 168
             return GetMultiple(table => table.OrderBy(orderBy), predicate, page, perPage,
160
-                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<DbSet<TModel>,
161
-                    IQueryable<TModel>>>(expression => (t => t.OrderBy(expression))).ToArray());
169
+                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<IOrderedQueryable<TModel>,
170
+                    IOrderedQueryable<TModel>>>(expression => (t => t.ThenBy(expression))).ToArray());
162 171
         }
163 172
 
164
-        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IQueryable<TModel>> orderBy,
165
-            int page = 0, int perPage = int.MaxValue, params Func<DbSet<TModel>, IQueryable<TModel>>[] otherOrderBy)
173
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Func<DbSet<TModel>, IOrderedQueryable<TModel>> orderBy,
174
+            int page = 0, int perPage = int.MaxValue, params Func<IOrderedQueryable<TModel>, IOrderedQueryable<TModel>>[] otherOrderBy)
166 175
         {
167 176
             return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
168 177
         }
@@ -170,11 +179,41 @@ namespace Luticate2.Utils.DataAccess
170 179
         public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(Expression<Func<TModel, object>> orderBy,
171 180
             int page = 0, int perPage = int.MaxValue, params Expression<Func<TModel, object>>[] otherOrderBy)
172 181
         {
173
-            return GetMultiple(table => table.OrderBy(orderBy), x => true, page, perPage,
174
-                otherOrderBy.Select<Expression<Func<TModel, object>>, Func<DbSet<TModel>,
175
-                    IQueryable<TModel>>>(expression => (t => t.OrderBy(expression))).ToArray());
182
+            return GetMultiple(orderBy, x => true, page, perPage, otherOrderBy);
176 183
         }
177 184
 
185
+        public LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
186
+        {
187
+            return Execute(() =>
188
+            {
189
+                var count = Table.Count();
190
+                IOrderedQueryable<TModel> ordered = null;
191
+                foreach (var field in orderBy.Fields)
192
+                {
193
+                    var fieldName = GetFieldName(field.Name);
194
+                    var param = Expression.Parameter(typeof(TModel), "x");
195
+                    var prop = Expression.Property(param, fieldName);
196
+                    var converted = Expression.Convert(prop, typeof(object));
197
+                    var exp = Expression.Lambda<Func<TModel, object>>(converted, param);
198
+                    if (ordered != null)
199
+                    {
200
+                        ordered = field.Asc ? ordered.ThenBy(exp) : ordered.ThenByDescending(exp);
201
+                    }
202
+                    else
203
+                    {
204
+                        ordered = field.Asc ? Table.OrderBy(exp) : Table.OrderByDescending(exp);
205
+                    }
206
+                }
207
+
208
+                var data = ordered.Skip(page * perPage).Take(perPage).Select(GetDboFromModel).ToList();
209
+                var result = new LuPaginatedDbo<TDboRead>
210
+                {
211
+                    Count = count,
212
+                    Data = data
213
+                };
214
+                return LuResult<LuPaginatedDbo<TDboRead>>.Ok(result);
215
+            });
216
+        }
178 217
 
179 218
 
180 219
 

+ 4
- 0
Luticate2.Utils/Dbo/OrderBy/LuOrderByBinder.cs Прегледај датотеку

@@ -8,6 +8,10 @@ namespace Luticate2.Utils.Dbo.OrderBy
8 8
     {
9 9
         public static LuResult<LuOrderByDbo> FromString(string data)
10 10
         {
11
+            if (data == null)
12
+            {
13
+                data = "";
14
+            }
11 15
             data = data.Trim();
12 16
             var dbo = new LuOrderByDbo {Fields = new List<LuOrderByFieldDbo>()};
13 17
             if (data != "")

+ 5
- 0
Luticate2.Utils/Interfaces/ILuCrudInterface.cs Прегледај датотеку

@@ -1,6 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using Luticate2.Utils.Dbo;
4
+using Luticate2.Utils.Dbo.OrderBy;
4 5
 
5 6
 namespace Luticate2.Utils.Interfaces
6 7
 {
@@ -37,6 +38,10 @@ namespace Luticate2.Utils.Interfaces
37 38
         LuResult<TDboRead> GetSingleById(long id);
38 39
 
39 40
 
41
+        LuResult<LuPaginatedDbo<TDboRead>> GetMultiple(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue);
42
+
43
+
44
+
40 45
 
41 46
         LuResult<T> EditSingleById<T>(long id, TDboUpdate update, Func<TDboRead, T> returnFunc);
42 47
 

+ 1
- 1
Test/Utils/DataAccess/LuUtilsPkBigSerialDataAccess.cs Прегледај датотеку

@@ -4,7 +4,7 @@ using Test.Utils.Dbo.PkBigSerial;
4 4
 
5 5
 namespace Test.Utils.DataAccess
6 6
 {
7
-    public class LuUtilsPkBigSerialDataAccess : LuEfCrudInterface<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext>
7
+    public class LuUtilsPkBigSerialDataAccess : LuEfCrudDataAccess<pk_bigserial, PkBigSerialAddDbo, PkBigSerialDbo, PkBigSerialAddDbo, LuUtilsDbContext>
8 8
     {
9 9
         public LuUtilsPkBigSerialDataAccess(LuUtilsDbContext db) : base(db, db.pk_bigserial)
10 10
         {

+ 1
- 1
Test/Utils/DataAccess/LuUtilsPkGuidDataAccess.cs Прегледај датотеку

@@ -4,7 +4,7 @@ using Test.Utils.Dbo.PkGuid;
4 4
 
5 5
 namespace Test.Utils.DataAccess
6 6
 {
7
-    public class LuUtilsPkGuidDataAccess : LuEfCrudInterface<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext>
7
+    public class LuUtilsPkGuidDataAccess : LuEfCrudDataAccess<pk_guid, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo, LuUtilsDbContext>
8 8
     {
9 9
         public LuUtilsPkGuidDataAccess(LuUtilsDbContext db) : base(db, db.pk_guid)
10 10
         {

+ 113
- 18
Test/Utils/EfCrudDataAccess/LuEfReadDataAccessTest.cs Прегледај датотеку

@@ -2,12 +2,13 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using Luticate2.Utils.Dbo;
5
+using Luticate2.Utils.Dbo.OrderBy;
5 6
 using Test.Utils.DataAccess;
6 7
 using Test.Utils.Dbo.PkBigSerial;
7 8
 using Test.Utils.Dbo.PkGuid;
8 9
 using Xunit;
9 10
 
10
-namespace Test.Utils.EfCrubDataAccess
11
+namespace Test.Utils.EfCrudDataAccess
11 12
 {
12 13
     public class LuEfReadDataAccessTest
13 14
     {
@@ -195,7 +196,7 @@ namespace Test.Utils.EfCrubDataAccess
195 196
                     },
196 197
                     new PkGuidAddDbo
197 198
                     {
198
-                        SomeInt = 24,
199
+                        SomeInt = 142,
199 200
                         SomeText = "24"
200 201
                     }
201 202
                 };
@@ -204,8 +205,7 @@ namespace Test.Utils.EfCrubDataAccess
204 205
                 Assert.Equal(LuStatus.Success, res.Status);
205 206
 
206 207
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
207
-                    guid => guid.some_int == 42, 0, int.MaxValue, set => set.OrderBy(guid => guid.some_text));
208
-
208
+                    guid => guid.some_int == 42, 0, int.MaxValue, set => set.ThenBy(guid => guid.some_text));
209 209
                 Assert.Equal(LuStatus.Success, get.Status);
210 210
                 Assert.Equal(2, get.Data.Count);
211 211
                 Assert.Equal(2, get.Data.Data.Count);
@@ -239,7 +239,7 @@ namespace Test.Utils.EfCrubDataAccess
239 239
                     },
240 240
                     new PkGuidAddDbo
241 241
                     {
242
-                        SomeInt = 24,
242
+                        SomeInt = 142,
243 243
                         SomeText = "24"
244 244
                     }
245 245
                 };
@@ -249,7 +249,6 @@ namespace Test.Utils.EfCrubDataAccess
249 249
 
250 250
                 var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
251 251
                     guid => guid.some_text);
252
-
253 252
                 Assert.Equal(LuStatus.Success, get.Status);
254 253
                 Assert.Equal(2, get.Data.Count);
255 254
                 Assert.Equal(2, get.Data.Data.Count);
@@ -283,7 +282,7 @@ namespace Test.Utils.EfCrubDataAccess
283 282
                     },
284 283
                     new PkGuidAddDbo
285 284
                     {
286
-                        SomeInt = 24,
285
+                        SomeInt = 142,
287 286
                         SomeText = "24"
288 287
                     }
289 288
                 };
@@ -292,23 +291,22 @@ namespace Test.Utils.EfCrubDataAccess
292 291
                 Assert.Equal(LuStatus.Success, res.Status);
293 292
 
294 293
                 var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
295
-                    set => set.OrderBy(guid => guid.some_text));
296
-
294
+                    set => set.ThenBy(guid => guid.some_text));
297 295
                 Assert.Equal(LuStatus.Success, get.Status);
298 296
                 Assert.Equal(3, get.Data.Count);
299 297
                 Assert.Equal(3, get.Data.Data.Count);
300 298
 
301 299
                 var dbo = get.Data.Data[0];
302
-                Assert.Equal(24, dbo.SomeInt);
303
-                Assert.Equal("24", dbo.SomeText);
304
-
305
-                dbo = get.Data.Data[1];
306 300
                 Assert.Equal(42, dbo.SomeInt);
307 301
                 Assert.Equal("42", dbo.SomeText);
308 302
 
309
-                dbo = get.Data.Data[2];
303
+                dbo = get.Data.Data[1];
310 304
                 Assert.Equal(42, dbo.SomeInt);
311 305
                 Assert.Equal("442", dbo.SomeText);
306
+
307
+                dbo = get.Data.Data[2];
308
+                Assert.Equal(142, dbo.SomeInt);
309
+                Assert.Equal("24", dbo.SomeText);
312 310
             });
313 311
         }
314 312
 
@@ -331,7 +329,7 @@ namespace Test.Utils.EfCrubDataAccess
331 329
                     },
332 330
                     new PkGuidAddDbo
333 331
                     {
334
-                        SomeInt = 24,
332
+                        SomeInt = 142,
335 333
                         SomeText = "24"
336 334
                     }
337 335
                 };
@@ -340,22 +338,119 @@ namespace Test.Utils.EfCrubDataAccess
340 338
                 Assert.Equal(LuStatus.Success, res.Status);
341 339
 
342 340
                 var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
343
-
344 341
                 Assert.Equal(LuStatus.Success, get.Status);
345 342
                 Assert.Equal(3, get.Data.Count);
346 343
                 Assert.Equal(3, get.Data.Data.Count);
347 344
 
348 345
                 var dbo = get.Data.Data[0];
349
-                Assert.Equal(24, dbo.SomeInt);
350
-                Assert.Equal("24", dbo.SomeText);
346
+                Assert.Equal(42, dbo.SomeInt);
347
+                Assert.Equal("42", dbo.SomeText);
351 348
 
352 349
                 dbo = get.Data.Data[1];
353 350
                 Assert.Equal(42, dbo.SomeInt);
351
+                Assert.Equal("442", dbo.SomeText);
352
+
353
+                dbo = get.Data.Data[2];
354
+                Assert.Equal(142, dbo.SomeInt);
355
+                Assert.Equal("24", dbo.SomeText);
356
+            });
357
+        }
358
+
359
+        [Fact]
360
+        public void TestGetMultiple5()
361
+        {
362
+            Tests.TestRealDb(context =>
363
+            {
364
+                var dbos = new List<PkGuidAddDbo>
365
+                {
366
+                    new PkGuidAddDbo
367
+                    {
368
+                        SomeInt = 42,
369
+                        SomeText = "442"
370
+                    },
371
+                    new PkGuidAddDbo
372
+                    {
373
+                        SomeInt = 42,
374
+                        SomeText = "42"
375
+                    },
376
+                    new PkGuidAddDbo
377
+                    {
378
+                        SomeInt = 142,
379
+                        SomeText = "24"
380
+                    }
381
+                };
382
+                var service = new LuUtilsPkGuidDataAccess(context);
383
+                var res = service.AddGuid(dbos);
384
+                Assert.Equal(LuStatus.Success, res.Status);
385
+
386
+                var orderBy = LuOrderByBinder.FromString("someInt,someText");
387
+                Assert.Equal(LuStatus.Success, orderBy.Status);
388
+
389
+                var get = service.GetMultiple(orderBy.Data);
390
+                Assert.Equal(LuStatus.Success, get.Status);
391
+                Assert.Equal(3, get.Data.Count);
392
+                Assert.Equal(3, get.Data.Data.Count);
393
+
394
+                var dbo = get.Data.Data[0];
395
+                Assert.Equal(42, dbo.SomeInt);
354 396
                 Assert.Equal("42", dbo.SomeText);
355 397
 
398
+                dbo = get.Data.Data[1];
399
+                Assert.Equal(42, dbo.SomeInt);
400
+                Assert.Equal("442", dbo.SomeText);
401
+
356 402
                 dbo = get.Data.Data[2];
403
+                Assert.Equal(142, dbo.SomeInt);
404
+                Assert.Equal("24", dbo.SomeText);
405
+            });
406
+        }
407
+
408
+        [Fact]
409
+        public void TestGetMultiple6()
410
+        {
411
+            Tests.TestRealDb(context =>
412
+            {
413
+                var dbos = new List<PkGuidAddDbo>
414
+                {
415
+                    new PkGuidAddDbo
416
+                    {
417
+                        SomeInt = 42,
418
+                        SomeText = "442"
419
+                    },
420
+                    new PkGuidAddDbo
421
+                    {
422
+                        SomeInt = 42,
423
+                        SomeText = "42"
424
+                    },
425
+                    new PkGuidAddDbo
426
+                    {
427
+                        SomeInt = 142,
428
+                        SomeText = "24"
429
+                    }
430
+                };
431
+                var service = new LuUtilsPkGuidDataAccess(context);
432
+                var res = service.AddGuid(dbos);
433
+                Assert.Equal(LuStatus.Success, res.Status);
434
+
435
+                var orderBy = LuOrderByBinder.FromString("someText:desc,someInt");
436
+                Assert.Equal(LuStatus.Success, orderBy.Status);
437
+
438
+                var get = service.GetMultiple(orderBy.Data);
439
+                Assert.Equal(LuStatus.Success, get.Status);
440
+                Assert.Equal(3, get.Data.Count);
441
+                Assert.Equal(3, get.Data.Data.Count);
442
+
443
+                var dbo = get.Data.Data[0];
357 444
                 Assert.Equal(42, dbo.SomeInt);
358 445
                 Assert.Equal("442", dbo.SomeText);
446
+
447
+                dbo = get.Data.Data[1];
448
+                Assert.Equal(42, dbo.SomeInt);
449
+                Assert.Equal("42", dbo.SomeText);
450
+
451
+                dbo = get.Data.Data[2];
452
+                Assert.Equal(142, dbo.SomeInt);
453
+                Assert.Equal("24", dbo.SomeText);
359 454
             });
360 455
         }
361 456
     }

+ 1
- 1
WebTest/Business/PkGuidBusiness.cs Прегледај датотеку

@@ -6,7 +6,7 @@ namespace WebTest.Business
6 6
 {
7 7
     public class PkGuidBusiness : LuCrudBusiness<LuUtilsPkGuidDataAccess, PkGuidAddDbo, PkGuidDbo, PkGuidAddDbo>
8 8
     {
9
-        public PkGuidBusiness(LuUtilsPkGuidDataAccess db) : base(db)
9
+        public PkGuidBusiness(LuUtilsPkGuidDataAccess nextCrud) : base(nextCrud)
10 10
         {
11 11
         }
12 12
     }

+ 5
- 4
WebTest/Controllers/PkGuidController.cs Прегледај датотеку

@@ -1,4 +1,6 @@
1
-using Luticate2.Utils.Controllers;
1
+using System.Collections.Generic;
2
+using Luticate2.Utils.Controllers;
3
+using Luticate2.Utils.Dbo;
2 4
 using Luticate2.Utils.Dbo.OrderBy;
3 5
 using Microsoft.AspNetCore.Mvc;
4 6
 using Test.Utils.Dbo.PkGuid;
@@ -22,10 +24,9 @@ namespace WebTest.Controllers
22 24
         }
23 25
 
24 26
         [Route("[controller]")]
25
-        public PkGuidDbo Get(LuOrderByDbo orderBy)
27
+        public LuPaginatedDbo<PkGuidDbo> Get(LuOrderByDbo orderBy, int page = 0, int perPage = int.MaxValue)
26 28
         {
27
-            return new PkGuidDbo();
28
-//            return Handle(_busines.GetMultiple());
29
+            return Handle(_busines.GetMultiple(orderBy, page, perPage));
29 30
         }
30 31
     }
31 32
 }

Loading…
Откажи
Сачувај