Mocking final methods

5 posts, 0 answers
  1. Leom
    Leom avatar
    5 posts
    Member since:
    Jul 2010

    Posted 20 Oct 2010 Link to this post

    I seem to be having problems with mocking final methods (or any other elevated features).  even running the examples fails.  Take the following for instance...

     [TestMethod]
            public void ShouldTreatSetupsForTwoDifferentInstancesDifferently()
            {
                var foo1 = Mock.Create<Foo>();
                var foo2 = Mock.Create<Foo>();

                Mock.Arrange(() => foo2.Echo(Arg.IsAny<int>())).Returns(10);
                Mock.Arrange(() => foo1.Echo(Arg.IsAny<int>())).Returns((int arg) => arg);
           
                Assert.Equal(foo2.Echo(12), 10);
                Assert.Equal(foo1.Echo(12), 12);
            }

    I expect both of these asserts to return true but the first fails as the call to echo returns 36.  I have the 'advanced' features turned on from the justmock menu (VS2008SP1) but no matter what I try it just wont pass.

    Any help greatly appreciated,

    Leom
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 21 Oct 2010 Link to this post

    Hello Leom,

    Thank you for submitting the issue. If JustMock is installed properly, the reason the elevated tests are failing or in other words JM profiler is not working is that there might be other profiler related tools installed  (Ex. TypeMock, DotTrace, etc) which are initializing COR_PROFILER environment variable after JustMock has initialized it. 

    To work around this issue. I would recommend to disable any such tools and re-run the tests again. Also, you can check if JM profiler is active by invoking Mock.IsProfilerEnabled.

    Finally, if you are running the tests using TestDriven.Net make sure you are using the latest RTM(3.0.2749).
     
    Hope this solves your issue.

    Kind Regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. Leom
    Leom avatar
    5 posts
    Member since:
    Jul 2010

    Posted 21 Oct 2010 Link to this post

    Hi,

    Unfortunately this is not the case.  I have no other profilers installed.  I have the problem 2 machines running win7 x64 and a VM running win7 x32.  Having used Process Monitor on the devenv.exe process I can see that the COR_PROFILER is set to the correct GUID for JustMock (after looking up the id using reflector on the add in dll), however the equivalent entry does not exist in the registry and therefore I get an error in the event log (.NET Runtime version 2.0.50727.4952 - Failed to CoCreate profiler.).  I have uninstalled/reinstalled several times to no avail.  The mentioned property returns false when checked.  I have recommended that my company use this product over TypeMock but unless I can get to the bottom of this issue then I have no way of substantiating my claims and the deal wont go ahead.

    I am also using basic MSTest and have tried with no other add-ins installed.
  5. Leom
    Leom avatar
    5 posts
    Member since:
    Jul 2010

    Posted 21 Oct 2010 Link to this post

    I have now loaded the latest version on to my 32-bit VM and this is now working but the same version (2010.1.810.6) on my 2 x64 machines are not working.  This seems to be an x64 specific problem.
  6. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 26 Oct 2010 Link to this post

    Hi Leom,

    Since the issue is fixed through a similar ticket via the installer update that is sent to your telerik account for the bug that skips the profiler registration if Visual studio 2010 is not installed (only VS 2008) in x64 based machines. Therefore, I am marking the current thread as resolved for now.

    Additionally, the fix will be included in Q3 release due in November and please feel free to write back if you have further queries.

    Kind Regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
DevCraft R3 2016 release webinar banner