using System; using System.Collections.Generic; using System.Linq; using Luticate2.Utils.Dbo.Result; using TestUtils.DataAccess; using TestUtils.Dbo.PkBigSerial; using TestUtils.Dbo.PkGuid; using Xunit; namespace TestUtils.EfCrudDataAccess { public class LuEfUpdateDataAccessTest { [Fact] public void TestEditMultiple1() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(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(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(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(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; 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(new Guid().ToString(), e); e = elements[1]; Assert.NotEqual(new Guid().ToString(), e); }); } [Fact] public void TestEditMultiple4() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; 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(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(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); }); } [Fact] public void TestEditSingle1() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleById(ids[0], guid => guid.some_int = -1, d => d); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle2() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleByIdId(ids[0], guid => guid.some_int = -1); Assert.Equal(LuStatus.Success, edit.Status); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle3() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleByIdDbo(ids[0], guid => guid.some_int = -1); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle4() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleById(ids[0], guid => guid.some_int = -1, d => d); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle5() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleByIdId(ids[0], guid => guid.some_int = -1); Assert.Equal(LuStatus.Success, edit.Status); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle6() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); var edit = service.EditSingleByIdDbo(ids[0], guid => guid.some_int = -1); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle7() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleById(ids[0], dbos[0], d => d); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle8() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleByIdId(ids[0], dbos[0]); Assert.Equal(LuStatus.Success, edit.Status); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle9() { Tests.TestRealDb(service => { var dbos = new List { new PkBigSerialAddDbo { SomeInt = 42, SomeText = "442" }, new PkBigSerialAddDbo { SomeInt = 42, SomeText = "42" }, new PkBigSerialAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleByIdDbo(ids[0], dbos[0]); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle10() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleById(ids[0], dbos[0], d => d); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle11() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleByIdId(ids[0], dbos[0]); Assert.Equal(LuStatus.Success, edit.Status); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } [Fact] public void TestEditSingle12() { Tests.TestRealDb(service => { var dbos = new List { new PkGuidAddDbo { SomeInt = 42, SomeText = "442" }, new PkGuidAddDbo { SomeInt = 42, SomeText = "42" }, new PkGuidAddDbo { SomeInt = 24, SomeText = "24" } }; var res = service.AddId(dbos); Assert.Equal(LuStatus.Success, res.Status); var ids = res.Data.ToList(); dbos[0].SomeInt = -1; var edit = service.EditSingleByIdDbo(ids[0], dbos[0]); Assert.Equal(LuStatus.Success, edit.Status); Assert.Equal(-1, edit.Data.SomeInt); Assert.Equal("442", edit.Data.SomeText); var get = service.GetMultiple(guid => guid.some_text); Assert.Equal(LuStatus.Success, get.Status); Assert.Equal(3, get.Data.Count); Assert.Equal(3, get.Data.Data.Count); var dbo = get.Data.Data[0]; Assert.Equal(24, dbo.SomeInt); Assert.Equal("24", dbo.SomeText); dbo = get.Data.Data[1]; Assert.Equal(42, dbo.SomeInt); Assert.Equal("42", dbo.SomeText); dbo = get.Data.Data[2]; Assert.Equal(-1, dbo.SomeInt); Assert.Equal("442", dbo.SomeText); }); } } }