123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Luticate2.Utils.Dbo;
- using Luticate2.Utils.Dbo.Result;
- using Test.Utils.DataAccess;
- using Test.Utils.Dbo.PkBigSerial;
- using Test.Utils.Dbo.PkGuid;
- using Xunit;
-
- namespace Test.Utils.EfCrubDataAccess
- {
- public class LuEfCreateDataAccessTest
- {
- [Fact]
- public void TestAddMultiple1()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(dbos, enumerable => enumerable);
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, PkBigSerialDbo>(dbo, serialDbo)))
- {
- Assert.NotNull(dbo.Key);
- Assert.NotNull(dbo.Value);
-
- Assert.NotEqual(0, dbo.Value.Id);
- Assert.Equal(dbo.Key.SomeText, dbo.Value.SomeText);
- Assert.Equal(dbo.Key.SomeInt, dbo.Value.SomeInt);
-
- var get = service.GetSingleById(dbo.Value.Id);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
- Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
- Assert.Equal(dbo.Value.Id, get.Data.Id);
- }
- });
- }
-
- [Fact]
- public void TestAddMultiple2()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.Id));
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, long>(dbo, serialDbo)))
- {
- Assert.NotNull(dbo.Key);
- Assert.NotNull(dbo.Value);
-
- Assert.NotEqual(0, dbo.Value);
-
- var get = service.GetSingleById(dbo.Value);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
- Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
- Assert.Equal(dbo.Value, get.Data.Id);
- }
- });
- }
-
- [Fact]
- public void TestAddMultiple3()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.CreatedAt));
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in res.Data)
- {
- Assert.NotEqual(default(DateTime), dbo);
- }
- });
- }
-
- [Fact]
- public void TestAddMultiple4()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "42"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.CreatedAt));
- Assert.Equal(LuStatus.DbError, res.Status);
- });
- }
-
-
- [Fact]
- public void TestAddSingle1()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- }, dbo => dbo);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(0, res.Data.Id);
- Assert.Equal("42", res.Data.SomeText);
- Assert.Equal(42, res.Data.SomeInt);
-
- var get = service.GetSingleById(res.Data.Id);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal("42", get.Data.SomeText);
- Assert.Equal(42, get.Data.SomeInt);
- Assert.Equal(res.Data.Id, get.Data.Id);
- });
- }
-
- [Fact]
- public void TestAddSingle2()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- }, dbo => dbo.Id);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(0, res.Data);
-
- var get = service.GetSingleById(res.Data);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal("42", get.Data.SomeText);
- Assert.Equal(42, get.Data.SomeInt);
- Assert.Equal(res.Data, get.Data.Id);
- });
- }
-
- [Fact]
- public void TestAddSingle3()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.Add(new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- }, dbo => dbo.CreatedAt);
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(default(DateTime), res.Data);
- });
- }
-
- [Fact]
- public void TestAddGuidMultiple1()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkGuidAddDbo>
- {
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkGuidAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddId(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkGuidAddDbo, string>(dbo, serialDbo)))
- {
- Assert.NotNull(dbo.Key);
- Assert.NotNull(dbo.Value);
-
- Assert.NotEqual(new Guid().ToString(), dbo.Value);
-
- var get = service.GetSingleById(dbo.Value);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
- Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
- Assert.Equal(dbo.Value, get.Data.Id);
- }
- });
- }
-
-
- [Fact]
- public void TestAddGuidSingle1()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddId(new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- });
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(new Guid().ToString(), res.Data);
-
- var get = service.GetSingleById(res.Data);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal("42", get.Data.SomeText);
- Assert.Equal(42, get.Data.SomeInt);
- Assert.Equal(res.Data, get.Data.Id);
- });
- }
-
- [Fact]
- public void TestAddIdMultiple1()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.AddId(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, long>(dbo, serialDbo)))
- {
- Assert.NotNull(dbo.Key);
- Assert.NotNull(dbo.Value);
-
- Assert.NotEqual(0, dbo.Value);
-
- var get = service.GetSingleById(dbo.Value);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
- Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
- Assert.Equal(dbo.Value, get.Data.Id);
- }
- });
- }
-
-
- [Fact]
- public void TestAddIdSingle1()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.AddId(new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- });
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(0, res.Data);
-
- var get = service.GetSingleById(res.Data);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal("42", get.Data.SomeText);
- Assert.Equal(42, get.Data.SomeInt);
- Assert.Equal(res.Data, get.Data.Id);
- });
- }
-
- [Fact]
- public void TestAddDboMultiple1()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 21,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.AddDbo(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
- foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, PkBigSerialDbo>(dbo, serialDbo)))
- {
- Assert.NotNull(dbo.Key);
- Assert.NotNull(dbo.Value);
-
- Assert.NotEqual(0, dbo.Value.Id);
-
- var get = service.GetSingleById(dbo.Value.Id);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
- Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
- Assert.Equal(dbo.Value.Id, get.Data.Id);
- }
- });
- }
-
-
- [Fact]
- public void TestAddDboSingle1()
- {
- Tests.TestRealDb(context =>
- {
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.AddDbo(new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- });
- Assert.Equal(LuStatus.Success, res.Status);
- Assert.NotEqual(0, res.Data.Id);
-
- var get = service.GetSingleById(res.Data.Id);
- Assert.Equal(LuStatus.Success, get.Status);
- Assert.Equal("42", get.Data.SomeText);
- Assert.Equal(42, get.Data.SomeInt);
- Assert.Equal(res.Data.Id, get.Data.Id);
- });
- }
- }
- }
|