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

Mocking UrlHelper.Action

7 Answers 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 31 May 2011, 06:55 PM
This is giving me a compile error:


var urlHelper = Mock.Create<UrlHelper>( Constructor.Mocked );
Mock.Arrange( () => urlHelper.Action( Arg.IsAny<string>(), Arg.IsAny<string>() ) )
    .DoInstead( ( string actionName, string controllerName ) => {} )
    .Returns( ( string actionName, string controllerName ) => String.Format( "/{0}/{1}", controllerName, actionName ) );

The error is:

Error 4 The type arguments for method 'Telerik.JustMock.Helpers.MultipleReturnValueChainHelper.Returns<TReturn>(Telerik.JustMock.Expectations.Abstraction.IAssertable, TReturn)' cannot be inferred from the usage. Try specifying the type arguments explicitly. D:\DevL\Overview\Alpha\Source\Test\Client\Client.Test\Core\Menus\MenuBuilderTest.cs 29 11 Client.Test

First, am I mocking this correctly?  I just want to return a formatted route instead of actually calling Action.

Second...what do I have to do to get it to compile?  I've tried specifying the template parameters for Returns and casting the lambda to Func2<string,string,string>.  I'm not sure why it's complaining.

Thanks,
Chris

7 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 01 Jun 2011, 05:11 PM
Hi  Chris,

Thank you for sending the issue.

The reason for the exception is that UrlHelper.Action(string, string) has overload with System.Web.Routing.RouteValueDictionary and if you are testing in .net 4.0 please make sure that you reference the corrrect System.Web.Routing dll that is referenced by UrlHelper. I found using decompiler that the version pointed by .net 4.0 client framework does not have RouteValueDictionary at all. Once i referenced the correct version, the build is green.

I am attaching my test project to let you have a look and hope that solves your issue.


Kind Regards,
Mehfuz
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
Chris
Top achievements
Rank 1
answered on 01 Jun 2011, 06:07 PM
I got it to compile by including System.Web.  I also, as you suggested, included System.Web.Routing.

Now, when calling, urlHelper.Action, I'm getting a validation exception (Operation could destabilize the runtime).  It's happening on a call to GenerateUrl inside the original UrlHelper implementation.  

Why is that even being called?  Doesn't the .DoInstead replace the original implementation with (in my case) nothing?

I am using .NET 4 and MVC 3.

Thanks,
Chris
0
Ricky
Telerik team
answered on 02 Jun 2011, 08:39 AM
Hi Chris,

Thanks again for your reply. I was having the exception in GenerateUrl when my profiler is not turned on. May be you could check if you have the profiler installed and enabled (visual studio addin is installed and enable JustMock is selected).

Hope that solves your issue.


Kind Regards,
Mehfuz
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
Chris
Top achievements
Rank 1
answered on 02 Jun 2011, 02:07 PM
Yes, JustMock addin is installed and enabled.

I submitted a support ticket so that I could upload a test project.

Chris
0
Ricky
Telerik team
answered on 09 Jun 2011, 10:28 AM
Hi Chris,
An answer to this issue has been posted in the other support ticket that you have sent. Please take a look into it.

Sorry for any inconvenience caused and hope to hear from you soon.



Kind Regards,
Ricky
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
Chris
Top achievements
Rank 1
answered on 09 Jun 2011, 01:40 PM
"We are looking into it" was the message I received in the support ticket.  If there is a resolution, perhaps it didn't make it into my support ticket.

Chris
0
Ricky
Telerik team
answered on 15 Jun 2011, 08:58 AM
Hi Chris,

The issue is occurring because of the conflict between the .net 4.0 System.Web and the one that is loaded in the AppDomain for intercepting by JustMock profiler (.net 3.5). We are still working on this and it will take some time to resolve this.

However the test is working perfectly fine with MVC 2 assemblies and calls made in MVC 3 that does not include the arguments referencing members from System.Web 4.0  as well.




Kind Regards,
Mehfuz
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
Chris
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Chris
Top achievements
Rank 1
Share this question
or