public void BatchUpdate_1() { Cleannup(); Seed(); using (var context = new ModelAndContext.EntityContext()) { context.Customers.Update(c => new ModelAndContext.Customer { TotalNumberOfOrders = c.Orders.Count(o => o.Name == "Works") }); Assert.AreEqual(1, context.Customers.Where(x => x.TotalNumberOfOrders == 1 && x.Name == "Customer_A").ToList().Count); Assert.AreEqual(0, context.Customers.Where(x => x.TotalNumberOfOrders == 1 && x.Name != "Customer_A").ToList().Count); Assert.AreEqual(2, context.Customers.Where(x => x.TotalNumberOfOrders != 1 && x.Name != "Customer_A").ToList().Count); } using (var context = new ModelAndContext.EntityContext()) { context.Customers.Update(c => new ModelAndContext.Customer { TotalNumberOfOrders = c.Orders.Count(o => o.Company.Name == "DoesntWork") }); Assert.AreEqual(1, context.Customers.Where(x => x.TotalNumberOfOrders == 1 && x.Name == "Customer_B").ToList().Count); Assert.AreEqual(0, context.Customers.Where(x => x.TotalNumberOfOrders == 1 && x.Name != "Customer_B").ToList().Count); Assert.AreEqual(2, context.Customers.Where(x => x.TotalNumberOfOrders != 1 && x.Name != "Customer_B").ToList().Count); } }
public static void cleannup() { using (var context = new ModelAndContext.EntityContext()) { context.ContractComplexs.RemoveRange(context.ContractComplexs); context.SaveChanges(); } }
public static void CreateContext(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) { Effort.Provider.EffortProviderConfiguration.RegisterProvider(); using (var context = new ModelAndContext.EntityContext()) { ModelAndContext.My.CreateBD(context); } }
public static void Cleannup() { using (var context = new ModelAndContext.EntityContext()) { context.Companies.Delete(); context.Orders.Delete(); context.Customers.Delete(); } }
public static void cleannup() { using (var context = new ModelAndContext.EntityContext()) { context.TvContracts.RemoveRange(context.TvContracts); context.MobileContracts.RemoveRange(context.MobileContracts); context.BroadbandContracts.RemoveRange(context.BroadbandContracts); context.SaveChanges(); } }
public void BatchUpdate_2() { Cleannup(); Seed(); var changedUpdatedEntityIds = new[] { Guid.NewGuid() }; var changedJoinedEntity1Ids = new[] { Guid.NewGuid() }; var changedIndirectlyJoinedEntityIds = new[] { Guid.NewGuid() }; var changedJoinedEntity2Ids = new[] { Guid.NewGuid() }; using (var context = new ModelAndContext.EntityContext()) { context.Customers.Update(c => new ModelAndContext.Customer { TotalNumberOfOrders = c.Orders.Count(o => o.Name == "Works") }); context.Customers.Update(c => new ModelAndContext.Customer { TotalNumberOfOrders = c.Orders.Count(o => o.Company.Name == "DoesntWork") }); // TODO CHECK VALUE ! context.Set <ModelAndContext.UpdatedEntity>().Include(x => x.JoinedEntity1).Include(x => x.JoinedEntity2) .Where( sp => changedUpdatedEntityIds.Contains(sp.UpdatedEntityId) || changedJoinedEntity2Ids.Contains(sp.JoinedEntity2.JoinedEntity2Id) || changedJoinedEntity1Ids.Contains(sp.JoinedEntity1.JoinedEntity1Id) || changedIndirectlyJoinedEntityIds.Contains(sp.JoinedEntity1.IndirectlyJoinedEntity.IndirectlyJoinedEntityId)) .Update( u => new ModelAndContext.UpdatedEntity { Status = (!u.IsActive ? ModelAndContext.UpdatedEntityStatus.Inactive : u.RestrictedBool && u.JoinedEntity2.String == null ? ModelAndContext.UpdatedEntityStatus.Invalid : u.JoinedEntity1.Status != ModelAndContext.JoinedEntity1Status.Valid ? ModelAndContext.UpdatedEntityStatus.Invalid : u.JoinedEntity1.Restrictions.Restriction1 && u.RestrictedNumber == 0 ? ModelAndContext.UpdatedEntityStatus.Invalid : u.JoinedEntity1.Restrictions.Restriction2 && !u.RestrictedBool ? ModelAndContext.UpdatedEntityStatus.Invalid : ModelAndContext.UpdatedEntityStatus.Valid) }); } }
public static void Seed() { using (var context = new ModelAndContext.EntityContext()) { var Company = new ModelAndContext.Company() { Name = "DoesntWork" }; var Company2 = new ModelAndContext.Company() { Name = "DoesntWorkZ" }; var order1 = new ModelAndContext.Order() { Name = "Works" }; var order2 = new ModelAndContext.Order() { Name = "NotWorks" }; order2.Company = Company; order1.Company = Company2; context.Orders.Add(order1); context.Orders.Add(order2); context.Customers.Add(new ModelAndContext.Customer() { Name = "Customer_A", IsActive = false, Orders = new List <ModelAndContext.Order>() { order1 } }); context.Customers.Add(new ModelAndContext.Customer() { Name = "Customer_B", IsActive = true, Orders = new List <ModelAndContext.Order>() { order2 } }); context.Customers.Add(new ModelAndContext.Customer() { Name = "Customer_C", IsActive = false }); context.SaveChanges(); } }
public void BatchUpdateDelete_ComplexType_4() { cleannup(); // SEED using (var context = new ModelAndContext.EntityContext()) { //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); //8 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.SaveChanges(); } var now = DateTime.Now; using (var context = new ModelAndContext.EntityContext()) { context.ContractComplexs.Update(x => new ModelAndContext.ContractComplex() { StartDate = (x.Months == 1 ? now : now) }); } using (var context = new ModelAndContext.EntityContext()) { Assert.AreEqual(context.ContractComplexs.Where(x => x.StartDate == now).ToList().Count, 16); } }
public void BatchUpdateDelete_ComplexType_3() { cleannup(); // SEED using (var context = new ModelAndContext.EntityContext()) { //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); //8 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.SaveChanges(); } using (var context = new ModelAndContext.EntityContext()) { context.ContractComplexs.Where(x => x.MobileContractComplex.MobileNumber != "4524").Update(x => new ModelAndContext.ContractComplex() { MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "100" } }); } using (var context = new ModelAndContext.EntityContext()) { Assert.AreEqual(context.ContractComplexs.Where(x => x.MobileContractComplex.MobileNumber == "100").ToList().Count, 12); } }
public void BatchUpdateDelete_ComplexType_1() { cleannup(); // SEED using (var context = new ModelAndContext.EntityContext()) { //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 4 }); //4 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 3, MobileContractComplex = new ModelAndContext.MobileContractComplex() { MobileNumber = "4524" } }); //8 context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 52 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 52 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 1 } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { Months = 6, BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 52 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.ContractComplexs.Add(new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 50 }, TvContractComplex = new ModelAndContext.TvContractComplex() { PackageType = ModelAndContext.PackageType.L } }); context.SaveChanges(); } using (var context = new ModelAndContext.EntityContext()) { // can't be null, but maybe I can do this where for get nothing context.ContractComplexs.Where(x => x.MobileContractComplex != null).Delete(); context.ContractComplexs.Where(x => x.MobileContractComplex.MobileNumber == "4524").Delete(); context.ContractComplexs.Where(x => x.BroadbandContractComplex.DownloadSpeed == 52).Update(y => new ModelAndContext.ContractComplex() { BroadbandContractComplex = new ModelAndContext.BroadbandContractComplex() { DownloadSpeed = 59 } }); } using (var context = new ModelAndContext.EntityContext()) { Assert.AreEqual(context.ContractComplexs.ToList().Count, 12); Assert.AreEqual(context.ContractComplexs.Where(x => x.BroadbandContractComplex.DownloadSpeed == 59).ToList().Count, 3); } }
public void BatchUpdateDelete_TPH_4() { cleannup(); // SEED using (var context = new ModelAndContext.EntityContext()) { //4 context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); //4 context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); //8 context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 51 }); context.SaveChanges(); } var now = DateTime.Now; using (var context = new ModelAndContext.EntityContext()) { context.Contracts.Update(x => new ModelAndContext.BroadbandContract { StartDate = now }); } using (var context = new ModelAndContext.EntityContext()) { Assert.AreEqual(context.Contracts.Where(x => x.StartDate == now).ToList().Count, 8); Assert.AreEqual(context.TvContracts.Where(x => x.StartDate == now).ToList().Count, 0); Assert.AreEqual(context.MobileContracts.Where(x => x.StartDate == now).ToList().Count, 0); Assert.AreEqual(context.BroadbandContracts.Where(x => x.StartDate == now).ToList().Count, 8); } }
public void BatchUpdateDelete_TPH_1() { cleannup(); // SEED using (var context = new ModelAndContext.EntityContext()) { //4 context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); context.TvContracts.Add(new ModelAndContext.TvContract() { Months = 4 }); //4 context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); context.MobileContracts.Add(new ModelAndContext.MobileContract() { Months = 3, MobileNumber = "4524" }); //8 context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 52 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { Months = 6, DownloadSpeed = 50 }); context.BroadbandContracts.Add(new ModelAndContext.BroadbandContract() { DownloadSpeed = 51 }); context.SaveChanges(); } using (var context = new ModelAndContext.EntityContext()) { context.MobileContracts.Where(x => 1 == 1).Delete(); context.BroadbandContracts.Where(x => x.DownloadSpeed == 52).Update(y => new ModelAndContext.BroadbandContract() { DownloadSpeed = 59 }); } using (var context = new ModelAndContext.EntityContext()) { Assert.AreEqual(context.MobileContracts.ToList().Count, 0); Assert.AreEqual(context.BroadbandContracts.Where(x => x.DownloadSpeed == 59).ToList().Count, 3); Assert.AreEqual(context.TvContracts.ToList(), 4); } }