public static void cleannup() { using (var context = new ModelAndContext.EntityContext()) { context.ContractComplexs.RemoveRange(context.ContractComplexs); context.SaveChanges(); } }
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 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); } }