3

I have an application which uploads a file to SharePoint via client object model. Now I need to write unit test cases for this application. The problem is, I how do I write test cases for the scenarios when

  1. a folder exists
  2. a folder does not exist

since this scenario can change anytime i cannot hardcore a folder name. I need to use Microsoft fakes framework. But can I use shims? If so... how to use it?

Thanks for the help!

2 Answers 2

3

This article has a very detailed inatruction how to use tests and fakes with SharePoint: http://msdn.microsoft.com/en-us/library/jj822928.aspx

1
  • 2
    Hi Max! If you extend this answer with more details regarding the users specific question it do qualify as an answer. As it stands now it is more of a comment :) Jan 2, 2014 at 11:17
1

According to article Using emulators to isolate unit tests for Sharepoint 2010 applications, Microsoft SharePoint Emulators provide a set of shims including SPFolder object, so the following test case could be used:

[TestMethod]
private bool CheckFolderExists(sting url,string folderName) 
{
    using (new SharePointEmulationScope(EmulationMode.Enabled))      
    {      
        SPSite site = new SPSite(url);

        //act    
        SPFolder folder = site.RootWeb.GetFolder(folderName);
        var success = folder.Exists;

        // assert 
        Assert.IsTrue(success);

        // cleanup  
        site.Dispose(); 
}
2
  • 1
    This is not relevant to client side object model though. Jun 2, 2015 at 20:11
  • It is a pity they do not have anything like that for CSOM.
    – Santhos
    Oct 27, 2016 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.