Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:42:41+00:00 2026-05-29T23:42:41+00:00

I was trying to perform subsequent calls verification and I found that moq supports

  • 0

I was trying to perform subsequent calls verification and I found that moq supports the InSequence() method for this, like:

MockSequence s = new MockSequence();
validator.InSequence(s).Setup(m => m.IsValid(It.IsAny<Frame>())).Returns(true);
encryptor.InSequence(s).Setup(m=>m.Encrypt(It.IsAny<Frame>()));
socket.InSequence(s).Setup(m => m.Send(It.IsAny<Frame>()));
compressor.InSequence(s).Setup(m => m.Compress(It.IsAny<Frame>()));

However, this seems to be working only when I specify mock behavior as “strict”, which forbids me calling additional mehods on mocked objects. I’d like, however, to be able to call other methods on those objects, I just want THESE calls to be performed in sequence.

Is there any “supported” way for that (instead of resorting to .Callback() and handmade implementation)? I found an additional library called moq.sequence, however, the precompiled version doesn’t work with latest Moq.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:42:42+00:00Added an answer on May 29, 2026 at 11:42 pm

    Ok, I investigated the case myself by digging into Moq’s source code in the SVN Browser (just for the record – the moq version in question is Moq.4.0.10827.Final).

    My investigation led me to:
    http://code.google.com/p/moq/source/browse/trunk/Source/MockSequence.cs?spec=svn751&r=712

    By looking at the InSequence() method, I can see now that the whole implementation is based on the When() method.

    So, in reality, the following code:

    validator.InSequence(s).Setup(m => m.IsValid(It.IsAny<Frame>())).Returns(true);
    

    ends up as something like:

    validator.When(/* call is made in sequence */).Setup(m => m.IsValid(It.IsAny<Frame>())).Returns(true);
    

    In other words, this is just setting up a conditional behavior – when the method is invoked in sequence, the specified Setup() comes into play. Otherwise, default implementation is executed. And because for a strict mock, the default implementation is to throw exception (the call is treated as unspecified), the whole solution works.

    Hence, it seems getting current solution to work with loose mocks would be quite cumbersome. I’ll just stick to homemade solutions based on Callback() (which can be really nicely wrapped, by the way) – it takes away the ability to use callback for other means, however, I wasn’t using it anyway.

    I am posting this answer in hope it is useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to perform a DISTINCT clause on a query like this SELECT DISTINCT
I'm trying to perform a complex issue, I have a query structured like this:
I'm trying to perform a calculation that looks to me like it has to
I'm trying to perform a skew on an image, like one shown here (source:
Trying to perform a very simple task here. I have an <ol> that contains
I am trying to perform a method in a background thread using a NSOperationQueue
I'm trying to perform some memory profiling on an applications that is accumulating large
Hey I'm trying to perform input validation in PHP to ensure that the stock
I am trying to perform a query like the following using ActiveRecord and Rails
Trying to perform a single boolean NOT operation, it appears that under MS SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.