Home > OS >  How to shim the Web class from Microsoft.Sharepoint.Client.Web?
How to shim the Web class from Microsoft.Sharepoint.Client.Web?

Time:12-06

I have a function that takes in an argument of type Web (Microsoft.Sharepoint.Client.Web). I need to write the test case for the same but unfortunately, ShimWeb is not a thing according to Visual Studio and it suggests me to change it to ShimSPWeb which is not what I am using here. How to fix it?

MY function is as follows:

 internal static bool EnsureFolders(string folderAbsolutePath, string folderRelativePath, string listName, ClientContext context, Web targetWeb, List spList)
{
            bool folderExists = false;

            Folder folder = null;
            folder = targetWeb.GetFolderByServerRelativeUrl(folderAbsolutePath);
            context.Load(folder);

            // .... something else to be done
}

Thanks in advance.

My unit test function is:

 [TestMethod]
        public void EnsureFolders_ShouldConfirmExistenceOrCreateFolders()
        {
            using (ShimsContext.Create())
            {
                ShimWeb.AllInstances.GetFolderByServerRelativeUrlString(arg) => {}; // this line throws in errors like I mentioned above.
            }
        }

CodePudding user response:

Need to add Microsoft.SharePoint.Client.Runtime dll to the references and use

ShimClientRuntimeContext.AllInstances.LoadOf1M0ExpressionOfFuncOfM0ObjectArray<ListItem>((sender, a, b) => { // Something to be done });

for the shim purpose

  • Related