Copied to clipboard

Flag this post as spam?

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


  • Damion 96 posts 331 karma points
    Jul 27, 2020 @ 10:59
    Damion
    0

    Setting extended properties on a mocked IMember in Nunit

    I have a mocked the GetByEmail method to return a mocked IMember. The returned IMember is the basic IMember with no extended properties.

    To progress thought the test I have to be able to call SetValue on the IMember, as this happens in the code I am testing.

    So in the code I am testing I have

    var customMember = _memberService.GetByEmail(member.Email);
    

    And in the test I have

    _mockMemberService.Setup(x => x.GetByEmail(It.IsAny<string>())).Returns(new Member("test name", new MemberType(12)));
    

    Then in the code I set a value:

    customMember.SetValue("firstName", member.FirstName);
    

    But this crashes the test as there is no firstName property on IMember, although there is in the back office.

    How can I mock adding or setting these extended properties?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft