public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); ITransactionStatus status = TransactionStatusForNewTransaction(); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); ptm.Commit(status); LastCall.On(ptm).Throw(ex); mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } mocks.VerifyAll(); }
public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof (ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction(); ITransactionStatus status = TransactionStatusForNewTransaction(); Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); ptm.Commit(status); LastCall.On(ptm).Throw(ex); mocks.ReplayAll(); TestObject to = new TestObject(); ITestObject ito = (ITestObject) Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } mocks.VerifyAll(); }
public void CannotCommitTransaction() { ITransactionAttribute txatt = new DefaultTransactionAttribute(); MethodInfo m = typeof(ITestObject).GetMethod("GetDescription"); MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource(); tas.AddTransactionalMethod(m, txatt); IPlatformTransactionManager ptm = A.Fake <IPlatformTransactionManager>(); ITransactionStatus status = A.Fake <ITransactionStatus>(); A.CallTo(() => ptm.GetTransaction(txatt)).Returns(status); UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null); A.CallTo(() => ptm.Commit(status)).Throws(ex); TestObject to = new TestObject(); ITestObject ito = (ITestObject)Advised(to, ptm, tas); try { ito.GetDescription(); Assert.Fail("Shouldn't have succeeded"); } catch (UnexpectedRollbackException thrown) { Assert.IsTrue(thrown == ex); } }