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

      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?

    • 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…)
      • please look at "fixed" issue 183

        I came across issue 183 (display what invocations were received when the expected one hasn't been met) when searching the issue list based on my own need for functionality.

        The issue precisely matches what I am looking for, but unfortunately the code changes made in response to the issue really don't address the request.

        I uploaded a patch that does meet my need and I believe better fulfills the request of the person who opened issue 183. I would appreciate feedback etc. with the goal of having the patch accepted into the project.

        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…)
        • 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…)
          • 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 →
            • 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…)
              • Extend Parameter validation

                In our unit tests I need to compare hirarchical objects when validating input parameters or validation the result of a method (similar to Rhino Mocks:

                Expect.Call(myMock.DoSomething(fooObject)).IgnoreArguments().Constraints(Property.AllPropertiesMatch(fooObject)))

                Example:
                MailMessage expectedX = ...;
                mock.Setup((x) => x.Send(Are.Same<MailMessage>(x, expectedX));

                // or

                MailMessage expectedX = ...;
                mock.Setup((x) => x.Send(It.Is<MailMessage>(x => Are.Equal(x, expectedX);

                ...

                // Validateion
                MailingProtocol result = ...
                MailingProtocol expectedResult = ...
                Assert.That(Are.Equal(result, expectedResult), ...);

                Any suggestions or ideas?

                Thanks a lot in advance!

                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 →
                  • 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…)
                    • Extend out parameter support

                      I'd like to be able to specify different out parameter values if a function is called more than once (say in a loop) at the moment I cannot se how this is possible.

                      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…)
                        • 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…)
                          • 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…)
                            ← Previous 1 2 Next →
                            • Don't see your idea?

                            General

                            Feedback and Knowledge Base