Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Ordered expectations for AAA syntax
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alex McMahon  
View profile  
 More options Jun 23, 6:02 am
From: Alex McMahon <fluxmu...@gmail.com>
Date: Tue, 23 Jun 2009 03:02:37 -0700 (PDT)
Local: Tues, Jun 23 2009 6:02 am
Subject: Ordered expectations for AAA syntax
I've found doing ordered expectations to be a bit of a pain since
Rhino Mocks 3.5 introduced AAA syntax, it seems to be one of the few
areas where you have to drop back to using the old record/replay
syntax, and it's making my test fixtures awfully complicated and
fragile.

So other than trying to find a nice way to do it in RhinoMocks itself
I've got a workaround that I've been using, and I wondered what others
thought of it.

[TestMethod()]
public void ViewTitleSetBeforeShownInWorkspace()
{
  //arrange
  var mockView=MockRepository.GenerateMock<IView>();
  bool viewTitleSet=false;
  mockView.Stub(x=>x.Title=Arg<string>.Is.Anything)
    .WhenCalled(a=>{viewTitleSet=true});
  mockView.Stub(x=>x.ShowInWorkspace("MyWorkspace"))
    .WhenCalled(a=>{Assert.IsTrue(viewTitleSet, "View title should
have been set first");});

  //act
  var target=new Presenter(mockView);
  target.Initialize();

  //assert
  mockView.AssertWasCalled(x=>x.ShowInWorkspace("MyWorkspace"));


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options Jun 23, 1:54 pm
From: Ayende Rahien <aye...@ayende.com>
Date: Tue, 23 Jun 2009 20:54:25 +0300
Local: Tues, Jun 23 2009 1:54 pm
Subject: Re: [RhinoMocks] Ordered expectations for AAA syntax

You cannot use Ordered with AAA, that was judged to be rare enough and the
complexity of providing this feature high enough to not do it.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth Xu  
View profile  
 More options Jun 27, 11:52 am
From: Kenneth Xu <kenne...@gmail.com>
Date: Sat, 27 Jun 2009 11:52:51 -0400
Local: Sat, Jun 27 2009 11:52 am
Subject: Re: [RhinoMocks] Re: Ordered expectations for AAA syntax
Just 2 cents worth as I didn't really look into the source code so
forgive me if all I'm talking is crap.

I assume we internally record each call so we can assert later. If we
keep an atomic running number within each mock instance, and record it
with the each call. We can probably say:

mockView.AssertWasCalled(x=>x.ShowInWorkspace("MyWorkspace")).Before(x=>... );

Cheers,
Kenneth


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kenneth Xu  
View profile  
 More options Jun 27, 2:59 pm
From: Kenneth Xu <kenne...@gmail.com>
Date: Sat, 27 Jun 2009 14:59:50 -0400
Local: Sat, Jun 27 2009 2:59 pm
Subject: Re: [RhinoMocks] Re: Ordered expectations for AAA syntax

Just want to confirm the idea :) I check out the RhinoMocks. It turn
out to be quite straightforward, thanks to nice design of it, I
created a class called CallRecord which keeps a thread safe sequencer
that is increased for each call and later use that information to
determine the order of each call.
    public class CallRecord
    {
        private static long sequencer = long.MinValue;

        internal CallRecord()
        {
            Sequence = Interlocked.Increment(ref sequencer);
        }
        internal object[] Arguments { get; set; }
        internal long Sequence { get; private set; }
        internal MethodInfo Method { get; set; }
        internal IMockedObject MockObject { get; set; }
    }

Then make AssertWasCalled methods return an IList<CallRecord>. And
added an extension method:

public static void Before(this IList<CallRecord> beforeCalls,
IList<CallRecord> afterCalls)

Now you can do this to verify the order:
mock1.AssertWasCalled(m1=>m1.MethodBefore())
  .Before(mock2.AssertWasCalled(m2=>MethodAfter());

I have attached the patch. And there is the unit test which is also
included in the patch.

Cheers,
Kenneth

    [TestFixture] public class BeforeExtensionMethodTest
    {
        public interface IBefore
        {
            void MethodBefore();
        }

        public interface IAfter
        {
            void MethodAfter();
        }

        [Test] public void
Before_succeeds_if_beforeCalls_occured_before_afterCalls()
        {
            var mockBefore = MockRepository.GenerateStub<IBefore>();
            var mockAfter = MockRepository.GenerateStub<IAfter>();
            mockBefore.MethodBefore();
            mockBefore.MethodBefore();
            mockAfter.MethodAfter();
            mockAfter.MethodAfter();
            mockAfter.MethodAfter();
            mockBefore.AssertWasCalled(b => b.MethodBefore())
                .Before(mockAfter.AssertWasCalled(a => a.MethodAfter()));
        }

        [ExpectedException(typeof(ExpectationViolationException))]
        [Test] public void
Before_chokes_if_one_of_beforeCalls_occured_after_any_of_afterCalls()
        {
            var mockBefore = MockRepository.GenerateStub<IBefore>();
            var mockAfter = MockRepository.GenerateStub<IAfter>();
            mockBefore.MethodBefore();
            mockAfter.MethodAfter();
            mockBefore.MethodBefore();
            mockAfter.MethodAfter();
            mockAfter.MethodAfter();
            mockBefore.AssertWasCalled(b => b.MethodBefore())
                .Before(mockAfter.AssertWasCalled(a => a.MethodAfter()));
        }
    }

  OrderedAAA.patch
18K Download

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google