public void RequireDbContextHandler_ExceptionThrownInTransaction_DbRollback() { Assert.Throws <InvalidOperationException>(() => RepoB.AddItemException()); Assert.False(DbContextFactory.IsOpen()); DbContextTemplate.ExecuteQuery <TestDbContext>(ctx => Assert.Empty(Items)); Assert.False(DbContextFactory.IsOpen()); }
public void RequireDbContextHandler_AddItem_ItemCreated() { RepoB.AddItem(); Assert.False(DbContextFactory.IsOpen()); DbContextTemplate.ExecuteQuery <TestDbContext>(ctx => Assert.Equal("testitem", Items.Single().Name)); Assert.False(DbContextFactory.IsOpen()); }
public void RequireDbContextHandler_ModifyDbWithoutRequireDb_ExceptionThrown() { var ex = Assert.Throws <InvalidOperationException>(() => RepoB.AddItemWithNoTransaction()); Assert.Equal($"Detected dbcontext is changed by method AddItemWithNoTransaction at class {typeof(RepoB).FullName}, but transaction is not opened.", ex.Message); }
public void RequireDbContextHandler_NormalQuery_ResultReceived() { DbContextTemplate.ExecuteQuery <TestDbContext>(ctx => Assert.Equal(0, RepoB.CountItems())); }