This is a migrated thread and some comments may be shown as answers.

Mocking final methods

4 Answers 78 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Leom
Top achievements
Rank 1
Leom asked on 20 Oct 2010, 08:39 PM
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

4 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 21 Oct 2010, 10:52 AM

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
0
Leom
Top achievements
Rank 1
answered on 21 Oct 2010, 11:08 AM
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.
0
Leom
Top achievements
Rank 1
answered on 21 Oct 2010, 11:28 AM
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.
0
Ricky
Telerik team
answered on 26 Oct 2010, 05:39 PM
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
Tags
General Discussions
Asked by
Leom
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Leom
Top achievements
Rank 1
Share this question
or