That's what I thought too, but indeed if I take the [Transaction] attribute away, there is no transaction. When I put it back, there is. I can test using the same transaction manager code I showed before.
Of course MyService inherits from IMyService - which I didn't show. Perhaps it is using the interface to create the proxy? -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of G. Richard Bellamy Sent: Wednesday, November 09, 2011 9:14 AM To: [email protected] Subject: Re: How to explicitly roll back when using [Transaction] attribute in AutoTx Facility? If your methods aren't virtual, they aren't being intercepted. -rb On 11/9/2011 7:47 AM, Matt Johnson wrote: > Well, that kinda helped. When I register the test classes with the > container, I now get told that my methods must be marked virtual in order to > use transaction interception. Strange that I didn't have to do this other > places (out side of the test framework) that indeed work with the > transaction attribute. Is it trying to create a proxy? Why? > > Even when marking them virtual, I still get no transaction from the manager. > > For now, I'm just using .Net's TransactionScope around my test classes, > which defaults to rollback anyway. I'll reserve the [Transaction] attribute > for my application service classes where it appears to be working. > > > In the app service: > > public class MyService > { > [Transaction] > public void AddItem(Item item) > { > _itemRepository.Add(item); > } > } > > In the data unit test: > > [TestClass] > public class ItemTests > { > [TestMethod] > public void AddItemTest() > { > using (new TransactionScope()) > { > // my test code > } > } > } > > > It sure would be nice to do it the same way in both cases, but at least this > works for now. > > Thanks, > Matt > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of gusgorman > Sent: Wednesday, November 09, 2011 8:11 AM > To: Castle Project Users > Subject: Re: How to explicitly roll back when using [Transaction] attribute > in AutoTx Facility? > >> I can dig deeper into the source for AutoTx if someone can point me in the >> right direction. Where does the transaction actually get created? In > other >> words, what part of AutoTx actually looks for the [Transaction] attribute? >> I have a feeling that part of the code is not being invoked in my > scenario. > Hi Matt, > > The object marked with the [Transaction] attribute needs to be in the > container. I would guess that your test class is not in the container, > and that is why no transaction has been started. > > regards, > Jordan. > -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
