Copied to clipboard

Flag this post as spam?

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


  • Terry Clancy 204 posts 944 karma points
    Apr 21, 2018 @ 19:07
    Terry Clancy
    0

    Unit Tests which use MemberService

    Updating question due to progress......

    Hi all,

    I am still struggling a little extending my unit testing to include code with Umbraco Dependencies. I got past my last problem but now have another. I am using the "UmbracoSupport" Class which uses Our.Umbraco.Community.Tests and then executing the following code to obtain an UmbracoMember object so I can read and write custom Member properties. The problem is that I end up with a null UmbracoMember object which means I can not test correctly.

    public UPSCalculateShippingReturn UPSCalculateShippingRequest(Shipment shipment, string memberUserName)   
            {
                UPSCalculateShippingReturn uPSCalculateShippingReturn = new UPSCalculateShippingReturn();
    
    
    
                Umbraco.Core.Services.IMemberService memberService = null;
    
    
                memberService = ApplicationContext.Current.Services.MemberService;
    
                var umbracoMember = memberService.GetByUsername(memberUserName);   //  <<<<<<<<<<<  Does not work – returns Null
    
    
            //   …………………………  More unrelated code
    
                }
    
            }
    

    Using the debugger it seems that the MemberService is "Mocked" which probably explains why it is returning null. Is there a way to get a "real MemberService to access and test against the real members in the database ?

    FYI I am using

    • Umbraco version 7.5.10 (assembly: 1.0.6261.14290)
    • UCommerce uCommerce 7.5.0.17040
    • NUnit {3.10.1}
    • NUnit3TestAdapter {3.10.0}
    • Moq {4.1.1309.0919}
    • Our.Umbraco.Community.Tests Nuget package (Version 7.5.10 to match my installed version of Umbraco.)
    • The "UmbracoSupport" Class from Lars-Erik's blog at
      http://blog.aabech.no/archive/the-basics-of-unit-testing-umbraco-just-got-simpler (after the heading "THE IMPLEMENTATION")

    Any assistance to overcome this problem would be appreciated !

    Thanks

    Terry Clancy

    ClanceZ

Please Sign in or register to post replies

Write your reply to:

Draft