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 { 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 { 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 { 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 { 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 { 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); }); } } }