Browse Source

tests

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

+ 3
- 0
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs View File

@@ -61,6 +61,7 @@ namespace Luticate2.Utils.DataAccess
61 61
             return Add(new List<TDboCreate> {obj}, list => returnFunc(list.First()));
62 62
         }
63 63
 
64
+
64 65
         public LuResult<IEnumerable<string>> AddGuid(IEnumerable<TDboCreate> objs)
65 66
         {
66 67
             var func = GetIdFunc<string>();
@@ -72,6 +73,7 @@ namespace Luticate2.Utils.DataAccess
72 73
             return AddGuid(new List<TDboCreate> {obj}).To(list => list.First());
73 74
         }
74 75
 
76
+
75 77
         public LuResult<IEnumerable<long>> AddId(IEnumerable<TDboCreate> obj)
76 78
         {
77 79
             var func = GetIdFunc<long>();
@@ -83,6 +85,7 @@ namespace Luticate2.Utils.DataAccess
83 85
             return AddId(new List<TDboCreate> {obj}).To(list => list.First());
84 86
         }
85 87
 
88
+
86 89
         public LuResult<IEnumerable<TDboRead>> AddDbo(IEnumerable<TDboCreate> obj)
87 90
         {
88 91
             return Add(obj, read => read);

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

@@ -357,5 +357,171 @@ namespace Test.Utils.EfCrubDataAccess
357 357
                 Assert.Equal(res.Data.Id, get.Data.Id);
358 358
             });
359 359
         }
360
+
361
+
362
+        [Fact]
363
+        public void TestGetSingle1()
364
+        {
365
+            Tests.TestRealDb(context =>
366
+            {
367
+                var service = new LuUtilsPkBigSerialDataAccess(context);
368
+                var res = service.AddDbo(new PkBigSerialAddDbo
369
+                {
370
+                    SomeInt = 42,
371
+                    SomeText = "42"
372
+                });
373
+                Assert.Equal(LuStatus.Success, res.Status);
374
+                Assert.NotEqual(0, res.Data.Id);
375
+
376
+                var get = service.GetSingle(bigserial => bigserial.some_int == 42);
377
+                Assert.Equal(LuStatus.Success, get.Status);
378
+                Assert.Equal("42", get.Data.SomeText);
379
+                Assert.Equal(42, get.Data.SomeInt);
380
+                Assert.Equal(res.Data.Id, get.Data.Id);
381
+            });
382
+        }
383
+
384
+        [Fact]
385
+        public void TestGetSingle2()
386
+        {
387
+            Tests.TestRealDb(context =>
388
+            {
389
+                var service = new LuUtilsPkBigSerialDataAccess(context);
390
+                var res = service.AddDbo(new PkBigSerialAddDbo
391
+                {
392
+                    SomeInt = 42,
393
+                    SomeText = "42"
394
+                });
395
+                Assert.Equal(LuStatus.Success, res.Status);
396
+                Assert.NotEqual(0, res.Data.Id);
397
+
398
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
399
+                Assert.Equal(LuStatus.NotFound, get.Status);
400
+            });
401
+        }
402
+
403
+
404
+        [Fact]
405
+        public void TestGetSingleByKeys1()
406
+        {
407
+            Tests.TestRealDb(context =>
408
+            {
409
+                var service = new LuUtilsPkBigSerialDataAccess(context);
410
+                var res = service.AddDbo(new PkBigSerialAddDbo
411
+                {
412
+                    SomeInt = 42,
413
+                    SomeText = "42"
414
+                });
415
+                Assert.Equal(LuStatus.Success, res.Status);
416
+                Assert.NotEqual(0, res.Data.Id);
417
+
418
+                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "42"));
419
+                Assert.Equal(LuStatus.Success, get.Status);
420
+                Assert.Equal("42", get.Data.SomeText);
421
+                Assert.Equal(42, get.Data.SomeInt);
422
+                Assert.Equal(res.Data.Id, get.Data.Id);
423
+            });
424
+        }
425
+
426
+        [Fact]
427
+        public void TestGetSingleByKeys2()
428
+        {
429
+            Tests.TestRealDb(context =>
430
+            {
431
+                var service = new LuUtilsPkBigSerialDataAccess(context);
432
+                var res = service.AddDbo(new PkBigSerialAddDbo
433
+                {
434
+                    SomeInt = 42,
435
+                    SomeText = "42"
436
+                });
437
+                Assert.Equal(LuStatus.Success, res.Status);
438
+                Assert.NotEqual(0, res.Data.Id);
439
+
440
+                var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
441
+                Assert.Equal(LuStatus.NotFound, get.Status);
442
+            });
443
+        }
444
+
445
+        [Fact]
446
+        public void TestGetSingleById1()
447
+        {
448
+            Tests.TestRealDb(context =>
449
+            {
450
+                var service = new LuUtilsPkBigSerialDataAccess(context);
451
+                var res = service.AddId(new PkBigSerialAddDbo
452
+                {
453
+                    SomeInt = 42,
454
+                    SomeText = "42"
455
+                });
456
+                Assert.Equal(LuStatus.Success, res.Status);
457
+                Assert.NotEqual(0, res.Data);
458
+
459
+                var get = service.GetSingleById(res.Data);
460
+                Assert.Equal(LuStatus.Success, get.Status);
461
+                Assert.Equal("42", get.Data.SomeText);
462
+                Assert.Equal(42, get.Data.SomeInt);
463
+                Assert.Equal(res.Data, get.Data.Id);
464
+            });
465
+        }
466
+
467
+        [Fact]
468
+        public void TestGetSingleById2()
469
+        {
470
+            Tests.TestRealDb(context =>
471
+            {
472
+                var service = new LuUtilsPkBigSerialDataAccess(context);
473
+                var res = service.AddId(new PkBigSerialAddDbo
474
+                {
475
+                    SomeInt = 42,
476
+                    SomeText = "42"
477
+                });
478
+                Assert.Equal(LuStatus.Success, res.Status);
479
+                Assert.NotEqual(0, res.Data);
480
+
481
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
482
+                Assert.Equal(LuStatus.NotFound, get.Status);
483
+            });
484
+        }
485
+
486
+        [Fact]
487
+        public void TestGetSingleById3()
488
+        {
489
+            Tests.TestRealDb(context =>
490
+            {
491
+                var service = new LuUtilsPkGuidDataAccess(context);
492
+                var res = service.AddGuid(new PkGuidAddDbo
493
+                {
494
+                    SomeInt = 42,
495
+                    SomeText = "42"
496
+                });
497
+                Assert.Equal(LuStatus.Success, res.Status);
498
+                Assert.NotEqual(new Guid().ToString(), res.Data);
499
+
500
+                var get = service.GetSingleById(res.Data);
501
+                Assert.Equal(LuStatus.Success, get.Status);
502
+                Assert.Equal("42", get.Data.SomeText);
503
+                Assert.Equal(42, get.Data.SomeInt);
504
+                Assert.Equal(res.Data, get.Data.Id);
505
+            });
506
+        }
507
+
508
+        [Fact]
509
+        public void TestGetSingleById4()
510
+        {
511
+            Tests.TestRealDb(context =>
512
+            {
513
+                var service = new LuUtilsPkGuidDataAccess(context);
514
+                var res = service.AddGuid(new PkGuidAddDbo
515
+                {
516
+                    SomeInt = 42,
517
+                    SomeText = "42"
518
+                });
519
+                Assert.Equal(LuStatus.Success, res.Status);
520
+                Assert.NotEqual(new Guid().ToString(), res.Data);
521
+
522
+                var get = service.GetSingle(bigserial => bigserial.some_int == 24);
523
+                Assert.Equal(LuStatus.NotFound, get.Status);
524
+            });
525
+        }
360 526
     }
361 527
 }

Loading…
Cancel
Save