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

Hi Team,

Am trying to create unit test for a SharePoint method but getting get_Web related error- TypeMock.TypeMockException :*** Method get_Web in type Microsoft.SharePoint.Client.ClientContext returns Microsoft.SharePoint.Client.Web and not Microsoft.SharePoint.Client.Web., PFB the unit test I have written. While debugging, it fails at assert.equal statement, it would be helpful if someone can point out where am getting wrong.

public static UsersFromGroupInfo GetAllInfo(string vendorName, string role, ClientContext clientContext)
        {
            //content
        }
 
//Unit Test
 
        [TestMethod]
        [Isolated]
        public void Test_To_Get_All_Info()
        {
            //Arrange
 
            ClientContext context = Isolate.Fake.NextInstance<ClientContext>(); //fake the client context
 
            List lstGroupMappingDetails = Isolate.Fake.Instance<List>(); //fake the list object
 
            Isolate.WhenCalled(() => context.Web.Lists.GetByTitle("GroupMappingOfInfo")).WillReturn(lstGroupMappingDetails);
 
            ListItem fakeListItem = Isolate.Fake.Instance<ListItem>();
 
            Isolate.WhenCalled(() => fakeListItem["Title"]).WithExactArguments().WillReturn("Manager");
            Isolate.WhenCalled(() => fakeListItem["Vendor"]).WithExactArguments().WillReturn("Dummy");
            Isolate.WhenCalled(() => fakeListItem["GroupName"]).WithExactArguments().WillReturn("Grp_Mgr");
 
            List<ListItem> listItems = new List<ListItem> { fakeListItem };
 
            Isolate.WhenCalled(() => lstGroupMappingDetails.GetItems(null)).WillReturnCollectionValuesOf(listItems);
 
            Isolate.WhenCalled(() => context.Load(lstGroupMappingDetails)).IgnoreCall(); //Ignore loading of context
            Isolate.WhenCalled(() => context.ExecuteQuery()).IgnoreCall(); //Ignore execution of SPQuery
 
            Group group = Isolate.Fake.Instance<Group>(); //fake the group object
 
            Isolate.WhenCalled(() => context.Web.SiteGroups.GetByName("Grp_Mgr")).WillReturn(group);
 
            Isolate.WhenCalled(() => context.Load(group)).IgnoreCall(); //Ignore loading of context
            Isolate.WhenCalled(() => context.ExecuteQuery()).IgnoreCall();
 
            Collection<string> groupUser = new Collection<string>();
 
            groupUser.Add(fakeListItem["Title"].ToString());
 
            //Assert
 
            Assert.AreEqual(groupUser, PortalCommon.GetAllInfo("Manager", "Dummy", context));
 
        }

 

asked by ashish5820 (1.1k points)

Please log in or register to answer this question.

...