123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Luticate2.Utils.Dbo;
- using Test.Utils.DataAccess;
- using Test.Utils.Dbo.PkBigSerial;
- using Test.Utils.Dbo.PkGuid;
- using Xunit;
-
- namespace Test.Utils.EfCrubDataAccess
- {
- public class LuEfUpdateDataAccessTest
- {
- [Fact]
- public void TestEditMultiple1()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkGuidAddDbo>
- {
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "442"
- },
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkGuidAddDbo
- {
- SomeInt = 24,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddGuid(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
-
- var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable);
-
- Assert.Equal(LuStatus.Success, edit.Status);
- var elements = edit.Data.ToList();
- Assert.Equal(2, elements.Count);
-
- var e = elements[0];
- Assert.Equal(-1, e.SomeInt);
- Assert.Equal("442", e.SomeText);
-
- e = elements[1];
- Assert.Equal(-1, e.SomeInt);
- Assert.Equal("42", e.SomeText);
- });
- }
-
- [Fact]
- public void TestEditMultiple2()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkGuidAddDbo>
- {
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "442"
- },
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkGuidAddDbo
- {
- SomeInt = 24,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddGuid(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
-
- var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable.Select(guidDbo => guidDbo.SomeText));
-
- Assert.Equal(LuStatus.Success, edit.Status);
- var elements = edit.Data.ToList();
- Assert.Equal(2, elements.Count);
-
- var e = elements[0];
- Assert.Equal("442", e);
-
- e = elements[1];
- Assert.Equal("42", e);
- });
- }
-
- [Fact]
- public void TestEditMultiple3()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkGuidAddDbo>
- {
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "442"
- },
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkGuidAddDbo
- {
- SomeInt = 24,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddGuid(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
-
- var edit = service.EditGuid(guid => guid.some_int == 42, guid => guid.some_int = -1);
-
- Assert.Equal(LuStatus.Success, edit.Status);
- var elements = edit.Data.ToList();
- Assert.Equal(2, elements.Count);
-
- var e = elements[0];
- Assert.NotEqual(new Guid().ToString(), e);
-
- e = elements[1];
- Assert.NotEqual(new Guid().ToString(), e);
- });
- }
-
- [Fact]
- public void TestEditMultiple4()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkBigSerialAddDbo>
- {
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "442"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkBigSerialAddDbo
- {
- SomeInt = 24,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkBigSerialDataAccess(context);
- var res = service.AddId(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
-
- var edit = service.EditId(guid => guid.some_int == 42, guid => guid.some_int = -1);
-
- Assert.Equal(LuStatus.Success, edit.Status);
- var elements = edit.Data.ToList();
- Assert.Equal(2, elements.Count);
-
- var e = elements[0];
- Assert.NotEqual(0, e);
-
- e = elements[1];
- Assert.NotEqual(0, e);
- });
- }
-
- [Fact]
- public void TestEditMultiple5()
- {
- Tests.TestRealDb(context =>
- {
- var dbos = new List<PkGuidAddDbo>
- {
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "442"
- },
- new PkGuidAddDbo
- {
- SomeInt = 42,
- SomeText = "42"
- },
- new PkGuidAddDbo
- {
- SomeInt = 24,
- SomeText = "24"
- }
- };
- var service = new LuUtilsPkGuidDataAccess(context);
- var res = service.AddGuid(dbos);
- Assert.Equal(LuStatus.Success, res.Status);
-
- var edit = service.EditDbo(guid => guid.some_int == 42, guid => guid.some_int = -1);
-
- Assert.Equal(LuStatus.Success, edit.Status);
- var elements = edit.Data.ToList();
- Assert.Equal(2, elements.Count);
-
- var e = elements[0];
- Assert.Equal(-1, e.SomeInt);
- Assert.Equal("442", e.SomeText);
-
- e = elements[1];
- Assert.Equal(-1, e.SomeInt);
- Assert.Equal("42", e.SomeText);
- });
- }
- }
- }
|