예제 #1
0
        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());
        }
예제 #2
0
        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());
        }
예제 #3
0
        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);
        }
예제 #4
0
 public void RequireDbContextHandler_NormalQuery_ResultReceived()
 {
     DbContextTemplate.ExecuteQuery <TestDbContext>(ctx => Assert.Equal(0, RepoB.CountItems()));
 }