General

I suggest you ...

You've used all your votes and won't be able to post a new idea, but you can still search and comment on existing ideas.

There are two ways to get more votes:

  • When an admin closes an idea you've voted on, you'll get your votes back from that idea.
  • You can remove your votes from an open idea you support.
  • To see ideas you have already voted on, select the “My feedback” filter and select “My open ideas”.
(thinking…)
Reset

Enter your idea and we'll search to see if someone has already suggested it.

If a similar idea already exists, you can vote and comment on it.

If it doesn't exist, you can post your idea so others can vote on it.

Enter your idea and we'll search to see if someone has already suggested it.

  • Hot ideas
  • Top ideas
  • New ideas
    1. Publish what's new in 4.0

      I could not find any information on the site or the readme.txt/changelog.txt files listing what's new in the upcoming 4.0 version of Moq. A little preview would be awesome

      83 votes
      Vote 0 votes Vote Vote
      Vote
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        I agree to the terms of service

        You'll receive a confirmation email with a link to create a password (optional).

        Signed in as (Sign out)
        You have left! (?) (thinking…)
        planned  ·  kzuAdminkzu (Admin, moq) responded

        we will provide more info when we get closer to releasing

      • Make it possible to verify the order of calls to the mock object

        I know that some consider verifying the order of calls as a bad practice (along with any form of interaction testing instead of state testing), but here's an example.
        I'm implementing the traversal of a data structure with the visitor pattern. I want to test my implementation. There's no state here, but only interaction that I can test. I want to make sure that all elements of the data structure are visited and in the correct order.
        How would you test it without verifying the calls to the mock (in a strict way) and also the order of the calls? … more

        31 votes
        Vote 0 votes Vote Vote
        Vote
        Sign in
        Check!
        (thinking…)
        Reset
        or sign in with
        • facebook
        • google
          I agree to the terms of service

          You'll receive a confirmation email with a link to create a password (optional).

          Signed in as (Sign out)
          You have left! (?) (thinking…)
        • Create a NuPack package for Moq

          "NuPack is a package management system for .NET. The goal of NuPack is to make the process of incorporating third party libraries into your solutions as simple as possible."

          http://nupack.codeplex.com/documentation?title=Creating%20a%20Package

          20 votes
          Vote 0 votes Vote Vote
          Vote
          Sign in
          Check!
          (thinking…)
          Reset
          or sign in with
          • facebook
          • google
            I agree to the terms of service

            You'll receive a confirmation email with a link to create a password (optional).

            Signed in as (Sign out)
            You have left! (?) (thinking…)
          • Add QuickStart examples for out a ref with callbacks.

            The quickstart page is a great reference for those occasions when the natural syntax doesn't tell you what you need.

            But it's missing examples on how to setup callbacks when ref and out parameters are used, and everytime I come across one of these situations I've forgotten what the rules are.

            Adding them to quickstart would be very helpful.

            16 votes
            Vote 0 votes Vote Vote
            Vote
            Sign in
            Check!
            (thinking…)
            Reset
            or sign in with
            • facebook
            • google
              I agree to the terms of service

              You'll receive a confirmation email with a link to create a password (optional).

              Signed in as (Sign out)
              You have left! (?) (thinking…)
              planned  ·  kzuAdminkzu (Admin, moq) responded

              Maybe the rules aren’t all that clear then?

              What would you improve in the syntax to make it more discoverable without having to resort to the quickstart?

            • Provide a callback before returning default mocks as values

              When you set up a Mock with DefaultValue.Mock it will return mock instances for any members that don't have Setups defined.

              I'm doing a lot of work with AutoMocking containers, and in that scenario it would be really nice to have a callback that would allow me to intercept this behavior.

              My AutoMocking container will take care of returning a mock of IFoo, and with DefaultValue.Mock, a member will automatically return a mock of IBar.

              However, I would really like to be able to say that "whenever Moq tries to return IBaz from an IBar method, I want to be… more

              14 votes
              Vote 0 votes Vote Vote
              Vote
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                I agree to the terms of service

                You'll receive a confirmation email with a link to create a password (optional).

                Signed in as (Sign out)
                You have left! (?) (thinking…)
                planned  ·  kzuAdminkzu (Admin, moq) responded

                yes, we had a request to allow the default value strategy be open (it’s already pluggable internally)

              • Please fix the broken API Documentation link. I want to read more about the new methods.

                I just started using Moq and all of the examples (including the one on the home page) uses obsolete methods. It's fairly easy to find the reference to the new methods by using Intellisense but if the API documentation link worked it would be great to find examples.

                13 votes
                Vote 0 votes Vote Vote
                Vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  I agree to the terms of service

                  You'll receive a confirmation email with a link to create a password (optional).

                  Signed in as (Sign out)
                  You have left! (?) (thinking…)
                • Make it possible to verify the number of times a protected member was invoked

                  It would be nice if protected setups could be verified using Times (Never, Once, etc.) just like normal setups.

                  12 votes
                  Vote 0 votes Vote Vote
                  Vote
                  Sign in
                  Check!
                  (thinking…)
                  Reset
                  or sign in with
                  • facebook
                  • google
                    I agree to the terms of service

                    You'll receive a confirmation email with a link to create a password (optional).

                    Signed in as (Sign out)
                    You have left! (?) (thinking…)
                    planned  ·  kzuAdminkzu (Admin, moq) responded

                    makes sense, yes. Protected() has lagged behind the typed API somehow…

                  • Make callbacks more flexible about the required parameters

                    Sometimes you don't need all the parameters of the mocked method in the callback. Sometimes you don't need any of them.

                    Is it possible to allow partial matches, I'm thinking if there are 4 parameters on the method, and only 3 on the callback, if the first 3 match then allow that callback.

                    As the callback verification seems to be done at run time I think this should be possible.

                    7 votes
                    Vote 0 votes Vote Vote
                    Vote
                    Sign in
                    Check!
                    (thinking…)
                    Reset
                    or sign in with
                    • facebook
                    • google
                      I agree to the terms of service

                      You'll receive a confirmation email with a link to create a password (optional).

                      Signed in as (Sign out)
                      You have left! (?) (thinking…)
                      under review  ·  kzuAdminkzu (Admin, moq) responded

                      what should be the batching behavior? Argument type obviously, but what about ordering? What if the method has 2 string parameters mixed with other types?

                    • Support mocking non-virtual method and sealed classes

                      It is understood, that you are under limitations of DynamicProxy library, but it really limit applicability of Moq, a lot.

                      It would be nice, if Moq use someting capable to create proxies which would allow you to intercept all calls (i.e. not derive a class).

                      Probably Unity may help here (at least, when it instrument a class, there is no limitations like for Castle DynamicProxy).

                      6 votes
                      Vote 0 votes Vote Vote
                      Vote
                      Sign in
                      Check!
                      (thinking…)
                      Reset
                      or sign in with
                      • facebook
                      • google
                        I agree to the terms of service

                        You'll receive a confirmation email with a link to create a password (optional).

                        Signed in as (Sign out)
                        You have left! (?) (thinking…)
                      • Add reporting to to mocks, outputing as much information as possible for every method invoked

                        When your debugging or simply trying to understand what is happening it would be very useful if we could get a list of all the methods that were invoked on a particular mock (or all mocks from a factory)

                        This could either be in the form of an explicit call:

                        mock.Report();

                        or as part of the ToString():

                        Console.Writeline(mock.ToString());

                        6 votes
                        Vote 0 votes Vote Vote
                        Vote
                        Sign in
                        Check!
                        (thinking…)
                        Reset
                        or sign in with
                        • facebook
                        • google
                          I agree to the terms of service

                          You'll receive a confirmation email with a link to create a password (optional).

                          Signed in as (Sign out)
                          You have left! (?) (thinking…)
                          under review  ·  kzuAdminkzu (Admin, moq) responded

                          we have significantly improved this reporting in case of verify errors. Would you want this to also be available when the verifications actually succeed too?

                        • 3 votes
                          Vote 0 votes Vote Vote
                          Vote
                          Sign in
                          Check!
                          (thinking…)
                          Reset
                          or sign in with
                          • facebook
                          • google
                            I agree to the terms of service

                            You'll receive a confirmation email with a link to create a password (optional).

                            Signed in as (Sign out)
                            You have left! (?) (thinking…)
                          • Make DynamicProxy layer interchangeable

                            I implemented my own DynamicProxy and would like to put my implementation underneath the Mock<> facade.

                            3 votes
                            Vote 0 votes Vote Vote
                            Vote
                            Sign in
                            Check!
                            (thinking…)
                            Reset
                            or sign in with
                            • facebook
                            • google
                              I agree to the terms of service

                              You'll receive a confirmation email with a link to create a password (optional).

                              Signed in as (Sign out)
                              You have left! (?) (thinking…)
                            • Support VB10

                              I kept hearing the Moq should support VB10, but I I'm having dificulty converting over C# samples to VB10, not sure if it's my code or if there are still VB10 compatibility issues? Some VB10 Quickstart exmamples would be great if VB10 is now supported?

                              3 votes
                              Vote 0 votes Vote Vote
                              Vote
                              Sign in
                              Check!
                              (thinking…)
                              Reset
                              or sign in with
                              • facebook
                              • google
                                I agree to the terms of service

                                You'll receive a confirmation email with a link to create a password (optional).

                                Signed in as (Sign out)
                                You have left! (?) (thinking…)
                              • Support for auto-mocking hierarchies (recursive mocks)

                                a thought. the need for auto-mocking hierarchies (recursive mocks) is a smell that LoD has been violated.

                                is good to support auto-mocking hierarchies then ?

                                3 votes
                                Vote 0 votes Vote Vote
                                Vote
                                Sign in
                                Check!
                                (thinking…)
                                Reset
                                or sign in with
                                • facebook
                                • google
                                  I agree to the terms of service

                                  You'll receive a confirmation email with a link to create a password (optional).

                                  Signed in as (Sign out)
                                  You have left! (?) (thinking…)
                                • Can't raise event on recursively-mocked interface

                                  Raise() doesn't raise an event on a recursively-mocked interface (i.e. the event belongs to the interface of a recursively-mocked property).

                                  3 votes
                                  Vote 0 votes Vote Vote
                                  Vote
                                  Sign in
                                  Check!
                                  (thinking…)
                                  Reset
                                  or sign in with
                                  • facebook
                                  • google
                                    I agree to the terms of service

                                    You'll receive a confirmation email with a link to create a password (optional).

                                    Signed in as (Sign out)
                                    You have left! (?) (thinking…)
                                  • Introduce a MoqException to wrap fex. ArgumentException

                                    I had a Unit Test with following attribute: [ExpectedException(typeof(ArgumentException))]
                                    So the test would succeed when this exception was thrown.

                                    But because I was incorrectly using Moq, my test would always pass. During the Setup() method, Moq was throwing an ArgumentException. Now if incorrect usage (fex using a sealed class to mock, or a property that's not defined as virtual) would throw MoqException, the test would fail, causing me to search for the problem.

                                    3 votes
                                    Vote 0 votes Vote Vote
                                    Vote
                                    Sign in
                                    Check!
                                    (thinking…)
                                    Reset
                                    or sign in with
                                    • facebook
                                    • google
                                      I agree to the terms of service

                                      You'll receive a confirmation email with a link to create a password (optional).

                                      Signed in as (Sign out)
                                      You have left! (?) (thinking…)
                                    • improve the errormessage for verifying Times.Once, when method is not called

                                      mock.Verify(m => m.Do(), Times.Once);

                                      The errormessage says the method was invoked more than once, even though the method was never invoked.

                                      3 votes
                                      Vote 0 votes Vote Vote
                                      Vote
                                      Sign in
                                      Check!
                                      (thinking…)
                                      Reset
                                      or sign in with
                                      • facebook
                                      • google
                                        I agree to the terms of service

                                        You'll receive a confirmation email with a link to create a password (optional).

                                        Signed in as (Sign out)
                                        You have left! (?) (thinking…)
                                      • Add VerifyNoMoreIntractions and VerifyZeroInteractions

                                        This will allow to write tests like the following, which AFAICT are not possible at the moment:

                                        // Arrange:
                                        var mock = new Mock<IFoo>();
                                        // Automatically return defaults for everything, so no additional setup.

                                        // Act:
                                        ...

                                        // Assert:
                                        mock.Verify(foo => foo.SomeMethod());
                                        mock.Verify(foo => foo.AnotherMethod());
                                        mock.VerifyNoMoreInteractions();

                                        Of course, one could use strict mode and specify all the expectations in advance, but that somewhat breaks the AAA approach.

                                        2 votes
                                        Vote 0 votes Vote Vote
                                        Vote
                                        Sign in
                                        Check!
                                        (thinking…)
                                        Reset
                                        or sign in with
                                        • facebook
                                        • google
                                          I agree to the terms of service

                                          You'll receive a confirmation email with a link to create a password (optional).

                                          Signed in as (Sign out)
                                          You have left! (?) (thinking…)
                                        • Take into account existing tests before removing things

                                          The Isuses log shows items that are going to be removed for release 3.5. While Rhino Mocks takes backwards compatibility a bit too far there is something to be said for stability in code that tests rely on. If every release or two of Moq I have to refactor a lot of tests there is no way I'm going to be able to continue using it.

                                          2 votes
                                          Vote 0 votes Vote Vote
                                          Vote
                                          Sign in
                                          Check!
                                          (thinking…)
                                          Reset
                                          or sign in with
                                          • facebook
                                          • google
                                            I agree to the terms of service

                                            You'll receive a confirmation email with a link to create a password (optional).

                                            Signed in as (Sign out)
                                            You have left! (?) (thinking…)
                                            under review  ·  kzuAdminkzu (Admin, moq) responded

                                            We’re working hard to keep backs compat, by basically hiding old/legacy API members and keeping compilation intact.

                                            We do remove members after 2 major versions, so you have to refactor as needed. That said, the intermediate version (the one containing the obsolete and warnings) helps you to see what you should be using instead.

                                            At the end of the day, if a given version of Moq does everything you need, you have no reason to upgrade to an incompatible version (which wouldn’t happen more than once a year, approx). I just pushed a couple breaking changes to 4.0 as that’s the next major release post-3.0.

                                            Keeping legacy APIs for 2 major versions gives you plenty of time to refactor or consider NOT to upgrade. We want to support new Moq scenarios without confusing new users with legacy APIs that are no longer in use.

                                            Would you prefer that we keep… more

                                          • Expose IDefaultValueProvider?

                                            For example, if I want to override a loose mock to also return empty lists or a dummy object for a specific type.

                                            Currently, I've set up a mock factory class that will use reflection on the interface after the mock has been created. If a method returns a type that I'd like a different default value for, it uses reflection to call Setup using that method and returning the empty list / dummy object. It works, but it's really slow.

                                            2 votes
                                            Vote 0 votes Vote Vote
                                            Vote
                                            Sign in
                                            Check!
                                            (thinking…)
                                            Reset
                                            or sign in with
                                            • facebook
                                            • google
                                              I agree to the terms of service

                                              You'll receive a confirmation email with a link to create a password (optional).

                                              Signed in as (Sign out)
                                              You have left! (?) (thinking…)
                                              under review  ·  kzuAdminkzu (Admin, moq) responded

                                              It also returns empty for enumerables and iqueryables.
                                              if you set the default value to DefaultValue.Mock, you’d get an empty list too. Have you tried that?

                                            ← Previous 1
                                          • Don’t see your idea?
                                          • Post a new idea…
                                          • General

                                            Knowledge Base and Helpdesk