try Order/Unordered:

using NUnit.Framework;
using Rhino.Mocks;

namespace SampleTest {
        [TestFixture]
        public class OrderedUnorderedMockExample {
                public interface IOperationContract {
                        void Start();
                        void DoSomeProcess1();
                        void DoSomeProcess2();
                        object Prop1 {
                                set;
                        }
                        object Prop2 {
                                set;
                        }
                        void End();
                }

                public class OperationContractUser {
                        private readonly IOperationContract operationContract;
                        public OperationContractUser(IOperationContract 
operationContract)
{
                                this.operationContract = operationContract;
                        }
                        public void Do() {
                                // Uncommenting one of these will fail the test:
                                //operationContract.DoSomeProcess1();
                                //operationContract.DoSomeProcess2();
                                //operationContract.Prop2 = new object();
                                //operationContract.Prop1 = new object();

                                operationContract.Start();
                                operationContract.DoSomeProcess1();
                                operationContract.Prop2 = new object();
                                operationContract.Prop1 = new object();
                                operationContract.DoSomeProcess2();
                                operationContract.Prop1 = new object();
                                operationContract.End();

                                // Uncommenting one of these will fail the test:
                                //operationContract.DoSomeProcess1();
                                //operationContract.DoSomeProcess2();
                                //operationContract.Prop2 = new object();
                                //operationContract.Prop1 = new object();
                        }
                }

                [Test]
                public void TestDo() {
                        var mocks = new MockRepository();
                        var mock = mocks.StrictMock<IOperationContract>();
                        using (mocks.Ordered()) {
                                Expect.Call(mock.Start);
                                using (mocks.Unordered()) {
                                        mock.Expect(x => 
x.DoSomeProcess1()).Repeat.AtLeastOnce();
                                        mock.Expect(x => 
x.DoSomeProcess2()).Repeat.AtLeastOnce();
                                        mock.Expect(x => x.Prop1 =
null).IgnoreArguments().Repeat.AtLeastOnce();
                                        mock.Expect(x => x.Prop2 =
null).IgnoreArguments().Repeat.AtLeastOnce();
                                }
                                Expect.Call(mock.End);
                        }
                        mocks.ReplayAll();
                        new OperationContractUser(mock).Do();
                        mocks.VerifyAll();
                }
        }
}




On Oct 6, 9:59 am, k0v1d pa9d3y <[email protected]> wrote:
> Thank you Alex for your help...
>
>
>
> On Wed, Oct 6, 2010 at 7:06 PM, Alex McMahon <[email protected]> wrote:
> > Here's what I meant:
>
> > public interface IDependency
> > {
> >   void Method1();
> >   void Method2();
> >   void End();
> > }
>
> > [TestClass()]
> > public class Test
> > {
> >   [TestMethod()]
> >   public void EndIsLastMethodCalled()
> >   {
> >     var dependency = MockRepository.GenerateMock<IDependency>();
> >     dependency.Stub(x => x.End()).WhenCalled(a =>
> >     {
> >       dependency.VerifyAllExpectations();
> >     });
> >     dependency.Method1();
> >     dependency.End();
> >   }
>
> >   [TestMethod()]
> >   [ExpectedException(typeof(InvalidOperationException))]
> >   public void EndIsNotLastMethodCalledThrows()
> >   {
> >     var dependency = MockRepository.GenerateMock<IDependency>();
> >     dependency.Stub(x => x.End()).WhenCalled(a =>
> >     {
> >       dependency.VerifyAllExpectations();
> >     });
> >     dependency.Method1();
> >     dependency.End();
> >     dependency.Method2();
> >   }
> > }
>
> > On 6 October 2010 14:06, k0v1d pa9d3y <[email protected]> wrote:
>
> >> Let me eloborate more on my question:
> >> I have to use dynamic mock and I need to make sure that Prop1, Prop2 is
> >> getting modified ; but once End() method gets called modification to prop1,
> >> prop2 should not be happened...
>
> >> Start()
> >> DoSomeProcess1()
> >> DoSomeProcess2()
> >> DoSomeProcess1()
> >> Prop1 = value;
> >> Prop2 = value;
> >> Prop1 = value;
> >> Prop2 = value;
> >> End(),
>
> >> On Wed, Oct 6, 2010 at 6:22 PM, k0v1d pa9d3y <[email protected]>wrote:
>
> >>> Thanks Alex for replying, but I want use Dynamic mock not stub , can you
> >>> eloborate your way of doing using WhenCalled(), I did not get it..
>
> >>> On Wed, Oct 6, 2010 at 5:08 PM, Alex McMahon <[email protected]>wrote:
>
> >>>> I don't know if there's a better way, but I think the following should
> >>>> work:
>
> >>>> Setup a Stub for End() with a WhenCalled() that does something that
> >>>> means any further calls on the mock will fail. I should think calling
> >>>> mockObject.VerifyAllExpectations() should probably work... although you'd
> >>>> need to verify this.
>
> >>>>   On 6 October 2010 12:22, 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]<rhinomocks%2bunsubscr...@googlegrou
> >>>>>  ps.com>
> >>>>> .
> >>>>> 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]<rhinomocks%2bunsubscr...@googlegrou
> >>>>  ps.com>
> >>>> .
> >>>> 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]<rhinomocks%2bunsubscr...@googlegrou
> >>  ps.com>
> >> .
> >> 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]<rhinomocks%2bunsubscr...@googlegrou 
> > ps.com>
> > .
> > 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.

Reply via email to