Search code examples
c#.netsharepointmicrosoft-fakesshim

Unable to use shims in MStest to fake a SharePoint in .net


public static SPListItemCollection GetItemsReadyForPublish(SPWeb tempWeb)
{
    SPList stagingLibrary = tempWeb.Lists["examplelibrary"];
    SPQuery CamlQuery = new SPQuery();
    CamlQuery.Query = $"<Where><Eq><FieldRef Name='{"DocumentStatus"}'/><Value Type='Text'>{"Ready For Publish""}</Value></Eq></Where>";
    CamlQuery.ViewAttributes = "Scope=\"Recursive\"";
    SPListItemCollection itemCollection = stagingLibrary.GetItems(CamlQuery);
    return itemCollection;
}

In this SharePoint, a lot of libraries are there and I want to grab the "examplelibrary".

Can some please help me in writing the test case for this function using shims. I am having a tough time faking the SharePoint list as there are no documents to refer and this is the first time I am doing it for a SharePoint.


Solution

  • I found an excellent material for the same. https://www.slideshare.net/stevedxu/better-unit-testing-with-microsoft-fakes-rtm