chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hello,

Why does this test fail?

roleAssignment.Member is null :(

        [TestMethod, Isolated]
        public void SomeTest()
        {
            // arrange
            var roleAssignment = Isolate.Fake.Instance<SPRoleAssignment>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => roleAssignment.Member.ID).WillReturn(50);

            // act

            // assert
            Assert.AreEqual(50, roleAssignment.Member.ID);
        }
asked by soniiic (720 points)

5 Answers

0 votes
Hi,

Unfortunately, you have stumbled on a corner case object Isolator has an issue with :(. When faking an abstract object, Isolator tries to extend it and create an instance of the new type. In the case of Member property, the SPPrincipal class is both abstract, and does not have an available contructor, thus Isolator fails to intantiate and fake it. This is a known issue, and I'll try to find a workaround for your case.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Ok thanks, any chance of a workaround yet? All my tests pass except this one :)
answered by soniiic (720 points)
0 votes
Hi soniiic,

You can try to fake one of the classes implementing the abstract class and return it with WillReturn :)
answered by anna (260 points)
0 votes
Hi soniiic,

You can try to fake one of the classes implementing the abstract class and return it with WillReturn :)


I don't have any classes implementing SPPrincipal. I don't know how I could do that as the only constructor for SPPrincipal is internal.
answered by soniiic (720 points)
0 votes
I got it working!

var roleAssignment1 = Isolate.Fake.Instance<SPRoleAssignment>(Members.MustSpecifyReturnValues);
var member1 = Isolate.Fake.Instance<SPUser>(Members.MustSpecifyReturnValues);
Isolate.WhenCalled(() => roleAssignment1.Member).WillReturn(member1);
Isolate.WhenCalled(() => member1.ID).WillReturn(50);


I'm faking SPUser which is derived from SPPrincipal so it has no issue casting up :)
answered by soniiic (720 points)
...