Mocking UrlHelper.Action

8 posts, 0 answers
  1. Chris
    Chris avatar
    7 posts
    Member since:
    Sep 2012

    Posted 31 May 2011 Link to this post

    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
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 01 Jun 2011 Link to this post

    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
  3. DevCraft R3 2016 release webinar banner
  4. Chris
    Chris avatar
    7 posts
    Member since:
    Sep 2012

    Posted 01 Jun 2011 Link to this post

    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
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 02 Jun 2011 Link to this post

    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
  6. Chris
    Chris avatar
    7 posts
    Member since:
    Sep 2012

    Posted 02 Jun 2011 Link to this post

    Yes, JustMock addin is installed and enabled.

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

    Chris
  7. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 09 Jun 2011 Link to this post

    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
  8. Chris
    Chris avatar
    7 posts
    Member since:
    Sep 2012

    Posted 09 Jun 2011 Link to this post

    "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
  9. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 15 Jun 2011 Link to this post

    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
Back to Top
DevCraft R3 2016 release webinar banner