public void UpdateAll_SetDateTimeValueFromVariable_RenamedColumn() { RenamedAndReorderedContext.SetupTestDb(); using (var db = new RenamedAndReorderedContext()) { db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T1", Created = new DateTime(2013, 01, 01) }); db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T2", Created = new DateTime(2013, 02, 01) }); db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T3", Created = new DateTime(2013, 03, 01) }); db.SaveChanges(); } int count; using (var db = new RenamedAndReorderedContext()) { count = EFBatchOperation.For(db, db.BlogPosts).Where(b => b.Title == "T2").Update(b => b.Created, b => DateTime.Today); Assert.AreEqual(1, count); } using (var db = new RenamedAndReorderedContext()) { var post = db.BlogPosts.First(p => p.Title == "T2"); Assert.AreEqual(DateTime.Today, post.Created); } }
public void UpdateAll_IncrementIntValue_RenamedColumn() { RenamedAndReorderedContext.SetupTestDb(); using (var db = new RenamedAndReorderedContext()) { db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T1", Created = new DateTime(2013, 01, 01) }); db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T2", Created = new DateTime(2013, 02, 01), Reads = 10 }); db.BlogPosts.Add(new RenamedAndReorderedBlogPost { Title = "T3", Created = new DateTime(2013, 03, 01) }); db.SaveChanges(); } int count; using (var db = new RenamedAndReorderedContext()) { count = EFBatchOperation.For(db, db.BlogPosts).Where(b => b.Title == "T2").Update(b => b.Reads, b => b.Reads + 100); Assert.AreEqual(1, count); } using (var db = new RenamedAndReorderedContext()) { var post = db.BlogPosts.First(p => p.Title == "T2"); Assert.AreEqual(110, post.Reads); } }
public static void SetupTestDb() { using (var db = new RenamedAndReorderedContext()) { if (db.Database.Exists()) { db.Database.Delete(); } db.Database.Create(); db.Database.ExecuteSqlCommand("drop table dbo.RenamedAndReorderedBlogPosts;"); db.Database.ExecuteSqlCommand(RenamedAndReorderedBlogPost.CreateTableSql()); } }
public void InsertAll_WrongColumnOrderAndRenamedColumn_InsertsItems() { using (var db = new RenamedAndReorderedContext()) { if (db.Database.Exists()) { db.Database.Delete(); } db.Database.Create(); db.Database.ExecuteSqlCommand("drop table dbo.RenamedAndReorderedBlogPosts;"); db.Database.ExecuteSqlCommand(RenamedAndReorderedBlogPost.CreateTableSql()); } using (var db = new RenamedAndReorderedContext()) { var list = new List<RenamedAndReorderedBlogPost>(){ RenamedAndReorderedBlogPost.Create("T1"), RenamedAndReorderedBlogPost.Create("T2"), RenamedAndReorderedBlogPost.Create("T3") }; EFBatchOperation.For(db, db.BlogPosts).InsertAll(list); } using (var db = new RenamedAndReorderedContext()) { Assert.AreEqual(3, db.BlogPosts.Count()); } }