Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edson Ferreira 4 posts 109 karma points
    Jan 15, 2016 @ 17:21
    Edson Ferreira
    0

    Mocking Umbraco Context - GetUmbracoContextWithRouteData Method on UmbracoContextHelper class missing

    Is there an alternative method for GetUmbracoContextWithRouteData() on the UmbracoContextHelper class (Umbraco.Tests assembly) in Umbraco v7.3.4?

    I need to mock an instance of IUmbracoContext on my Unit Tests, which I could do previously with the Umbraco.Tests.dll on v7.2.8, but this method has disappeared from the same dll after upgrading to v7.3.4.

    This is the my code currently:

    var umbracoContextHelper = new UmbracoContextHelper();
    var umbracoContext = UmbracoTests.GetUmbracoContextWithRouteData("http://rb.com", 0);
    _umbracoContextMock = new Mock<IUmbracoContext>();
    _umbracoContextMock.Setup(x => x.Current).Returns(() => umbracoContext);
    

    Is there a different way of doing this in v.7.3.4?

    Thanks in advance for your help.

  • Gary Devenay 39 posts 245 karma points
    Apr 01, 2016 @ 14:03
    Gary Devenay
    100

    Hi Edson, I have released a NuGet package to do exactly this. You can find it at https://www.nuget.org/packages/GDev.Umbraco.Testing/ and also a blog post on how to get started http://garydevenay.com/articles/unit-testing-in-umbraco-7x/

    Let me know if you need any assistance getting up and running.

  • Edson Ferreira 4 posts 109 karma points
    Jun 16, 2016 @ 15:24
    Edson Ferreira
    0

    Thanks Gary!

Please Sign in or register to post replies

Write your reply to:

Draft