Browse Source

added LuUsersController; fixed UseLucticate location (before UseMvc()); tests

tags/v0.1.0
Robin Thoni 8 years ago
parent
commit
2c294d9b92

+ 14
- 0
Luticate2.Auth/Controllers/LuUsersController.cs View File

@@ -0,0 +1,14 @@
1
+using Luticate2.Utils.Controllers;
2
+using Microsoft.AspNetCore.Mvc;
3
+
4
+namespace Luticate2.Auth.Controllers
5
+{
6
+    [Route("luticate/users")]
7
+    public class LuUsersController : LuController
8
+    {
9
+        public string Get()
10
+        {
11
+            return "users";
12
+        }
13
+    }
14
+}

+ 2
- 0
Luticate2.Auth/Controllers/LuticateExtensions.cs View File

@@ -14,6 +14,8 @@ namespace Luticate2.Auth.Controllers
14 14
             services.AddSingleton<LuGroupsBusiness>();
15 15
             services.AddSingleton<LuGroupsDataAccess>();
16 16
 
17
+            services.AddSingleton<LuUsersController>();
18
+
17 19
             services.AddDbContext<LuDatabaseContext>();
18 20
 
19 21
             return services;

+ 16
- 2
Luticate2.Auth/Middlewares/LuAuthMiddleware.cs View File

@@ -1,19 +1,33 @@
1
-using System.Threading.Tasks;
1
+using System;
2
+using System.Linq;
3
+using System.Reflection;
4
+using System.Threading.Tasks;
2 5
 using Microsoft.AspNetCore.Http;
6
+using Microsoft.AspNetCore.Mvc.Controllers;
7
+using Microsoft.AspNetCore.Mvc.Infrastructure;
3 8
 
4 9
 namespace Luticate2.Auth.Middlewares
5 10
 {
6 11
     public class LuAuthMiddleware
7 12
     {
8 13
         private readonly RequestDelegate _next;
14
+        private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider;
9 15
 
10
-        public LuAuthMiddleware(RequestDelegate next)
16
+        public LuAuthMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
11 17
         {
12 18
             _next = next;
19
+            _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
13 20
         }
14 21
 
15 22
         public async Task Invoke(HttpContext context)
16 23
         {
24
+//            var items = _actionDescriptorCollectionProvider.ActionDescriptors.Items;
25
+//            var item = items.FirstOrDefault();
26
+//            var actionDescriptor = item as ControllerActionDescriptor;
27
+//            if (actionDescriptor != null)
28
+//            {
29
+////                actionDescriptor.MethodInfo.GetCustomAttributes()
30
+//            }
17 31
             await _next.Invoke(context);
18 32
         }
19 33
     }

+ 0
- 351
Test/Utils/EfCrubDataAccess/LuEfCreateDataAccessTest.cs View File

@@ -1,9 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
-using System.Diagnostics;
4 3
 using System.Linq;
5 4
 using Luticate2.Utils.Dbo;
6
-using Microsoft.AspNetCore.Mvc.Controllers;
7 5
 using Test.Utils.DataAccess;
8 6
 using Test.Utils.Dbo.PkBigSerial;
9 7
 using Test.Utils.Dbo.PkGuid;
@@ -383,354 +381,5 @@ namespace Test.Utils.EfCrubDataAccess
383 381
                 Assert.Equal(res.Data.Id, get.Data.Id);
384 382
             });
385 383
         }
386
-
387
-
388
-        [Fact]
389
-        public void TestGetSingle1()
390
-        {
391
-            Tests.TestRealDb(context =>
392
-            {
393
-                var service = new LuUtilsPkBigSerialDataAccess(context);
394
-                var res = service.AddDbo(new PkBigSerialAddDbo
395
-                {
396
-                    SomeInt = 42,
397
-                    SomeText = "42"
398
-                });
399
-                Assert.Equal(LuStatus.Success, res.Status);
400
-                Assert.NotEqual(0, res.Data.Id);
401
-
402
-                var get = service.GetSingle(bigserial => bigserial.some_int == 42);
403
-                Assert.Equal(LuStatus.Success, get.Status);
404
-                Assert.Equal("42", get.Data.SomeText);
405
-                Assert.Equal(42, get.Data.SomeInt);
406
-                Assert.Equal(res.Data.Id, get.Data.Id);
407
-            });
408
-        }
409
-
410
-        [Fact]
411
-        public void TestGetSingle2()
412
-        {
413
-            Tests.TestRealDb(context =>
414
-            {
415
-                var service = new LuUtilsPkBigSerialDataAccess(context);
416
-                var res = service.AddDbo(new PkBigSerialAddDbo
417
-                {
418
-                    SomeInt = 42,
419
-                    SomeText = "42"
420
-                });
421
-                Assert.Equal(LuStatus.Success, res.Status);
422
-                Assert.NotEqual(0, res.Data.Id);
423
-
424
-                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
425
-                Assert.Equal(LuStatus.NotFound, get.Status);
426
-            });
427
-        }
428
-
429
-
430
-        [Fact]
431
-        public void TestGetSingleByKeys1()
432
-        {
433
-            Tests.TestRealDb(context =>
434
-            {
435
-                var service = new LuUtilsPkBigSerialDataAccess(context);
436
-                var res = service.AddDbo(new PkBigSerialAddDbo
437
-                {
438
-                    SomeInt = 42,
439
-                    SomeText = "42"
440
-                });
441
-                Assert.Equal(LuStatus.Success, res.Status);
442
-                Assert.NotEqual(0, res.Data.Id);
443
-
444
-                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "42"));
445
-                Assert.Equal(LuStatus.Success, get.Status);
446
-                Assert.Equal("42", get.Data.SomeText);
447
-                Assert.Equal(42, get.Data.SomeInt);
448
-                Assert.Equal(res.Data.Id, get.Data.Id);
449
-            });
450
-        }
451
-
452
-        [Fact]
453
-        public void TestGetSingleByKeys2()
454
-        {
455
-            Tests.TestRealDb(context =>
456
-            {
457
-                var service = new LuUtilsPkBigSerialDataAccess(context);
458
-                var res = service.AddDbo(new PkBigSerialAddDbo
459
-                {
460
-                    SomeInt = 42,
461
-                    SomeText = "42"
462
-                });
463
-                Assert.Equal(LuStatus.Success, res.Status);
464
-                Assert.NotEqual(0, res.Data.Id);
465
-
466
-                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
467
-                Assert.Equal(LuStatus.NotFound, get.Status);
468
-            });
469
-        }
470
-
471
-        [Fact]
472
-        public void TestGetSingleById1()
473
-        {
474
-            Tests.TestRealDb(context =>
475
-            {
476
-                var service = new LuUtilsPkBigSerialDataAccess(context);
477
-                var res = service.AddId(new PkBigSerialAddDbo
478
-                {
479
-                    SomeInt = 42,
480
-                    SomeText = "42"
481
-                });
482
-                Assert.Equal(LuStatus.Success, res.Status);
483
-                Assert.NotEqual(0, res.Data);
484
-
485
-                var get = service.GetSingleById(res.Data);
486
-                Assert.Equal(LuStatus.Success, get.Status);
487
-                Assert.Equal("42", get.Data.SomeText);
488
-                Assert.Equal(42, get.Data.SomeInt);
489
-                Assert.Equal(res.Data, get.Data.Id);
490
-            });
491
-        }
492
-
493
-        [Fact]
494
-        public void TestGetSingleById2()
495
-        {
496
-            Tests.TestRealDb(context =>
497
-            {
498
-                var service = new LuUtilsPkBigSerialDataAccess(context);
499
-                var res = service.AddId(new PkBigSerialAddDbo
500
-                {
501
-                    SomeInt = 42,
502
-                    SomeText = "42"
503
-                });
504
-                Assert.Equal(LuStatus.Success, res.Status);
505
-                Assert.NotEqual(0, res.Data);
506
-
507
-                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
508
-                Assert.Equal(LuStatus.NotFound, get.Status);
509
-            });
510
-        }
511
-
512
-        [Fact]
513
-        public void TestGetSingleById3()
514
-        {
515
-            Tests.TestRealDb(context =>
516
-            {
517
-                var service = new LuUtilsPkGuidDataAccess(context);
518
-                var res = service.AddGuid(new PkGuidAddDbo
519
-                {
520
-                    SomeInt = 42,
521
-                    SomeText = "42"
522
-                });
523
-                Assert.Equal(LuStatus.Success, res.Status);
524
-                Assert.NotEqual(new Guid().ToString(), res.Data);
525
-
526
-                var get = service.GetSingleById(res.Data);
527
-                Assert.Equal(LuStatus.Success, get.Status);
528
-                Assert.Equal("42", get.Data.SomeText);
529
-                Assert.Equal(42, get.Data.SomeInt);
530
-                Assert.Equal(res.Data, get.Data.Id);
531
-            });
532
-        }
533
-
534
-        [Fact]
535
-        public void TestGetSingleById4()
536
-        {
537
-            Tests.TestRealDb(context =>
538
-            {
539
-                var service = new LuUtilsPkGuidDataAccess(context);
540
-                var res = service.AddGuid(new PkGuidAddDbo
541
-                {
542
-                    SomeInt = 42,
543
-                    SomeText = "42"
544
-                });
545
-                Assert.Equal(LuStatus.Success, res.Status);
546
-                Assert.NotEqual(new Guid().ToString(), res.Data);
547
-
548
-                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
549
-                Assert.Equal(LuStatus.NotFound, get.Status);
550
-            });
551
-        }
552
-
553
-        [Fact]
554
-        public void TestGetMultiple1()
555
-        {
556
-            Tests.TestRealDb(context =>
557
-            {
558
-                var dbos = new List<PkGuidAddDbo>
559
-                {
560
-                    new PkGuidAddDbo
561
-                    {
562
-                        SomeInt = 42,
563
-                        SomeText = "442"
564
-                    },
565
-                    new PkGuidAddDbo
566
-                    {
567
-                        SomeInt = 42,
568
-                        SomeText = "42"
569
-                    },
570
-                    new PkGuidAddDbo
571
-                    {
572
-                        SomeInt = 24,
573
-                        SomeText = "24"
574
-                    }
575
-                };
576
-                var service = new LuUtilsPkGuidDataAccess(context);
577
-                var res = service.AddGuid(dbos);
578
-                Assert.Equal(LuStatus.Success, res.Status);
579
-
580
-                var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
581
-                    guid => guid.some_int == 42, 0, int.MaxValue, set => set.OrderBy(guid => guid.some_text));
582
-
583
-                Assert.Equal(LuStatus.Success, get.Status);
584
-                Assert.Equal(2, get.Data.Count);
585
-                Assert.Equal(2, get.Data.Data.Count);
586
-
587
-                var dbo = get.Data.Data[0];
588
-                Assert.Equal(42, dbo.SomeInt);
589
-                Assert.Equal("42", dbo.SomeText);
590
-
591
-                dbo = get.Data.Data[1];
592
-                Assert.Equal(42, dbo.SomeInt);
593
-                Assert.Equal("442", dbo.SomeText);
594
-            });
595
-        }
596
-
597
-        [Fact]
598
-        public void TestGetMultiple2()
599
-        {
600
-            Tests.TestRealDb(context =>
601
-            {
602
-                var dbos = new List<PkGuidAddDbo>
603
-                {
604
-                    new PkGuidAddDbo
605
-                    {
606
-                        SomeInt = 42,
607
-                        SomeText = "442"
608
-                    },
609
-                    new PkGuidAddDbo
610
-                    {
611
-                        SomeInt = 42,
612
-                        SomeText = "42"
613
-                    },
614
-                    new PkGuidAddDbo
615
-                    {
616
-                        SomeInt = 24,
617
-                        SomeText = "24"
618
-                    }
619
-                };
620
-                var service = new LuUtilsPkGuidDataAccess(context);
621
-                var res = service.AddGuid(dbos);
622
-                Assert.Equal(LuStatus.Success, res.Status);
623
-
624
-                var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
625
-                    guid => guid.some_text);
626
-
627
-                Assert.Equal(LuStatus.Success, get.Status);
628
-                Assert.Equal(2, get.Data.Count);
629
-                Assert.Equal(2, get.Data.Data.Count);
630
-
631
-                var dbo = get.Data.Data[0];
632
-                Assert.Equal(42, dbo.SomeInt);
633
-                Assert.Equal("42", dbo.SomeText);
634
-
635
-                dbo = get.Data.Data[1];
636
-                Assert.Equal(42, dbo.SomeInt);
637
-                Assert.Equal("442", dbo.SomeText);
638
-            });
639
-        }
640
-
641
-        [Fact]
642
-        public void TestGetMultiple3()
643
-        {
644
-            Tests.TestRealDb(context =>
645
-            {
646
-                var dbos = new List<PkGuidAddDbo>
647
-                {
648
-                    new PkGuidAddDbo
649
-                    {
650
-                        SomeInt = 42,
651
-                        SomeText = "442"
652
-                    },
653
-                    new PkGuidAddDbo
654
-                    {
655
-                        SomeInt = 42,
656
-                        SomeText = "42"
657
-                    },
658
-                    new PkGuidAddDbo
659
-                    {
660
-                        SomeInt = 24,
661
-                        SomeText = "24"
662
-                    }
663
-                };
664
-                var service = new LuUtilsPkGuidDataAccess(context);
665
-                var res = service.AddGuid(dbos);
666
-                Assert.Equal(LuStatus.Success, res.Status);
667
-
668
-                var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
669
-                    set => set.OrderBy(guid => guid.some_text));
670
-
671
-                Assert.Equal(LuStatus.Success, get.Status);
672
-                Assert.Equal(3, get.Data.Count);
673
-                Assert.Equal(3, get.Data.Data.Count);
674
-
675
-                var dbo = get.Data.Data[0];
676
-                Assert.Equal(24, dbo.SomeInt);
677
-                Assert.Equal("24", dbo.SomeText);
678
-
679
-                dbo = get.Data.Data[1];
680
-                Assert.Equal(42, dbo.SomeInt);
681
-                Assert.Equal("42", dbo.SomeText);
682
-
683
-                dbo = get.Data.Data[2];
684
-                Assert.Equal(42, dbo.SomeInt);
685
-                Assert.Equal("442", dbo.SomeText);
686
-            });
687
-        }
688
-
689
-        [Fact]
690
-        public void TestGetMultiple4()
691
-        {
692
-            Tests.TestRealDb(context =>
693
-            {
694
-                var dbos = new List<PkGuidAddDbo>
695
-                {
696
-                    new PkGuidAddDbo
697
-                    {
698
-                        SomeInt = 42,
699
-                        SomeText = "442"
700
-                    },
701
-                    new PkGuidAddDbo
702
-                    {
703
-                        SomeInt = 42,
704
-                        SomeText = "42"
705
-                    },
706
-                    new PkGuidAddDbo
707
-                    {
708
-                        SomeInt = 24,
709
-                        SomeText = "24"
710
-                    }
711
-                };
712
-                var service = new LuUtilsPkGuidDataAccess(context);
713
-                var res = service.AddGuid(dbos);
714
-                Assert.Equal(LuStatus.Success, res.Status);
715
-
716
-                var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
717
-
718
-                Assert.Equal(LuStatus.Success, get.Status);
719
-                Assert.Equal(3, get.Data.Count);
720
-                Assert.Equal(3, get.Data.Data.Count);
721
-
722
-                var dbo = get.Data.Data[0];
723
-                Assert.Equal(24, dbo.SomeInt);
724
-                Assert.Equal("24", dbo.SomeText);
725
-
726
-                dbo = get.Data.Data[1];
727
-                Assert.Equal(42, dbo.SomeInt);
728
-                Assert.Equal("42", dbo.SomeText);
729
-
730
-                dbo = get.Data.Data[2];
731
-                Assert.Equal(42, dbo.SomeInt);
732
-                Assert.Equal("442", dbo.SomeText);
733
-            });
734
-        }
735 384
     }
736 385
 }

+ 362
- 0
Test/Utils/EfCrubDataAccess/LuEfReadDataAccessTest.cs View File

@@ -0,0 +1,362 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using Luticate2.Utils.Dbo;
5
+using Test.Utils.DataAccess;
6
+using Test.Utils.Dbo.PkBigSerial;
7
+using Test.Utils.Dbo.PkGuid;
8
+using Xunit;
9
+
10
+namespace Test.Utils.EfCrubDataAccess
11
+{
12
+    public class LuEfReadDataAccessTest
13
+    {
14
+        [Fact]
15
+        public void TestGetSingle1()
16
+        {
17
+            Tests.TestRealDb(context =>
18
+            {
19
+                var service = new LuUtilsPkBigSerialDataAccess(context);
20
+                var res = service.AddDbo(new PkBigSerialAddDbo
21
+                {
22
+                    SomeInt = 42,
23
+                    SomeText = "42"
24
+                });
25
+                Assert.Equal(LuStatus.Success, res.Status);
26
+                Assert.NotEqual(0, res.Data.Id);
27
+
28
+                var get = service.GetSingle(bigserial => bigserial.some_int == 42);
29
+                Assert.Equal(LuStatus.Success, get.Status);
30
+                Assert.Equal("42", get.Data.SomeText);
31
+                Assert.Equal(42, get.Data.SomeInt);
32
+                Assert.Equal(res.Data.Id, get.Data.Id);
33
+            });
34
+        }
35
+
36
+        [Fact]
37
+        public void TestGetSingle2()
38
+        {
39
+            Tests.TestRealDb(context =>
40
+            {
41
+                var service = new LuUtilsPkBigSerialDataAccess(context);
42
+                var res = service.AddDbo(new PkBigSerialAddDbo
43
+                {
44
+                    SomeInt = 42,
45
+                    SomeText = "42"
46
+                });
47
+                Assert.Equal(LuStatus.Success, res.Status);
48
+                Assert.NotEqual(0, res.Data.Id);
49
+
50
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
51
+                Assert.Equal(LuStatus.NotFound, get.Status);
52
+            });
53
+        }
54
+
55
+
56
+        [Fact]
57
+        public void TestGetSingleByKeys1()
58
+        {
59
+            Tests.TestRealDb(context =>
60
+            {
61
+                var service = new LuUtilsPkBigSerialDataAccess(context);
62
+                var res = service.AddDbo(new PkBigSerialAddDbo
63
+                {
64
+                    SomeInt = 42,
65
+                    SomeText = "42"
66
+                });
67
+                Assert.Equal(LuStatus.Success, res.Status);
68
+                Assert.NotEqual(0, res.Data.Id);
69
+
70
+                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "42"));
71
+                Assert.Equal(LuStatus.Success, get.Status);
72
+                Assert.Equal("42", get.Data.SomeText);
73
+                Assert.Equal(42, get.Data.SomeInt);
74
+                Assert.Equal(res.Data.Id, get.Data.Id);
75
+            });
76
+        }
77
+
78
+        [Fact]
79
+        public void TestGetSingleByKeys2()
80
+        {
81
+            Tests.TestRealDb(context =>
82
+            {
83
+                var service = new LuUtilsPkBigSerialDataAccess(context);
84
+                var res = service.AddDbo(new PkBigSerialAddDbo
85
+                {
86
+                    SomeInt = 42,
87
+                    SomeText = "42"
88
+                });
89
+                Assert.Equal(LuStatus.Success, res.Status);
90
+                Assert.NotEqual(0, res.Data.Id);
91
+
92
+                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
93
+                Assert.Equal(LuStatus.NotFound, get.Status);
94
+            });
95
+        }
96
+
97
+        [Fact]
98
+        public void TestGetSingleById1()
99
+        {
100
+            Tests.TestRealDb(context =>
101
+            {
102
+                var service = new LuUtilsPkBigSerialDataAccess(context);
103
+                var res = service.AddId(new PkBigSerialAddDbo
104
+                {
105
+                    SomeInt = 42,
106
+                    SomeText = "42"
107
+                });
108
+                Assert.Equal(LuStatus.Success, res.Status);
109
+                Assert.NotEqual(0, res.Data);
110
+
111
+                var get = service.GetSingleById(res.Data);
112
+                Assert.Equal(LuStatus.Success, get.Status);
113
+                Assert.Equal("42", get.Data.SomeText);
114
+                Assert.Equal(42, get.Data.SomeInt);
115
+                Assert.Equal(res.Data, get.Data.Id);
116
+            });
117
+        }
118
+
119
+        [Fact]
120
+        public void TestGetSingleById2()
121
+        {
122
+            Tests.TestRealDb(context =>
123
+            {
124
+                var service = new LuUtilsPkBigSerialDataAccess(context);
125
+                var res = service.AddId(new PkBigSerialAddDbo
126
+                {
127
+                    SomeInt = 42,
128
+                    SomeText = "42"
129
+                });
130
+                Assert.Equal(LuStatus.Success, res.Status);
131
+                Assert.NotEqual(0, res.Data);
132
+
133
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
134
+                Assert.Equal(LuStatus.NotFound, get.Status);
135
+            });
136
+        }
137
+
138
+        [Fact]
139
+        public void TestGetSingleById3()
140
+        {
141
+            Tests.TestRealDb(context =>
142
+            {
143
+                var service = new LuUtilsPkGuidDataAccess(context);
144
+                var res = service.AddGuid(new PkGuidAddDbo
145
+                {
146
+                    SomeInt = 42,
147
+                    SomeText = "42"
148
+                });
149
+                Assert.Equal(LuStatus.Success, res.Status);
150
+                Assert.NotEqual(new Guid().ToString(), res.Data);
151
+
152
+                var get = service.GetSingleById(res.Data);
153
+                Assert.Equal(LuStatus.Success, get.Status);
154
+                Assert.Equal("42", get.Data.SomeText);
155
+                Assert.Equal(42, get.Data.SomeInt);
156
+                Assert.Equal(res.Data, get.Data.Id);
157
+            });
158
+        }
159
+
160
+        [Fact]
161
+        public void TestGetSingleById4()
162
+        {
163
+            Tests.TestRealDb(context =>
164
+            {
165
+                var service = new LuUtilsPkGuidDataAccess(context);
166
+                var res = service.AddGuid(new PkGuidAddDbo
167
+                {
168
+                    SomeInt = 42,
169
+                    SomeText = "42"
170
+                });
171
+                Assert.Equal(LuStatus.Success, res.Status);
172
+                Assert.NotEqual(new Guid().ToString(), res.Data);
173
+
174
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
175
+                Assert.Equal(LuStatus.NotFound, get.Status);
176
+            });
177
+        }
178
+
179
+        [Fact]
180
+        public void TestGetMultiple1()
181
+        {
182
+            Tests.TestRealDb(context =>
183
+            {
184
+                var dbos = new List<PkGuidAddDbo>
185
+                {
186
+                    new PkGuidAddDbo
187
+                    {
188
+                        SomeInt = 42,
189
+                        SomeText = "442"
190
+                    },
191
+                    new PkGuidAddDbo
192
+                    {
193
+                        SomeInt = 42,
194
+                        SomeText = "42"
195
+                    },
196
+                    new PkGuidAddDbo
197
+                    {
198
+                        SomeInt = 24,
199
+                        SomeText = "24"
200
+                    }
201
+                };
202
+                var service = new LuUtilsPkGuidDataAccess(context);
203
+                var res = service.AddGuid(dbos);
204
+                Assert.Equal(LuStatus.Success, res.Status);
205
+
206
+                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
+
209
+                Assert.Equal(LuStatus.Success, get.Status);
210
+                Assert.Equal(2, get.Data.Count);
211
+                Assert.Equal(2, get.Data.Data.Count);
212
+
213
+                var dbo = get.Data.Data[0];
214
+                Assert.Equal(42, dbo.SomeInt);
215
+                Assert.Equal("42", dbo.SomeText);
216
+
217
+                dbo = get.Data.Data[1];
218
+                Assert.Equal(42, dbo.SomeInt);
219
+                Assert.Equal("442", dbo.SomeText);
220
+            });
221
+        }
222
+
223
+        [Fact]
224
+        public void TestGetMultiple2()
225
+        {
226
+            Tests.TestRealDb(context =>
227
+            {
228
+                var dbos = new List<PkGuidAddDbo>
229
+                {
230
+                    new PkGuidAddDbo
231
+                    {
232
+                        SomeInt = 42,
233
+                        SomeText = "442"
234
+                    },
235
+                    new PkGuidAddDbo
236
+                    {
237
+                        SomeInt = 42,
238
+                        SomeText = "42"
239
+                    },
240
+                    new PkGuidAddDbo
241
+                    {
242
+                        SomeInt = 24,
243
+                        SomeText = "24"
244
+                    }
245
+                };
246
+                var service = new LuUtilsPkGuidDataAccess(context);
247
+                var res = service.AddGuid(dbos);
248
+                Assert.Equal(LuStatus.Success, res.Status);
249
+
250
+                var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
251
+                    guid => guid.some_text);
252
+
253
+                Assert.Equal(LuStatus.Success, get.Status);
254
+                Assert.Equal(2, get.Data.Count);
255
+                Assert.Equal(2, get.Data.Data.Count);
256
+
257
+                var dbo = get.Data.Data[0];
258
+                Assert.Equal(42, dbo.SomeInt);
259
+                Assert.Equal("42", dbo.SomeText);
260
+
261
+                dbo = get.Data.Data[1];
262
+                Assert.Equal(42, dbo.SomeInt);
263
+                Assert.Equal("442", dbo.SomeText);
264
+            });
265
+        }
266
+
267
+        [Fact]
268
+        public void TestGetMultiple3()
269
+        {
270
+            Tests.TestRealDb(context =>
271
+            {
272
+                var dbos = new List<PkGuidAddDbo>
273
+                {
274
+                    new PkGuidAddDbo
275
+                    {
276
+                        SomeInt = 42,
277
+                        SomeText = "442"
278
+                    },
279
+                    new PkGuidAddDbo
280
+                    {
281
+                        SomeInt = 42,
282
+                        SomeText = "42"
283
+                    },
284
+                    new PkGuidAddDbo
285
+                    {
286
+                        SomeInt = 24,
287
+                        SomeText = "24"
288
+                    }
289
+                };
290
+                var service = new LuUtilsPkGuidDataAccess(context);
291
+                var res = service.AddGuid(dbos);
292
+                Assert.Equal(LuStatus.Success, res.Status);
293
+
294
+                var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
295
+                    set => set.OrderBy(guid => guid.some_text));
296
+
297
+                Assert.Equal(LuStatus.Success, get.Status);
298
+                Assert.Equal(3, get.Data.Count);
299
+                Assert.Equal(3, get.Data.Data.Count);
300
+
301
+                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
+                Assert.Equal(42, dbo.SomeInt);
307
+                Assert.Equal("42", dbo.SomeText);
308
+
309
+                dbo = get.Data.Data[2];
310
+                Assert.Equal(42, dbo.SomeInt);
311
+                Assert.Equal("442", dbo.SomeText);
312
+            });
313
+        }
314
+
315
+        [Fact]
316
+        public void TestGetMultiple4()
317
+        {
318
+            Tests.TestRealDb(context =>
319
+            {
320
+                var dbos = new List<PkGuidAddDbo>
321
+                {
322
+                    new PkGuidAddDbo
323
+                    {
324
+                        SomeInt = 42,
325
+                        SomeText = "442"
326
+                    },
327
+                    new PkGuidAddDbo
328
+                    {
329
+                        SomeInt = 42,
330
+                        SomeText = "42"
331
+                    },
332
+                    new PkGuidAddDbo
333
+                    {
334
+                        SomeInt = 24,
335
+                        SomeText = "24"
336
+                    }
337
+                };
338
+                var service = new LuUtilsPkGuidDataAccess(context);
339
+                var res = service.AddGuid(dbos);
340
+                Assert.Equal(LuStatus.Success, res.Status);
341
+
342
+                var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
343
+
344
+                Assert.Equal(LuStatus.Success, get.Status);
345
+                Assert.Equal(3, get.Data.Count);
346
+                Assert.Equal(3, get.Data.Data.Count);
347
+
348
+                var dbo = get.Data.Data[0];
349
+                Assert.Equal(24, dbo.SomeInt);
350
+                Assert.Equal("24", dbo.SomeText);
351
+
352
+                dbo = get.Data.Data[1];
353
+                Assert.Equal(42, dbo.SomeInt);
354
+                Assert.Equal("42", dbo.SomeText);
355
+
356
+                dbo = get.Data.Data[2];
357
+                Assert.Equal(42, dbo.SomeInt);
358
+                Assert.Equal("442", dbo.SomeText);
359
+            });
360
+        }
361
+    }
362
+}

+ 223
- 0
Test/Utils/EfCrubDataAccess/LuEfUpdateDataAccessTest.cs View File

@@ -0,0 +1,223 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using Luticate2.Utils.Dbo;
5
+using Test.Utils.DataAccess;
6
+using Test.Utils.Dbo.PkBigSerial;
7
+using Test.Utils.Dbo.PkGuid;
8
+using Xunit;
9
+
10
+namespace Test.Utils.EfCrubDataAccess
11
+{
12
+    public class LuEfUpdateDataAccessTest
13
+    {
14
+        [Fact]
15
+        public void TestEditMultiple1()
16
+        {
17
+            Tests.TestRealDb(context =>
18
+            {
19
+                var dbos = new List<PkGuidAddDbo>
20
+                {
21
+                    new PkGuidAddDbo
22
+                    {
23
+                        SomeInt = 42,
24
+                        SomeText = "442"
25
+                    },
26
+                    new PkGuidAddDbo
27
+                    {
28
+                        SomeInt = 42,
29
+                        SomeText = "42"
30
+                    },
31
+                    new PkGuidAddDbo
32
+                    {
33
+                        SomeInt = 24,
34
+                        SomeText = "24"
35
+                    }
36
+                };
37
+                var service = new LuUtilsPkGuidDataAccess(context);
38
+                var res = service.AddGuid(dbos);
39
+                Assert.Equal(LuStatus.Success, res.Status);
40
+
41
+                var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable);
42
+
43
+                Assert.Equal(LuStatus.Success, edit.Status);
44
+                var elements = edit.Data.ToList();
45
+                Assert.Equal(2, elements.Count);
46
+
47
+                var e = elements[0];
48
+                Assert.Equal(-1, e.SomeInt);
49
+                Assert.Equal("442", e.SomeText);
50
+
51
+                e = elements[1];
52
+                Assert.Equal(-1, e.SomeInt);
53
+                Assert.Equal("42", e.SomeText);
54
+            });
55
+        }
56
+
57
+        [Fact]
58
+        public void TestEditMultiple2()
59
+        {
60
+            Tests.TestRealDb(context =>
61
+            {
62
+                var dbos = new List<PkGuidAddDbo>
63
+                {
64
+                    new PkGuidAddDbo
65
+                    {
66
+                        SomeInt = 42,
67
+                        SomeText = "442"
68
+                    },
69
+                    new PkGuidAddDbo
70
+                    {
71
+                        SomeInt = 42,
72
+                        SomeText = "42"
73
+                    },
74
+                    new PkGuidAddDbo
75
+                    {
76
+                        SomeInt = 24,
77
+                        SomeText = "24"
78
+                    }
79
+                };
80
+                var service = new LuUtilsPkGuidDataAccess(context);
81
+                var res = service.AddGuid(dbos);
82
+                Assert.Equal(LuStatus.Success, res.Status);
83
+
84
+                var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable.Select(guidDbo => guidDbo.SomeText));
85
+
86
+                Assert.Equal(LuStatus.Success, edit.Status);
87
+                var elements = edit.Data.ToList();
88
+                Assert.Equal(2, elements.Count);
89
+
90
+                var e = elements[0];
91
+                Assert.Equal("442", e);
92
+
93
+                e = elements[1];
94
+                Assert.Equal("42", e);
95
+            });
96
+        }
97
+
98
+        [Fact]
99
+        public void TestEditMultiple3()
100
+        {
101
+            Tests.TestRealDb(context =>
102
+            {
103
+                var dbos = new List<PkGuidAddDbo>
104
+                {
105
+                    new PkGuidAddDbo
106
+                    {
107
+                        SomeInt = 42,
108
+                        SomeText = "442"
109
+                    },
110
+                    new PkGuidAddDbo
111
+                    {
112
+                        SomeInt = 42,
113
+                        SomeText = "42"
114
+                    },
115
+                    new PkGuidAddDbo
116
+                    {
117
+                        SomeInt = 24,
118
+                        SomeText = "24"
119
+                    }
120
+                };
121
+                var service = new LuUtilsPkGuidDataAccess(context);
122
+                var res = service.AddGuid(dbos);
123
+                Assert.Equal(LuStatus.Success, res.Status);
124
+
125
+                var edit = service.EditGuid(guid => guid.some_int == 42, guid => guid.some_int = -1);
126
+
127
+                Assert.Equal(LuStatus.Success, edit.Status);
128
+                var elements = edit.Data.ToList();
129
+                Assert.Equal(2, elements.Count);
130
+
131
+                var e = elements[0];
132
+                Assert.NotEqual(new Guid().ToString(), e);
133
+
134
+                e = elements[1];
135
+                Assert.NotEqual(new Guid().ToString(), e);
136
+            });
137
+        }
138
+
139
+        [Fact]
140
+        public void TestEditMultiple4()
141
+        {
142
+            Tests.TestRealDb(context =>
143
+            {
144
+                var dbos = new List<PkBigSerialAddDbo>
145
+                {
146
+                    new PkBigSerialAddDbo
147
+                    {
148
+                        SomeInt = 42,
149
+                        SomeText = "442"
150
+                    },
151
+                    new PkBigSerialAddDbo
152
+                    {
153
+                        SomeInt = 42,
154
+                        SomeText = "42"
155
+                    },
156
+                    new PkBigSerialAddDbo
157
+                    {
158
+                        SomeInt = 24,
159
+                        SomeText = "24"
160
+                    }
161
+                };
162
+                var service = new LuUtilsPkBigSerialDataAccess(context);
163
+                var res = service.AddId(dbos);
164
+                Assert.Equal(LuStatus.Success, res.Status);
165
+
166
+                var edit = service.EditId(guid => guid.some_int == 42, guid => guid.some_int = -1);
167
+
168
+                Assert.Equal(LuStatus.Success, edit.Status);
169
+                var elements = edit.Data.ToList();
170
+                Assert.Equal(2, elements.Count);
171
+
172
+                var e = elements[0];
173
+                Assert.NotEqual(0, e);
174
+
175
+                e = elements[1];
176
+                Assert.NotEqual(0, e);
177
+            });
178
+        }
179
+
180
+        [Fact]
181
+        public void TestEditMultiple5()
182
+        {
183
+            Tests.TestRealDb(context =>
184
+            {
185
+                var dbos = new List<PkGuidAddDbo>
186
+                {
187
+                    new PkGuidAddDbo
188
+                    {
189
+                        SomeInt = 42,
190
+                        SomeText = "442"
191
+                    },
192
+                    new PkGuidAddDbo
193
+                    {
194
+                        SomeInt = 42,
195
+                        SomeText = "42"
196
+                    },
197
+                    new PkGuidAddDbo
198
+                    {
199
+                        SomeInt = 24,
200
+                        SomeText = "24"
201
+                    }
202
+                };
203
+                var service = new LuUtilsPkGuidDataAccess(context);
204
+                var res = service.AddGuid(dbos);
205
+                Assert.Equal(LuStatus.Success, res.Status);
206
+
207
+                var edit = service.EditDbo(guid => guid.some_int == 42, guid => guid.some_int = -1);
208
+
209
+                Assert.Equal(LuStatus.Success, edit.Status);
210
+                var elements = edit.Data.ToList();
211
+                Assert.Equal(2, elements.Count);
212
+
213
+                var e = elements[0];
214
+                Assert.Equal(-1, e.SomeInt);
215
+                Assert.Equal("442", e.SomeText);
216
+
217
+                e = elements[1];
218
+                Assert.Equal(-1, e.SomeInt);
219
+                Assert.Equal("42", e.SomeText);
220
+            });
221
+        }
222
+    }
223
+}

+ 2
- 2
WebTest/Startup.cs View File

@@ -51,9 +51,9 @@ namespace WebTest
51 51
 
52 52
             app.UseApplicationInsightsExceptionTelemetry();
53 53
 
54
-            app.UseMvc();
55
-
56 54
             app.UseLuticate();
55
+
56
+            app.UseMvc();
57 57
         }
58 58
     }
59 59
 }

Loading…
Cancel
Save