public virtual void Can_insert_update_delete() { DbContextHelpers.ExecuteWithStrategyInTransaction( CreateContext, UseTransaction, context => { var kiwi = new Kiwi { Species = "Apteryx owenii", Name = "Little spotted kiwi", IsFlightless = true, FoundOn = Island.North }; var nz = context.Set <Country>().Single(c => c.Id == 1); nz.Animals.Add(kiwi); context.SaveChanges(); }, context => { var kiwi = context.Set <Kiwi>().Single(k => k.Species.EndsWith("owenii")); kiwi.EagleId = "Aquila chrysaetos canadensis"; context.SaveChanges(); }, context => { var kiwi = context.Set <Kiwi>().Single(k => k.Species.EndsWith("owenii")); Assert.Equal("Aquila chrysaetos canadensis", kiwi.EagleId); context.Set <Bird>().Remove(kiwi); context.SaveChanges(); }, context => { var count = context.Set <Kiwi>().Count(k => k.Species.EndsWith("owenii")); Assert.Equal(0, count); }); }
protected virtual void Update <TBlog>(string navigation) where TBlog : class, IBlogAccesor, new() { DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction, context => { var blogs = context.Set <TBlog>().ToList(); foreach (var blog in blogs) { context.Entry(blog).Collection(navigation).Load(); blog.AccessTitle += "Updated"; foreach (var post in blog.AccessPosts) { post.AccessTitle += "Updated"; } } AssertGraph(blogs, "Updated"); context.SaveChanges(); AssertGraph(blogs, "Updated"); }, context => { var blogs = context.Set <TBlog>().ToList(); foreach (var blog in blogs) { context.Entry(blog).Collection(navigation).Load(); } AssertGraph(blogs, "Updated"); }); }
protected virtual void ExecuteWithStrategyInTransaction( Action <UpdatesContext> testOperation, Action <UpdatesContext> nestedTestOperation1 = null) => DbContextHelpers.ExecuteWithStrategyInTransaction(CreateContext, UseTransaction, testOperation, nestedTestOperation1);