Mark,

Thanks again but one thing I noticed. The <cftransaction
action="rollback"> works in that the newly inserted test record
doesn't appear post-test in my table. However the autoincrement ID
field of that same table does actually increase in my SQL Server
table.

I confirmed this by first running my unit test once without the
rollback and saw the test record with an id=5. I then put back the
rollback statement and ran my unit test 4 more times and each time, no
test record persisted which is good. Then I removed the rollback
statement, ran the test, and to my surprise, the id field was at id=10
instead of id=6.

Any advice? Thanks.

-Bim

On Jan 20, 5:43 pm, bimp <bpa...@gmail.com> wrote:
> Mark, sweet that worked!!
>
> Now correct me if I'm wrong. With this type of implementation of
> rolling back, this assumes that in addition to the test functions
> being advised by the Transaction class, that all the functions being
> tested in the service, gateway, and business objects need to also be
> advised as well for all this to work?
>
> -Bim
>
> On Jan 20, 4:54 pm, "Mark Mandel" <mark.man...@gmail.com> wrote:
>
> > This is a really good question!
>
> > I've done similar things in my unit tests, by cheating a little, and
> > it worked a charm.
>
> > I can't seem the find the code... but the basics went something like
> > this (written in gmail, so errors will happen):
>
> > <cfcomponent extends="frameworkYouUse.TestCase">
>
> > <cfscript>
> >    //wrap everything in a transaction
> >    application.transferFactory.getTransaction().advise(this, "^test");
> > </cfscript>
>
> > <cffunction name="tearDown">
> >   //dump the cache after every test
> >   <cfset application.transferFactory.getTransfer().discardAll();
> > </cffunction>
>
> > <cffunction name="testFoo">
> >   <cfset assertTrue(...) />
>
> >   <!--- rollback any processing that you've done --->
> >   <cftransaction action="rollback" />
> > </cffunction>
>
> > </component>
>
> > Using a combination of discardAll() and <cftransaction> you could roll
> > back your data and your cache quite happily.
>
> > There is an enhancement ticket for you to be able to start() and
> > stop() transactions on your own, but this way works pretty well as
> > well.
>
> > Mark
>
> > On Wed, Jan 21, 2009 at 11:44 AM, bimp <bpa...@gmail.com> wrote:
>
> > > I'm trying to devise a method of rolling back database operations in
> > > Transfer for unit testing purposes. After reading about leveraging the
> > > Transaction object advise() implementation (http://docs.transfer-
> > > orm.com/wiki/Transactions_and_Transfer.cfm), I tried creating a
> > > function called 'rollback()' that is wrapped by the advise() method
> > > along with all my other 'save()' functions.
>
> > > Then only in unit testing implementations, I would execute the
> > > 'rollback()' function which does a <cfthrow> operation. I thought from
> > > the docs that this would effectively rollback all the database and
> > > Transfer operations but nothing happened. The <cfthrow> occurred but
> > > the database records still existed. Am I using the Transaction advise
> > > () function correctly?
>
> > > Is there a way to execute a tranasaction rollback using the advise
> > > implementation?
>
> > > Thanks.
>
> > --
> > E: mark.man...@gmail.com
> > W:www.compoundtheory.com
--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer

You received this message because you are subscribed to the Google Groups 
"transfer-dev" group.
To post to this group, send email to transfer-dev@googlegroups.com
To unsubscribe from this group, send email to 
transfer-dev-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to