If we take Rhino Mocks out of the picture, there's a few ways to implement the class to try and enforce this:
1. Make the class IDisposable. The "End" would be called during Dispose. Your consumers should wrap the usage of this in a "using" block and that should ensure they don't use the object after it's disposed (i.e. after "End" is called). 2. However, this won't force them to use "using". Therefore, you could use DynamicProxy (http://stw.castleproject.org/Tools.DynamicProxy.ashx) and intercept your method/property calls. Set a flag as soon as "End" is called. When the interceptor gets called, it will throw an exception whenever this flag has been set. As for testing, that would be tricky. I could think of a real ugly hack that might set up a "WhenCalled" delegate for every method. When "End" is called, the delegate would set some flag (similar to what I described for an interceptor). The other "WhenCalled" delegates would check the flag and throw an error if its set. This sounds ugly because you'd have to mock out every virtual method on the class. TestSetup would be a nightmare! :) --- Patrick Steele http://weblogs.asp.net/psteele On Wed, Oct 6, 2010 at 7:22 AM, k0v1d pa9d3y <[email protected]> wrote: > How do i make sure that after the particular method called up no other > method/ property setter should be called on the same object. > > Let say I have a method which has three methods, > > Start() > DoSomeProcess1() > DoSomeProcess2() > DoSomeProcess1() > //Some property settings... > ..... > End(), > > I want to make sure that End() should always be executed at last, no other > method should be executed once End gets executed? > > How can I achieve this using Rhinomock(); > > Thanks in advance! > > -- > You received this message because you are subscribed to the Google Groups > "Rhino.Mocks" 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/rhinomocks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" 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/rhinomocks?hl=en.
