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…)

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

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

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

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

  1. Consider MOQ for performance testing.

    I was able to successfully run load tests and measure throughput metrics (tps) for a web service tier by mocking out external db calls (the db calls are a known performance bottleneck and we only wanted to measure throughput for our web service calls in isolation). I ran into issues with mocked instances leaking memory when the mocked reference was returned in a myMock.Return(mockInstance) call. Without typing a book on all of the things I tried - I was able to mitigate the leakage using weak references but I would be nice if MOQ were hardened for use in load…

    1 vote
    Vote
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      You have left! (?) (thinking…)
    • Ability to disable saving references to arguments the mock was invoked with

      At my company I'm using Mock to unit test for memory leaks.

      Our UI controls typically take some interface of a model, binds to its events and then updates the UI state depending on this model. When the UI gets disposed it's crucial that it unhooks completely from the model and can be garbage collected.

      I unit test this by
      1. Making a mock of the model interface
      2. Use the mock to create the control
      3. Attach a weak reference to the control
      4. Dispose the control
      5. Run a garbage collection
      6. Check if the weak reference is…

      3 votes
      Vote
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        Password icon
        I agree to the terms of service
        Signed in as (Sign out)
        You have left! (?) (thinking…)
      • Make the internal recording of actual invocations optional in order to reduce memory usage by Moq

        I use Moq simply to produce stubbed interfaces. I have no need to check the invocations of each method for some of my mocked interfaces. In some cases, the number of invocations is in the 100,000's, which causes many OutOfMemoryExceptions to be thrown unexpectedly.

        Being able to turn off invocation tracking for specific mocks would fix this issue.

        3 votes
        Vote
        Sign in
        Check!
        (thinking…)
        Reset
        or sign in with
        • facebook
        • google
          Password icon
          I agree to the terms of service
          Signed in as (Sign out)
          You have left! (?) (thinking…)
        • Matching parameters which are expressions

          Maybe it is already somehow possible, but I need to be able to do something like this:

          mock.Verify(x => x.Foo(y => Bar(It.Is<int>(z => z == 2))), Times.Once);

          Verify must match calls to Foo where the parameter is an expression calling 'Bar' with a parameter which must equal '2'.

          I know I can write the following, which however is not quite specific enough.

          mock.Verify(x => x.Foo(It.IsAny<Expression<Func<int, int>>()), Times.Once);

          10 votes
          Vote
          Sign in
          Check!
          (thinking…)
          Reset
          or sign in with
          • facebook
          • google
            Password icon
            I agree to the terms of service
            Signed in as (Sign out)
            You have left! (?) (thinking…)
            1 comment  ·  Admin →
          • Most painful experience in over a year....

            Wow. This is the worst experience I've had in a long time.
            Working on a project at home with VS 2010 Express.
            All the instructions I've found so far either say to install with NuGet or just download, reference the dll, and go.
            Since I couldn't get the download and reference approach to work, finally gave in and tried the NuGet approach. Got it to install but it doesn't work in Express. Back to the manual approach.
            The only DLL in the zip file is in the samples folder.
            Referencing that gives a compile error.
            Surely I'm missing something.
            More…

            1 vote
            Vote
            Sign in
            Check!
            (thinking…)
            Reset
            or sign in with
            • facebook
            • google
              Password icon
              I agree to the terms of service
              Signed in as (Sign out)
              You have left! (?) (thinking…)
            • Make MockVerificationException public

              I was trying to verify that a method was NOT called in a unit test. I set up that method in the mock as verifiable, then after I ran the method, I ran mock.Verify(). I notice if they are not called, it throws an Exception of type MockVerificationException. However, I was unable to catch Exceptions of that type, or set up the method to expect that type of Exception.

              I can catch a MockException, however I would prefer to keep it as specific as possible in the event that something else goes wrong.

              1 vote
              Vote
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                Password icon
                I agree to the terms of service
                Signed in as (Sign out)
                You have left! (?) (thinking…)
              • Publish Debug Symbols (pdb)

                Please provide the pdb for recent build via SymbolSource.org at https://www.symbolsource.org/Public/Metadata/Default/Project/Moq

                or build the project on free for open source project CI server such as http://www.appveyor.com, https://drone.io, https://travis-ci.com, etc.

                6 votes
                Vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  Password icon
                  I agree to the terms of service
                  Signed in as (Sign out)
                  You have left! (?) (thinking…)
                • Add a new strict MockBehavior that does not throw any MoqException until VerifyAll

                  A Mock object with MockBehavior.Strict throws an exception instantly when a method is called that is not setup.

                  Problem: The thrown MoqException can be masked by a try/catch in the business logic of the unit you are testing. This could result in a false positive test or unexpected application behavior.

                  I would suggest implementing a new MockBehavior which behaves like Strict, but waits throwing an exception until VerifyAll is called.

                  Developing unit tests would be easier when the failed unit test throws a MoqException in stead of the MoqException being swalowed somewhere in your application code by a try/catch.

                  This…

                  1 vote
                  Vote
                  Sign in
                  Check!
                  (thinking…)
                  Reset
                  or sign in with
                  • facebook
                  • google
                    Password icon
                    I agree to the terms of service
                    Signed in as (Sign out)
                    You have left! (?) (thinking…)
                  • please add a "Times" argument to IVerifies.Verifiable

                    I would like to be able to specify the number of times a method should be called from a "Setup" so that if I need to setup multiple methods on a mock I can use a single Verify()

                    For example, instead of:
                    mock.Setup(x=>x.Foo()).Returns(1);
                    mock.Setup(x=>x.Bar()).Returns(2);
                    //exercise interface
                    mock.Verify(x=>x.Foo(), Times.Once(), "Foo should be called once");
                    mock.Verify(x=>x.Bar(), Times.Once(), "Bar should be called once");

                    I would prefer:
                    mock.Setup(x=>x.Foo()).Returns(1).Verifiable(Times.Once(), "Foo should be called once");
                    mock.Setup(x=>x.Bar()).Returns(2).Verifiable(Times.Once(), "Bar should be called once");
                    //exercise interface
                    mock.Verify();

                    Thank you for your consideration.

                    23 votes
                    Vote
                    Sign in
                    Check!
                    (thinking…)
                    Reset
                    or sign in with
                    • facebook
                    • google
                      Password icon
                      I agree to the terms of service
                      Signed in as (Sign out)
                      You have left! (?) (thinking…)
                    • InSequence can handle the case where 'expectations' are met on different threads

                      I have a scenario where the code in my class under tests runs in a new thread (using Tasks in TPL if that is relevant) ie a different thread to where setup of mock done.

                      It would appear that Moq cannot handle this scenario. I picture it would rely on Callback functionality to allow this.

                      I have had a bit of a go trying to write an extension method to tackle it this way but struggling to do it.

                      1 vote
                      Vote
                      Sign in
                      Check!
                      (thinking…)
                      Reset
                      or sign in with
                      • facebook
                      • google
                        Password icon
                        I agree to the terms of service
                        Signed in as (Sign out)
                        You have left! (?) (thinking…)
                      • SetupSequence() : More operators

                        Be able to use SetupSequence like this : Example : The first time, I want the method returns 0, then it returns 1.

                        mock.SetupSequence(x => x.GetNumber())
                        .ReturnsFirst(0)
                        .ThenReturns(1);

                        Today, to do this I write this, it's a little bit verbose...

                        var firstTime = true;

                        mock.Setup(x => x.GetNumber())
                        .Returns(()=>
                        {
                        if(!firstTime)
                        return 1;

                        firstTime = false;
                        return 0;
                        });

                        src : http://stackoverflow.com/questions/11308328/moq-setupsequence

                        I think it could be a good improvement to deal with sequences to add
                        some function like these.

                        28 votes
                        Vote
                        Sign in
                        Check!
                        (thinking…)
                        Reset
                        or sign in with
                        • facebook
                        • google
                          Password icon
                          I agree to the terms of service
                          Signed in as (Sign out)
                          You have left! (?) (thinking…)
                          1 comment  ·  Admin →
                        • Fix the several broken links on the moq home page

                          There are several broken links on the home page, which gives the impression this project is either dead or dying. Is it? (http://code.google.com/p/moq )

                          2 votes
                          Vote
                          Sign in
                          Check!
                          (thinking…)
                          Reset
                          or sign in with
                          • facebook
                          • google
                            Password icon
                            I agree to the terms of service
                            Signed in as (Sign out)
                            You have left! (?) (thinking…)
                          • 1 vote
                            Vote
                            Sign in
                            Check!
                            (thinking…)
                            Reset
                            or sign in with
                            • facebook
                            • google
                              Password icon
                              I agree to the terms of service
                              Signed in as (Sign out)
                              You have left! (?) (thinking…)
                            • Might not be a bad idea to update the title

                              Right now the header says "The simplest mocking library for .NET 3.5 and Silverlight with deep C# 3.0 integration" ... Moq does support 4.0 does it not?

                              1 vote
                              Vote
                              Sign in
                              Check!
                              (thinking…)
                              Reset
                              or sign in with
                              • facebook
                              • google
                                Password icon
                                I agree to the terms of service
                                Signed in as (Sign out)
                                You have left! (?) (thinking…)
                                1 comment  ·  Admin →
                              • Tutorial: How do I use Moq with C++/CLI

                                I am experimenting with MOQ on C++/CLI but I am totally lost becuase of the lamda expressions. Is it possible to use Moq with C++/CLI or just with C#?

                                1 vote
                                Vote
                                Sign in
                                Check!
                                (thinking…)
                                Reset
                                or sign in with
                                • facebook
                                • google
                                  Password icon
                                  I agree to the terms of service
                                  Signed in as (Sign out)
                                  You have left! (?) (thinking…)
                                  1 comment  ·  Admin →
                                • 3 votes
                                  Vote
                                  Sign in
                                  Check!
                                  (thinking…)
                                  Reset
                                  or sign in with
                                  • facebook
                                  • google
                                    Password icon
                                    I agree to the terms of service
                                    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.

                                    4 votes
                                    Vote
                                    Sign in
                                    Check!
                                    (thinking…)
                                    Reset
                                    or sign in with
                                    • facebook
                                    • google
                                      Password icon
                                      I agree to the terms of service
                                      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 ?

                                      4 votes
                                      Vote
                                      Sign in
                                      Check!
                                      (thinking…)
                                      Reset
                                      or sign in with
                                      • facebook
                                      • google
                                        Password icon
                                        I agree to the terms of service
                                        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
                                        Sign in
                                        Check!
                                        (thinking…)
                                        Reset
                                        or sign in with
                                        • facebook
                                        • google
                                          Password icon
                                          I agree to the terms of service
                                          Signed in as (Sign out)
                                          You have left! (?) (thinking…)
                                          1 comment  ·  Admin →
                                        • Provide a DefaultValue that returns the mocked object

                                          I'm mocking an NHibernate criteria interface, and methods can be chained on the object, e.g. CreateCriteria<User>().Add(exp1).Add(exp2).Add(exp3). Each method call returns the object itself. It would be nice to have the mock object returned for all method calls that don't have expectations.

                                          2 votes
                                          Vote
                                          Sign in
                                          Check!
                                          (thinking…)
                                          Reset
                                          or sign in with
                                          • facebook
                                          • google
                                            Password icon
                                            I agree to the terms of service
                                            Signed in as (Sign out)
                                            You have left! (?) (thinking…)
                                          ← Previous 1
                                          • Don't see your idea?

                                          General

                                          Feedback and Knowledge Base