private static mock returning null

4 posts, 0 answers
  1. DudeWheresMyLaptop
    DudeWheresMyLaptop avatar
    2 posts
    Member since:
    Mar 2014

    Posted 21 Apr 2014 Link to this post

    Hi there,
    Been trying out the JustMock pro trial and I'm almost ready to buy. However, I have run into an issue which could be a deal breaker. Hoping someone with more knowledge of the product can steer me in the right direction.

    I am attempting to test a private static method that resides in the codebehind file of a default.aspx page of a single-page web application (aka default.aspx.cs). The method under test is a very simple one that is a component of a much larger processes involving URL's, see below:

    default.aspx.cs

    namespace Company.Project
    {
    public partial class _default : System.Web.UI.Page
    {
    private static string CleanupURL(String theUrl)
    {
    theUrl = theUrl.ToLower();
    theUrl = theUrl.Replace(@"\", "/");
    while (!theUrl.IndexOf(".aspx").Equals(-1))
    {
    theUrl = theUrl.Substring(0, theUrl.IndexOf(".aspx"));
    while (!theUrl.EndsWith("/") && theUrl.Length > 0)
    {
    theUrl = theUrl.Substring(0, theUrl.Length - 1);
    }
    }
    return theUrl;
    }
    }
    }

    here is the test I have written (using nunit/justmock/dotcover test runner)

    [Test]
            public void WillCleanupUrl()
            {
                var instance = PrivateAccessor.ForType(typeof(_default));
                string given = "server/subsite/default.aspx";
                var expected = "server/subsite";
                var returned = instance.CallMethod("CleanpUrl", given);
                Assert.AreEqual(expected, returned);
            }

    My implementation is a copy/pasta of the example shown in the documentation regarding static methods with private accessors however the returned var is always null.

    Other information:
    This test is being executed inside of a virtual machine that has IIS/SQL/Sharepoint installed on it and it also communicates with a neighboring domain controller vm. Essentially, everything the project needs to run the entire application is running locally or nearby on the virtual lan, there is no true connection to the internet. I notice, using fiddler2, that requests are being sent  to various URL's (monitor.ashx?) by the jetbrains dotcover test runner. Obviously, these requests fail. Not sure if this has something to do with it? Possible bug?

    Any help or guidance on the issue would be greatly appreciated!



  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 22 Apr 2014 Link to this post

    Hi James,

    I was unable to reproduce the "returns null" behavior using the code you gave us. Taken as is, the code throws an exception because there's no method called "CleanpUrl". The name must match exactly, so I fixed the name to read "CleanupURL". Now the CallMethod call returned the string value "server/subsite/", as one would expect. I've attached the project I used for testing. You can take a look at it and try to spot any differences between your code and the sample code. Alternatively, you could wrap the test code in a minimal repro project and send it to us for investigation.

    Could you also try running the tests without dotCover? Although unlikely, it may be subtly changing the behavior of PrivateAccessor.

    I hope that your issue gets resolved quickly and you can continue with your trial.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft R3 2016 release webinar banner
  4. DudeWheresMyLaptop
    DudeWheresMyLaptop avatar
    2 posts
    Member since:
    Mar 2014

    Posted 22 Apr 2014 in reply to Stefan Link to this post

    Haha wow, thanks Stefan. Apparently I need more caffeine in the afternoons. :)
  5. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 23 Apr 2014 Link to this post

    Hello James,

    I assume that the problem you encountered was caused by that misspelling and that you're now all set up. I am closing the ticket for now.

    If you stumble upon any other problems during your evaluation don't hesitate to contact us again.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top